1. Define Java
Java is a general-purpose, Object-oriented programming and most widely used language which was developed by James Gosling in the 1990s. It’s a system-independent language where one can run the compiled byte code in any other system which contains JRE in it.
2. Explain the Features of Java
The features of Java include
Platform Independent – The byte code generated on one computer can run on another system.
Robust – Can easily handle errors during execution.
Multithreaded – IT enables users to write programs that can perform many tasks at a time.
Object Oriented – As we know everything in java is an Object.
Performance – The inclusion of JIT Compilers in JRE increases their performance than other programming languages.
3. Define variables in Java and their types.
Variables are the storage locations that are used to store different types of data. In Java, there are three types of variables based on their scope. They are
Local Variables – These are the variables that are declared inside a method
Static Variables – These are the variables when one wants to initialize when the execution of the program starts. They are defined using the static keyword.
Instance Variables – These are defined outside the method but inside the class.
4. Difference between JDK, JRE, and JVM.
JDK (Java Development Kit) is a Software Development Environment that is used for developing java programs. JRE (Java Runtime Environment) is a space that enables users to execute java programs and JVM (Java Virtual Machine) is responsible for providing the runtime environment in which java compiler-generated byte code can be executed.
5. What is meant by JIT Compiler? Define its usage
JIT (Just In Time) Compiler is responsible for compiling code at runtime instead of compiling it during the compile time of the programs (also known as Ahead-Of-Time). It improves the performance of java programs by compiling the generated byte code into machine code at run time.
6. Wrapper classes in Java?
The main objective of introducing wrapper classes is when one wants to convert primitive data types to object types and vice versa. There are some cases where the util package handles only objects then we need to convert the primitive types to objects using these wrapper classes. The wrapper class for int is Integer, char Character, double-Double, etc.
7. What are various access specifiers in Java?
In general access specifiers when we want to restrict the usage of variables under the scope. Mainly There are three access specifiers in java. They are
Public – These members can be accessible everywhere in the program.
Private – These members are accessible only inside the class.
Protected – These members can be accessed outside the package only with the help of child class.
8. Why the main method in Java is declared static?
In Java, the static method is the one that is going to create inside the memory even before initializing the instance(object) of it. So, as we all know that in java the execution starts from the main method, we need to make sure that the main method is called first with the help of declaring it as a static method.
9. Is it possible to execute a Java program without the main method?
Yes, we can execute the java program without the main method up to JDK 6 by initializing the static block but from JDK version 7 it’s mandatory to include the main method in the java program because the JVM finds the main() method in the program first.
10. Method Overloading in Java?
The process of writing the same method in different ways in a single program is known as Method Overloading in Java. The method can be overloaded in two ways in java one is by changing the number of arguments we are going to pass to that function and another way is to change the data type of the arguments.
11. Final keyword and its usage in Java?
The final keyword in java is used when we want to make sure that the state/value of the variable or object Shouldn’t be changed once it’s initialized. So, when a final keyword is used in the declaration of class then no inheritance is possible if we declare a method using the final keyword then that method cannot be overridden and finally the final variable cannot be changed once it was initialized.
12. Is Java a pure object-oriented language?
No, Java is not a pure object-oriented language. The existence of primitive data types in java language makes it a True Object-oriented language instead of Pure because the primitive data type literals are considered as values not as objects so to convert them to objects, they introduced wrapper classes.
13. Constructors and their types in Java.
Constructors are special methods in java that are invoked when an object is created instead of explicitly calling like general methods. There are three types of constructors in java
Default Constructor
No argument Constructor
Parameterized Constructor
14. Explain the Singleton class in Java.
As the name indicates singleton class in java refers to a class that can have a maximum of only one instance (object). The main purpose of introducing them is to restrict the creation of objects.
15. Is Java object-oriented or object-based language? Justify your answer.
Java is an object-oriented language because it’s capable of implementing all OOPS concepts when it comes to object-based languages the objects are pre-defined in them instead of creating them explicitly we’ll simply use them. JavaScript is a good example of an Object-based language because even though it has the concept of an object but can’t be able to implement OOPS concepts like Java does.
Advanced Java Interview Questions
1. What is a reflection in Java?
The reflection in Java is an API that is used to inspect other code which is present in the same node where it is running. This reflection is also used to give information about the instance to which an object belongs.
2. How to differentiate the interface and class in Java?
Even though both are used to achieve abstraction in Java. When it comes to the implementation point of view the abstract classes can have both abstract and non–abstract methods when it comes to the interface only abstract methods are allowed to include in the body of the interface.
3. Does java supports the concept of pass-by-reference?
No, java does not explicitly support the concept of pass-by-reference because there is the concept of pointers in java. In Java, everything is passed as values so we can java only supports the pass-by value and implicitly these are passed as references.
4. What is meant by JavaBean?
Java Bean is a java class that follows some specifications it must have a no-argument constructor, the class should be serializable and it must contain setter and getter methods. Simply we can say that java bean classes are the foundation stones to achieve encapsulation in Java.
5. What is meant by marker interface in Java?
The marker is an empty interface in java which means it consists of no methods in it. This interface is responsible to provide run-time information about objects. There are three types of marker interfaces in java Serializable, Cloneable, and Remote interfaces.
6. Why are Character arrays preferable in java to String?
The strings in java are immutable objects so it’s difficult to perform any operations on them. When it comes to character arrays, they are mutable objects in java so without using any methods we can directly perform operations on them. So, the Character arrays are preferred over Strings in Java.
7. What is meant by Dynamic Methos Dispatch in Java?
The dynamic method dispatch is the mechanism by which a call to an overridden method is resolved at runtime. This means with this process Runtime Polymorphism can be implemented in Java.
8. Name the Inheritance which is not supported by Java using classes?
Multiple Inheritance is a type of inheritance that is not possible using Java using classes. Here In multiple Inheritance, the child class inherits the properties of one or more parent classes at a time. So during that, if that multiple parent classes might have methods with the same name so here the conflict arises and this can be achieved through interfaces by implementing them.
9. Discuss Exception Handling in Java.
The process of handling errors or exceptions during the runtime to make sure the execution flow does affect because of them is known as Exception Handling in Java. Exceptions can be handled mainly using five keywords in Java
try – In this block the exceptional code is placed
catch – used to catch the errors that were thrown by a try block
finally – used to execute irrespective of exceptions
throw – used to throw an exception
throws – this is used to declare user declare exceptions
10. Usage of the super keyword.
The super is a keyword in Java that is used to refer to the superclass objects. The super is used to call super class methods and constructors when the user wants to access them after their declaration.
11. Explain Map in Java?
The map is an interface in Java. This map is used to implement collections that contain key-value pairs.
No duplication of keys is allowed in the Map interface.
12. Is it possible to override the private or static method in Java?
No, it’s not possible to override static or private methods in Java because the private methods are the ones that have some limited access to perform operations and when it comes to the static method if you override them the sub-class methods are considered instead of superclass methods.
13. What are servlets in Java?
Servlets are used the extend the capabilities of web servers and also used to implement dynamic web pages. These can be implemented using javax.sevlet.http package.
14. What is JDBC?
The JDBC is an acronym for Java Data Base Connectivity. JDBC is a driver software that enables java programs to establish connections with databases.
15 Name one popular framework in Java.
Spring is a Java Application Framework that is used to build Enterprise Applications. It follows MVC (Model, View, Control) approach which ensures developer to achieve robust exception-handling techniques. This Framework provides good infrastructural support at the application level with the help of plumbing techniques.