Java interview Questions for technical round

The most important Java interviews Questions.

1.What is the difference between JVM &JDK and JRE?
JVM:
JVM stands for java virtual machine. JVM is an abstract machine . JVM to run the program , we required a  JVM. A hardware and software platforms are available in JVM, So JVM is a platform-independent.

JDK:
JDK stands for java development kit. we need to  write and compile the program.
JRE:
JRE stands for java runtime environment .It physically exists.JRE contains JVM and Java API.
2) How many types of memory areas allocated by JVM?

There are many types of memory areas are allocated by JVM.
There are
>Native Method Stack
>Program Counter Register
>Heap
>Class(Method) Area

3) What is JIT Compiler?

JIT stands for Just-In-Time compiler. JIT is used to improve the performance. It is compiled parts of the bytecode that have contain similar  functionality at the same time, and hence decrease  the amount of time needed for compilation.Now  the term “compiler” refers to a  set of a Java virtual machine (JVM) to  set of a specific CPU.

4) What is a platform?
Basically, a platform having software or hardware environment in which program runs.Two types of platforms, there are Software based and hardware based.  java provides only Software based.

5)What is the path?
The path is an environment variable.It is used by the operating system , to execute same files like javac , java, java etc.

6)What  do u know about  Java?
Java is a high-level programming  language.  Sun Microsystems developed  by java and released in 1995.It is a platform independent. Java runs different platforms such as windows , Mac OS,and various versions of Unix.

7.  Without Main the program compile or not?

without the main method, the program compiled but not executed.

8. What is the difference between the Local variable, instance variable?

Local variable:

Variable which is declared inside method those variable are called Local variable. The local variable doesn’t have any default values. It doesn’t have any default values. Before going to use a local variable you should declare the value otherwise the compiler gives the compilation error.

Example Program:

public class variable {
public void suri(){
String k=”lifebix”;// local vriable
int a=20;    // localvariable
System.out.println(k);
System.out.println(a);
}
public static void main(String args[]){
variable v=new variable();
v.suri();

}
}

Run(Output);

LIfebix

20

Instance variable:

The variable which is declared outside the method inside the class those variable are called Instance variables. Instance variable having default values. Every object having one separate copy of instance variable. the scope of instance variables is inside the class.

Example program:

public class instance {
String Name;  // instance variable default values
int a;               // default value printed
int k=100;
public static void main(String args[]){
instance i=new instance();
System.out.println(i.Name);
System.out.println(i.a);
System.out.println(i.k);

}
}

Run (Output):

null
0
100

9. Explain about static variable?

The variable which is declared inside the class and outside the method, constructor, block by using keyword static those variables are called as Static variable.

10. Explain about the method?

method are used for the business logics. A method is a set of code which is referred to by name and can be called (invoked) at any point in a program simply by utilizing the method’s name.  Think of a method as a subprogram that acts on data and often returns a value.

11. Explain about this keyword?

This keyword doesn’t work at static method. this is a reference variable, it refers the present object.

For Example:

* this keyword can be used as refers the present variable instance variable

* it used for the invoking the current class method.

* this can be used for passed an argument in the method call and constructor call.

For example programe:

public class thisexample {
int age=20;
public void suresh(){
int age=40;
System.out.println(age);

System.out.println(this.age);

}
public static void main(String args[]){
thisexample th=new thisexample();
th.suresh();

}

}

run (output):
40
20

12. explain about Static block?

Static block Is used fo initialize the static data member. The Stic block is executed before the main method at the time of class loading.

13. Explain about Static method?

By using of static keyword declare a method is called the static method. Static method can acces the static data , can change the value of data. this method can be invoked without creating any instance of class.

Example program:

public class staticexample {
public static int addTwoNumbers(int a,int b){
int k=a+b;
System.out.println(k);
return(k);
}
public int substractTwoNumbers(int a,int b){
int s=a-b;
System.out.println(s);

return(s);
}

public static void main(String args[]){

staticexample v=new staticexample();
v.addTwoNumbers(20,40);
v.substractTwoNumbers(40,10);

}
}
Run(Output);

60

30

14. Explain about method signature?

Methos signature can contains the method name, parameter, return type. We can’t declare same method name and signature.. We can declare with method name same with different signature.

15. Explain about Constructor?

Constructor doesn’t have any return type explicitily by default it is class type. The constructor name and class name should be same.

Constructors are two types

* Default constructor.

* Parametaraised constructor.

* Default constructor:

