Core Java Interview Questions with answer


Java Interview question 1 
What is immutable in Java Technology? 
Java Interview answer 
String is immutable. 

Java Interview question 2
What is the difference does it have over other objects? 

Java Interview answer 
Immutable object like String, whose value once initialized
 can never be changed, that is when object or instance of 
String is created and initialized, then the reference of 
this object points to a value that can never be changed. 

Java Interview question 3 
Can a private variable be also declared as final? If yes,
why and if no, why? 

Java Interview answer 
I think, No, one can not define a private variable as final, as a
private variable can not be visible outside this class, 
so there is no need for a private variable to be defined as final.




Java Interview question  
What will happen if I try to compile a Java program
at runtime by using another Java program?
How could I create , compile and load a Java class
file from another Java program?
Basically I am trying to create an IDE (development environment)
where by I should be generating Java code based on some
user input and compiling and running this program
by click of a menu from IDE?

Java Interview answer
You can explore using Castor or any other Framework
for dynamic class file generation and then can
use Runtime api to compile and system class loader
api to load this class into the JRE of the IDE
to be able to run the generated class file.

Java Interview question  
What is Generalization (UML) in Java Code perspective?

It is a Java class extending to another Java class or
the inheritance principle.

Java Interview question  
What is Realization (UML) in Java Code perspective?

It is a Java class implementing an interface or actually
realizing an interface in a Java class.

Java Interview question  
What is Association(UML) in Java Code perspective?

It is when a Java class has any other Java class as variable
and it is using the other class.

Java Interview question  
What is Composition(UML) in Java Code perspective?

It is when a Java class C1 has any other Java class C2 as variable
and it is creating an instance of C2 class in it. So when object of
C1 is set to null or dies , so object/instance of C2 dies too.

Java Interview question  
What is Aggregation (UML) in Java Code perspective?

It is when a Java class C1 has collection of any other Java class 
instance as variable and this collection is populated by some other
object, so C1 doesn't control life cycle of these objects in collection.

please correct me if I am wrong in answering any of these question,
by email to me at share.understanding@gmail.com


If you have any questions and answer those you want to publish
here in this page, please drop me an email at
share.understanding @ gmail.com.