Core Java Interview Question's Answers - 1

How to write java documentation comment?
/**
java statement
java statement 
*/

What is JDK,  JRE,  JVM and JIT?

JVM
  • JVM stands for java virtual machine.
  • It's basic functionality is to convert the byte code to machine code.
  • Due to jvm and byte code java is platform independent.
JRE
  • JRE stands for java runtime environment. 
  • It contains libraries like networking, language fundamentals, threading, IO, Date and Time, JDBC, Security, Collections, Math, Reflections.
  • It is super set of  of jvm and hence it contains libraries and jvm as well.
  • It provides an environment to run the java code at run-time.
JDK
  • JDK stands for java development kit.
  • It is a complete package which includes each and everything required for java application development.
  • JDK contains tools for java application development like java interpreter, javac compiler , Javadoc documentation tool, jar tools for jar file execution, javap tool for showing the profile of any java libraries.
  • It is super-set of Jre So it include tools for java application development & JRE as well. 
JIT
  • JIT stands for just in time compiler.
  • In initial version of jdk java was considered as a slower language due to java interpreter functionality which translates the code line by line.
  • Later java team introduced JIT as the part of java language which compiles the most frequently used code.
  • Now as it is compiler which translates the code at once it saves a significant amount of time and so due to JIT introduction in jdk  java has become faster to a significant level.
class A {
  B b=new B ();
  Public void m1 () {
        X=b.getValue ();                X=b.value;              X=b.value;       X=b.value;       X=b.value;
         …………………..                   ………………               ………………       ………………       ……………..
         …………………..                   ………………               ………………       ………………       ……………..
       Y=b.getValue ();                 Y=b.value;                 Y=X;                  X=X;                Dead Code
        Sum=X+Y;                          Sum=X+Y;               Sum=X+Y;       Sum=X+X;      Sum=2X;
   }
}

class B{
int value=12;
final int getValue() {
Return value;
}
}
  • In the above code as you can see getValue() method in B class is a final method hence it's guaranteed that it's implementation can't be changed anywhere or anytime.
  • By looking the code where two times getValue() method has been invoked we can see how JIT has optimized the code as we have shown the code explanation in 5 steps.
What are the java 5 features?
  • For-each loop.
  • Varargs.
  • Static Import.
  • Covariant Return Type.
  • StringBuilder.
  • Autoboxing and Unboxing.
  • Queue Interface of Collection.
  • Generics.
  • Enum (enum new keyword added in jdk 1.5) so from java 5 onward java has 50 keywords.    
  • Annotation.
  • java.util.concurrent.Executors
  • java.util.concurrent.ThreadPoolExecutor
  • java.util.concurrent.Executor
  • java.util.concurrent.ExecutorService    
What are the java 6 features?
  • NavigableSet interface of collection.
  • NavigableMap interface of Map hierarchy.
What are Java 7 features?
  • Binary Literals.
  • Underscore in Numeric Literals.
  • String in Switch statement.
  • Catching multiple exception types in single catch block.
  • Try with resources | AutoCloseable.
  • Enhancement in Re- throwing the Exceptions.
  • Diamond Operator.
What are the java 8 features? Explore about java 9 and java 10.
  •         Lambda Expressions
  •          Default Methods in interface.
  •          Static methods in interface.
  •          Date and Time API
  •          Using this as method parameter.
  •          Accessing Parameters Name using reflection.
  •          Type Annotations
  •          Pipelines and Streams
  •          Nashhorn JavaScript Engine
  •          Concurrent Accumulators
  •          Parallel operations
  •          PermGen Error Removed
  •          TLS SNI

What is static?
  • static is a keyword  in java programming language which can be applied with variables, initialization block, methods, and inner classes.
Variables.
  • static variables gets memory during the class loading in method area.
  • All objects of a class share the same copy of a static variable.
  • static variables are also knows as class variable.
  •  Jvm provides default value for static variable.
  • static variables are usually set as final.
  •  static variables are supposed to be accessed with class name.
  • When you write the code to access the static variable with object or reference variable, during the compilation time compiler converts this piece of code with ClassName.staticVariable. So in byte code while executing it jvm will see the code as ClassName.staticVariable instead of object.staticVarible or objectReference.staticVariable.
Initialization Block.
  • Static initialization block is executed during class loading after static variable allocation.
  • In a class we can have multiple static initialization block and they will execute in order you have mentioned in your code.
Methods.
  • Static methods contains the code that is common for all the objects of a class.
  • static methods are supposed to be accessed with class name.
  • When you write the code to access the static method with object or object reference, during the compilation time compiler converts this piece of code with ClassName.staticMethod. So in byte code while executing it jvm will see the code as ClassName.staticMethod instead of object.staticMethod or objectReference.staticMethod.
What is final?
  • final is a keyword in java programming language.
  • We can apply final with variable, methods and class as well.
Variable.
  • If Variable is final then we can’t re-assign value in it.
  • The values once assigned to it that will become the finalized version of value of that final variable.
  • If we are initializing final variable through constructor then we need to do so in all the constructor.
  • If we don’t initialize final variable in the same line then it is known as blank final variable.
  • Jvm doesn’t supply default value for final variable.
Methods.
  • If methods are final we can’t override them.
  • So final method means its functionality is the finalized version and hence no chance to modify in any means.
  • final method can’t be abstract since abstract method means it is supposed to be overridden while final method can't be overridden.
Class
  • If class is final we can’t extend that class i.e for final class we can't create it's subclass.
  • Final class means its description is the finalized version of description.   
<< Previous            Next >>

Comments

Post a Comment

Thank You for reading our post.
Your comment or feedback encourages us to improve the quality of content.
Don't forget to follow/subscribe to get the latest post.

Popular posts from this blog

Java Coding Interview Questions with Answers

Xylem bangalore : Senior Java Developer.

Zensar Java Interview Questions.