Default constructor does not have any parametrs. In amethod doesn’t have any method in a class automatically it calls the default method.

Example program:

public class constructorex{

public static void main(String args[]){
constructorex j=new constructorex();
System.out.println(“lifebix”);

}

}
Run (output):

lifebix

* Parametaraised constructor:

A constructor that has a parameter is known as parameteraised construcctor. The method and class shoul be the same. In a clss there is no any constructor automatically calls the default constructors, if there is any constructor in a class default constructor will be in visible.

16. Explain about arrays?

* Array is an object it is store the similar type of data.

* Once create an array we can not change increament and decreament lenght of the array.

* Array index start with zero, elements data stored in indexes.

Inheritance:

deriving a new from existing class by using of  implements (or) extends keywords is known as inheritance. existing class is known as super class or parent class and a new class is child class for parent class.
Life bix create for students who are feel difficult that’s way I am create a this web serving and sharing my knowledge inthis blog we are explained a technical round jam session, java technical intervieew round. Lifebix is explained a very well for Java interview Questions for technical round and Group discussion and jam session round all are explained very well.

Can try statements be nested?
Yes

17.What are ClassLoaders?
A class loader is an object that is responsible for loading classes. The class ClassLoader is an abstract class.

18.What is the difference between an Interface and an Abstract class?
An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. An interface has all public members and no implementation.

19.What will happen if static modifier is removed from the signature of the main method?
Program throws “NoSuchMethodError” error at runtime.

20. What is the default value of an object reference declared as an instance variable?
Null, unless it is defined explicitly.

21. Can a top level class be private or protected?
No, a top level class can not be private or protected. It can have either “public” or no modifier.

22. Why do we need wrapper classes?
We can pass them around as method parameters where a method expects an object. It also provides utility methods.

23. What is the difference between error and an exception?
An error is an irrecoverable condition occurring at runtime. Such as OutOfMemory error. Exceptions are conditions that occur because of bad input etc. e.g. FileNotFoundException will be thrown if the specified file does not exist.

24. Is it necessary that each try block must be followed by a catch block?
It is not necessary that each try block must be followed by a catch block. It should be followed by either a catch block or a finally block.

25. What is the Locale class?
The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region.

26. What are synchronized methods and synchronized statements?
Synchronized methods are methods that are used to control access to an object. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.

27. What is runtime polymorphism or dynamic method dispatch?
Runtime polymorphism or dynamic method dispatch is a process in which a call to an overridden method is resolved at runtime rather than at compile-time. In this process, an overridden method is called through the reference variable of a superclass.

28. What is Dynamic Binding(late binding)?
Binding refers to the linking of a procedure call to the code to be executed in response to the call. Dynamic binding means that the code associated with a given procedure call is not known until the time of the call at run-time.

29.Can constructor be inherited?
No, constructor cannot be inherited.

30. What are the advantages of ArrayList over arrays?
ArrayList can grow dynamically and provides more powerful insertion and search mechanisms than arrays.



31. Why deletion in LinkedList is fast than ArrayList?
Deletion in linked list is fast because it involves only updating the next pointer in the node before the deleted node and updating the previous pointer in the node after the deleted node.

32. What is Downcasting?
It is the casting from a general to a more specific type, i.e. casting down the hierarchy.

33. What are order of precedence and associativity and how are they used?
Order of precedence determines the order in which operators are evaluated in expressions. Associatity determines whether an expression is evaluated left-to-right or right-to-left.

34. If a method is declared as protected, where may the method be accessed?
A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.

35. What is the difference between inner class and nested class?
When a class is defined within a scope of another class, then it becomes inner class. If the access modifier of the inner class is static, then it becomes nested class.

36. What restrictions are placed on method overriding?
Overridden methods must have the same name, argument list, and return type. The overriding method may not limit the access of the method it overrides.

37. What is constructor chaining and how is it achieved in Java?
A child object constructor always first needs to construct its parent. In Java it is done via an implicit call to the no-args constructor as the first statement.

38. Can a double value be cast to a byte?
Yes, a double value can be cast to a byte.

39. How does a try statement determine which catch clause should be used to handle an exception?
When an exception is thrown within the body of a try statement, the catch clauses of the try statement are examined in the order in which they appear. The first catch clause that is capable of handling the exception is executed. The remaining catch clauses are ignored.

40.What will be the default values of all the elements of an array defined as an instance variable?
If the array is an array of primitive types, then all the elements of the array will be initialized to the default value corresponding to that primitive type.

Leave a Reply

Your email address will not be published.