Interview questions about Java
Top 15 Interview questions about Java
1. What is Java?
A: Java is the high-level, object-oriented, robust, secure programming language, platform-independent, high performance, Multithreaded, and portable programming language. It was developed by James Gosling in June 1991. It can also be known as the platform as it provides its own JRE and API.
2. Why Java is not 100% Object-oriented?
A: Java is not 100% Object-oriented because it makes use of eight primitive data types such as boolean, byte, char, int, float, double, long, short which are not objects.
3. What is singleton class in Java and how can we make a class singleton?
A: Singleton class is a class whose only one instance can be created at any given time, in one JVM. A class can be made singleton by making its constructor private.
4. What kind of variable you can access in a lambda expression?
A: Using lambda expression, you can refer to final variable or effectively final variable (which is assigned only once). Lambda expression throws a compilation error, if a variable is assigned a value the second time.
5. Can you differentiate between J2SDK 1.5 and J2SDK 5.0?
A: There is really no difference between J2SDK 1.5 and J2SDK 5.0. The versions have been rebranded by Sun Microsystems.
6. Is Java by Reference or Pass by Value?
A: The Java Spec says that everything in Java is pass-by-value. There is no such thing as “pass-by-reference” in Java. The difficult thing can be to understand that Java passes “objects as references” passed by value.
7. Define JVM?
A: JVM is the abbreviation for Java Virtual Machine. It is a virtual machine that provides the runtime environment to write code. JVM is a part of JRE (Java Runtime Environment) and that is used to convert the bytecode into machine level language. This machine is responsible for allocating memory.
8. What are the different types of variables in Java?
A: There are mainly three different types of variables available in Java, and they are:
• Static Variables
• Local Variables
• Instance Variables
9. What is type conversion?
A: Type conversion can be defined as converting of one data type to another data type automatically by the compiler.
There are two types of type conversions, and they are:
• Implicit type conversion
• Explicit type conversion
10. What is the difference between static and new keyword?
A: New keyword is useful for providing memory for non-static data, it is individual, where as static keyword is useful for providing memory static data by default by JVM, it is common for all.
11. What is the use of constructor?
A: Constructor is useful for initialize the non-static variables meanwhile of object creation.
12. What is use of this () in java?
A: This () method is useful for making communication between one constructor to another constructor within the same class.
13. Can we this and super keywords in static context?
A: No, we are unable to use, the reason are by default non-static final reference variables.
14. What is factory method?
A: A method which is returns either same class memory other class memory is called factory method.
15. What is encapsulation?
A: The process of providing security for our data, if the end user is authorized then we should provides permissions to security data is called encapsulation.