Core Java Interview Questions- Part3

11)      What is bytecode in java ?

When a javac 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.

 

12)       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.

 

13)      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.

 

public class FirstClass {public static void main(String[] args) {System.out.println(“My First class”);}

}

 

 

 

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.

 

 

14)   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 also called as an instance.

To instantiate the class we declare with the class type.

public classFirstClass {

public static voidmain(String[] args) {

FirstClass f=new FirstClass();

System.out.println(“My First class”);

}

 

}

 

To instantiate the FirstClass we use this statement

FirstClass f=new FirstClass();

f is used to refer FirstClass object.

 

15)What is method in java ?

It contains the executable body that can be applied to the specific object of the class.

Method includes method name, parameters or arguments and return type and a body of executable code.

 

Syntax : type methodName(Argument List){}

 

 

ex : public float add(int a, int b, int c)

methods can have multiple arguments. Separate with commas when we have multiple arguments.

5 thoughts on “Core Java Interview Questions- Part3

    • Hi Divya,

      In Java we dont have concept of Global variables.we have only class variables and instance variables.Instance variables are tied to instance and class variables to class.

  1. thus concept of giving comments down here is juust amezing,,,,, i jusst want to say tht ths component is helping all the student who r commited to learn JAVA PROGRAMMING…..

  2. I don’t like the idea of using public static member variables for anything other than defining constants.
    Is there any other use case where it cannot be avoided or has some real benefit?

Leave a Reply

Your email address will not be published. Required fields are marked *