1. Write a Program to count number of duplicate characters in a string “BANGALOREJOBSEEKERSADMIN” ?
Answer:
void Findrepeter()
{ String s=”BANGALOREJOBSEEKERSADMIN”;
int distinct = 0 ;
for (int i = 0; i < s.length(); i++)
{
for (int j = 0; j < s.length(); j++)
{
if(s.charAt(i)==s.charAt(j))
{distinct++;}
}
System.out.println(s.charAt(i)+”–“+distinct);
distinct = 0;
}
}


2. What is Singleton class? with an Example?

Answer: Singleton class means you can create only one object for the given class. You can create a singleton class by making its constructor as private, so that you can restrict the creation of the object.  The purpose of singleton is to control object creation by keeping private constructor.

Example:
public class MySingleTon
{
private static MySingleTon myObj;
/*Create private constructor*/
private MySingleTon(){
}


3. What is the difference between JDK, JRE, and JIT?

Answer:
JDK : (Java Development Kit) is a bundle of software components that is used to develop Java based applications. JDK is an implementation of either of Java SE, Java EE or Java ME.
JRE : (Java Run-time Environment) is an implementation of the JVM(Java Virtual Machine) which actually executes Java programs. It includes the JVM, core libraries and other additional components to run applications and applets written in Java.
JIT : (Just-In-Time Compiler) is a component of the Java Run-time Environment (JRE). It improves the performance of Java applications by compiling byte-codes to native machine code at run time.


4. Can we have multiple public Classes in a Java Source File?

Answer: YES, there can only be one public class per .java file, as public classes must have the same name as the source file. Remaining classes should not be Public.


5. What is the default value of Boolean Keyword?

Answer: The default value of Boolean Keyword is False.


6. In the below example, how many objects are created?
–String s1= “I am a Java Expert”;
–String s2= “I am a C++ Expert”;
–String s3= “I am a Java Expert”;

Answer: Two objects will be created and these objects will be stored in the string constant pool.


7. How to use constructor in an Interface?
Answer: No, Interfaces cannot have constructors. There is no need to have interface object (interface cannot be instantiated in fact) in order to call the method as the implementation is in a separate class and class object can call this method.


8. How to create Object for Interface?
Answer: No, it is not possible. Because interface contains only abstract methods and as abstract methods do not have a body (of implementation code), we cannot create an object. There is no need to have interface object (interface cannot be instantiated in fact) in order to call the method as the implementation is in a separate class and class object can call this method.


9. What is Method Overloading and Method Overriding? Differences?
Answer:
Method Overloading
is a feature that allows a class to have more than one method having the same name, if their argument lists are different.
Method overriding means having two methods with the same arguments, but different implementations. One of them would exist in the parent class, while another will be in the derived, or child class.


10. What do you mean by Static and Final keywords? 
Answer:
Static: static keyword can be applied to instance variables and methods but not to classes. When applied, variables and methods can be called without the help of an object. When a method or variable is called without object, encapsulation is not maintained. That is, with static variables and methods, encapsulation does not exist.
1) Usage of static Keyword: Generally, an instance variable or method requires an object to call with. But static variables and methods do not require an object.

Final: final keyword can be applied to all constructs – variables, methods and classes. When applied, final behaves very differently with each with different functionalities.
1) final with variables: a final variable cannot be reassigned. Java does not support const keyword and its place uses final keyword.
2) final with methods: If the super class does not permit the subclass to override, it simply declares the method as final. The final methods of super class cannot be overridden by subclass.
3) final with classes: The programmer may not like a class to be inherited by other classes because he would like to allow the accessibility throgh composition not by inheritance.


One response to “Core Java Interview Questions for Freshers and Experienced”

  1. Your article is very informative and helpful. I just loved reading your article. Thanks a lot for sharing the java interview question here, As I have an interview as java developer & was looking for some java questions with answers to prepare for the interview & here I get all needful questions. So thanks for sharing this article.

Leave a Reply