JAVA (OOP) INTERVIEW QUESTIONS FOR JOB
1. What is the difference between JVM and JRE?
Java Runtime Environment (JRE) is the implementation of JVM. JRE consists of JVM and java binaries and other classes to execute any program successfully. JRE doesn’t contain any development tools like java compiler, debugger etc. If you want to execute any java program, you should have JRE installed.2. What is the difference between JDK and JVM?
Java Development Kit (JDK) is for development purpose and JVM is a part of it to execute the java programs.JDK provides all the tools, executables and binaries required to compile, debug and execute a Java Program. The execution part is handled by JVM to provide machine independence.
3. Why Java is not pure Object Oriented language?
Java is not said to be pure 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. Obviously, java could have wrapper objects for the primitive types but just for the representation, they would not have provided any benefit.4. What is the importance of the main method in Java?
main() method is the entry point of any standalone java application. The syntax of the main method is public static void main(String args[]).The main method is public and static so that Java can access it without initializing the class. The input parameter is an array of String through which we can pass runtime arguments to the java program.
5. What is the static keyword?
Static keyword can be used with class level variables to make it global i.e all the objects will share the same variable.static keyword can be used with methods also. A static method can access only static variables of class and invoke only static methods of the class.
A static variable is a class variable and doesn’t belong to Object/instance of the class.
6. What is static block?
Java static block is the group of statements that gets executed when the class is loaded into memory by Java ClassLoader. It is used to initialize static variables of the class. Mostly it’s used to create static resources when a class is loaded.7. Can we declare a class as static?
We can’t declare a top-level class as static however an inner class can be declared as static. If inner class is declared as static, it’s called static nested class.Static nested class is same as any other top-level class and is nested for only packaging convenience.
8. Can we have multiple public classes in a java source file?
We can’t have more than one public class in a single java source file. A single source file can have multiple classes that are not public.9. What is Java Package and which package is imported by default?
Java package is the mechanism to organize the java classes by grouping them. The grouping logic can be based on functionality or modules based. A java class fully classified name contains package and class name. For example, java.lang.Object is the fully classified name of Object class that is part of java.lang package.java.lang package is imported by default and we don’t need to import any class from this package explicitly.
10. What is the final keyword?
final keyword is used with Class to make sure no other class can extend it, for example, String class is final and we can’t extend it.We can use the final keyword with methods to make sure child classes can’t override it.
final keyword can be used with variables to make sure that it can be assigned only once. However the state of the variable can be changed, for example, we can assign a final variable to an object only once but the object variables can change later on.
Java interface variables are by default final and static.
Name some OOPS Concepts in Java?
Java is based on Object Oriented Programming Concepts, following are some of the OOPS concepts implemented in java programming.- Abstraction
- Encapsulation
- Polymorphism
- Inheritance
- Association
- Aggregation
- Composition
References
https://www.edureka.co/blog/interview-questions/java-interview-questions/#basichttps://www.journaldev.com/2366/core-java-interview-questions-and-answers
https://www.oodesign.com/
https://www.geeksforgeeks.org/singleton-class-java/
https://github.com/eugenp/tutorials/tree/master/core-java
Comments
Post a Comment