Java Interview Questions

·

3 min read

Table of contents

No heading

No headings in the article.

  1. Why java is platform independent?

The most unique feature of java is platform independent. In any programming language soruce code is compiled in to executable code. This cannot be run across all platforms. When javac compiles a java program it generates an executable file called .class file. class file contains byte codes. Byte codes are interpreted only by JVM’s . Since these JVM’s are made available across all platforms by Sun Microsystems, we can execute this byte code in any platform. Byte code generated in windows environment can also be executed in linux environment. This makes java platform independent.

  1. What is JIT compiler ?

JIT compiler stands for Just in time compiler. JIT compiler compiles byte code in to executable code . JIT a part of JVM .JIT cannot convert complete java program in to executable code it converts as and when it is needed during execution.

  1. What is bytecode in java?

When a javac compiler compiler compiles a class it generates .class file. This .class file contains set of instructions called byte code. Byte code is a machine independent language and contains set of instructions which are to be executed only by JVM. JVM can understand this byte codes.

  1. Difference between this() and super() in java ?

this() is used to access one constructor from another with in the same class while super() is used to access superclass constructor. Either this() or super() exists it must be the first statement in the constructor.

  1. What is a class ?

Classes are fundamental or basic unit in Object Oriented Programming. A class is kind of blueprint or template for objects. Class defines variables, methods. A class tells what type of objects we are creating. For example take Department class tells us we can create department type objects. We can create any number of department objects. All programming constructs in java reside in class. When JVM starts running it first looks for the class when we compile. Every Java application must have atleast one class and one main method. Class starts with class keyword. A class definition must be saved in class file that has same as class name. File name must end with .java extension.

If we see the above class when we compile JVM loads the FirstClass and generates a .class file (FirstClass.class). When we run the program we are running the class and then executes the main method.

  1. What is an object ?

An Object is instance of class. A class defines type of object. Each object belongs to some class.Every object contains state and behavior. State is determined by value of attributes and behavior is called method. Objects are alos called as an instance. To instantiate the class we declare with the class type.

To instantiate the FirstClass we use this statement

FirstClass f=new FirstClass();

f is used to refer FirstClass object.

Did you find this article valuable?

Support Codec1 by becoming a sponsor. Any amount is appreciated!