Top 30 Core Java Interview Questions and Answers for Fresher, Experienced Developer

Want more awesome content? Sign up for our newsletter.

Java is a programming language and also a platform for computing. Java was first released by Sun Microsystems in the year 1995. There are lots of applications and websites that will not work unless Java is installed in them. Each day there are more and more applications created using Java. It is a very simple, powerful and robust, programming language which provides a fast, secure, and reliable platform to work on. Java is being used everywhere, from laptops to data centers, game consoles to scientific supercomputers, and cell phones to the Internet.

Due to its ease of use and simplicity, Java is used almost everywhere in the IT sector. This means that the professionals who are skilled in Java are always required. If you are someone who is likely to attend a job that would test you on your Java skills, then please go through the list of questions and their answers provided herein. You may also refer to them just to add on to your knowledge.

Core Java Interview Questions and Answers cover:

  1. Core Java Interview Questions for Fresher
  2. Core Java interview Questions for Experienced
  3. Core Java Interview Questions for Senior Developer

Core Java Interview Questions 

  1. Explain the difference between JDK, JRE, and JVM.
  2. What makes Java a platform-independent programming language?
  3. Would it be correct to say that Java is not 100% Object-oriented?
  4. What is a constructor in Java?
  5. Differentiate between a constructor and a method? Can we mark constructors final?
  6. What is a class in Java?
  7. State the significance of public, private, protected class.
  8. What is the final class?
  9. What is a wrapper class?
  10. What is an abstract class?
  11. Describe synchronization with respect to multi-threading.
  12. What is the purpose of garbage collection in Java, and when is it used?
  13. What are the different ways of implementing thread? Which one is more advantageous?
  14. What if the main() method is declared as private? What happens when the static modifier is removed from the signature of the main() method?
  15. What is the first argument of the String array in main() method?
  16. What is a Java servlet?
  17. Describe the Life-cycle of a Java Servlet.
  18. Explain the Request Dispatcher?
  19. List the steps to connect to a database in java?
  20. What do you mean by a JDBC Driver?
  21. What is a Java applet?
  22. What is a numeric promotion?
  23. What is false sharing in the context of multi-threading?
  24. What are the methods used to implement for the key Object in HashMap?
  25. What is an immutable object?
  26. Differentiate between String Buffer and String Builder in Java?
  27. What is the difference between factory and abstract factory pattern?
  28. Differentiate JAR and WAR files
  29. What is a JIT compiler?
  30. What is the multi-catch block in Java? 

Java Interview Questions & Answers for Developer

For a Java enthusiast who is looking to attend a Java interview anytime soon, here are the most popular interview questions and answers that might come your way. We have tried to include the top frequently asked questions as well as their answers to help freshers and the experienced professionals with their job interview. 

Q1). Explain the difference between JDK, JRE, and JVM.

JDK JRE JVM
JDK stands for Java Development Kit and is the tool used to compile, package and document Java programs. JRE stands for Java Runtime Environment and is a runtime environment which is a pre-requisite to run java byte-code. JVM stands for Java Virtual Machine and is a specification that facilitates a run-time environment in which Java’s bytecode can be implemented.
Read:   Top 20 QTP Interview Questions and Answers

Q2). What makes Java a platform-independent programming language?

Java is platform independent because it provides the feasibility to run and compile the program in one platform and execute the program on any other platform of your choice.

Q3). Would it be correct to say that Java is not 100% Object-oriented?

Yes, it would be correct to say that Java is not 100% Object-oriented because it utilizes eight kinds of primitive data types and they are – Boolean, byte, char, int, float, double, long, short. These datatypes are not objects.

Q4). What is a constructor in Java?

A constructor is a block of code which is used in a Java environment to initialize an object. It carries the same name that you had given to the class. A Java constructor is automatically called when an object is created.

Q5). Differentiate between a constructor and a method? Can we mark constructors final?

A constructor constructs the value, by providing data for the object. It is a special type of method that is used to initialize the object. The constructor has the same name as the class itself, has no return type, and is invoked using the new operator.

A method is an ordinary member function of a class. A method can be invoked using the dot operator and has its own name, and a return type. No, declaring the constructor as final is not possible.

Q6). What is a class in Java?

A class, in the environment of Java, are some templates which are used for object creation, and to define certain object datatypes and their methods.

Q7). State the significance of public, private, protected class.

  • Public: When a class is public, the public class is visible in other packages, the field is visible everywhere.
  • Private: Private variables or methods can be used by an instance of the same class only which declares the variable or method. A private feature can be accessed by the class that owns the feature.
  • Protected: Protected variable is available to all classes in the same package. It is also available to all subclasses of the class that owns the protected feature. Subclasses that reside in a different package also is provided with the access from the class that owns the protected feature.

Q8). What is the final class?

A final class is a constant value of a final variable. Extending A final class is not possible ie., final class may not be sub-classed. A final method cannot be overridden when its class is inherited. 

Q9). What is a wrapper class?

The classes that “wrap” the primitive data type into an object of that class are called Java wrapper classes.

Core Java interview Questions for Experienced 

Q10). What is an abstract class?

Abstract serves as a template. In order to use an abstract class, it must be extended or subclassed. An abstract class may not be instantiated.

Any class with an abstract method is abstract itself, hence is declared as such.

Read:   Social Media Marketing Interview Questions and Answers

Q11). Describe synchronization with respect to multi-threading.

Synchronization is the method to control the access of multiple threads to shared resources, with respect to multi-threading.

One thread can modify a shared variable when not in synchronization even when another thread is in the process of using or updating the same shared variable. This can lead to significant errors.

Q12). What is the purpose of garbage collection in Java, and when is it used?

The main purpose of garbage collection is to analyze a program, identify and discard the objects that are no longer needed. It is helpful as the resources can be reclaimed and reused.

A Java object is subjected to garbage collection when the object is not reachable to the program in which it is used.

Q13). What are the different ways of implementing thread? Which one is more advantageous?

The thread can be implemented by

Using runnable interface

Inheriting from the Thread class.

The use of the Runnable interface is more advantageous because when going for multiple inheritances, the only interface can help.

Q14). What if the main() method is declared as private? What happens when the static modifier is removed from the signature of the main() method?

When the main() method is declared as private, the program compiles but during runtime it shows “main() method not public.” Message.

When the static modifier is removed from the signature of the main() method, the Program compiles but at runtime throws an error “NoSuchMethodError”.

Q15). What is the first argument of the String array in main() method?

Unlike in C/C++ where the first element by default is the program name, the string array in main() has no element, the String array is empty. 

Q16). What is a Java servlet?

A Servlet in Java refers to the server-side technologies which are used to extend the competence of web servers by giving it support for a dynamic response as well as data persistence.

Q17). Describe the Life-cycle of a Java Servlet.

Here is the life-cycle of a Java Servlet-Core Java Interview Questions

  • Servlet is loaded
  • Servlet is instantiated
  • Servlet is destroyed
  • Servlet is initialized
  • Service the request

Q18). Explain the Request Dispatcher?

Request Dispatcher is a Java interface which is used to forward a request to some other resource which can be HTML, JSP or any another Java servlet within the same application.

Q19). List the steps to connect to a database in java?

Follow the given steps to connect to a database in java-

  • Close the Connection
  • Register the Drive Class
  • Create Connection
  • Create Statement
  • Execute Queries

Q20). What do you mean by a JDBC Driver?

JDBC Driver in Java refers to a software component that allows Java application to relate with the database.

Core Java Interview Questions

There are 4 types of JDBC drivers in Java-

  • JDBC-ODBC bridge driver
  • Native-API driver (partially java driver)
  • Network Protocol driver (fully java driver)
  • Thin driver (fully java driver) 

Core Java Interview Questions for Senior Developer 

Q21). What is a Java applet?

The applet is a Java program which is designed for transmitting the Java code over the internet. The execution works automatically by Java-enabled Web Browser. The applet can respond to the user input immediately as it is dynamically programmed.

Read:   Top 40 Advanced Mobile Testing Interview Questions and Answers

Q22). What is a numeric promotion?

Numeric promotions of a numeric operator are used for the conversion of the operands into a common type. In order to perform calculation easily, numeric promotion, conversion is performed.

It is the conversion of a smaller numeric type to a larger numeric type so that integer and floating-point operations can be performed over it. Here byte, char, and short values are converted to int values. The int values are converted to long values, and the long and float values are converted to double values.

Q23). What is false sharing in the context of multi-threading?

On multi-core systems, false sharing is one of the well-known performance issues. Here each process has its local cache. When threads on a different processor, modify variables false sharing occurs, that resides on the same cache line as shown in the following images

Core Java Interview Questions

As the thread may access different global variables completely, false sharing can be hard to detect.

Q24). What are the methods used to implement for the key Object in HashMap?

Equals and hashcode methods are to be implemented In order to use any object as Key in HashMap, in Java.

Q25). What is an immutable object?

Java classes whose objects cannot be modified once they are created are known as Immutable classes. Any modification of Immutable object results formation of the new object. 

Q26). Differentiate between String Buffer and String Builder in Java?

The only difference between StringBuffer and StringBuilder is that StringBuffer methods are synchronized while StringBuilder is not synchronized. StringBuilder in Java was introduced in Java 5.

Core Java Interview Questions

Q27). What is the difference between factory and abstract factory pattern?

Abstract Factory provides one more level of abstraction. Consider different factories each extended from an Abstract Factory and responsible for the creation of different hierarchies of objects based on the type of factory. E.g. Abstract Factory extended by Automobile Factory, User Factory, Role Factory etc. Each individual factory would be responsible for the creation of objects in that genre.

Q28). Differentiate JAR and WAR files

We are going to share Difference between JAR & WAR File:

JAR FILES WAR FILES
Full form of JAR files is Java Archive Files. Full form of WAR files is Web Archive Files.
Aggregating many files into one is allowed in JAR files XML, Java classes, and JavaServer pages are stored in WAR
The JAR is usually used to hold Java classes in a library. Mainly used for Web Application purposes.`

 

Q29). What is a JIT compiler?

Just-In-Time(JIT) compiler is used to improve the performance. JIT compiles parts of the bytecode that has similar functionality which in turn reduces the amount of time needed for compilation. The term “compiler” here refers to a translator from the instruction set of a Java virtual machine (JVM) to the instruction set of a specific CPU.

Q30). What is the multi-catch block in Java?

Multi-catch block makes the code shorter and cleaner when every catch block has a similar code. We can catch multiple exceptions in a single catch block using this feature.

JanBask Training

JanBask Training

JanBask Training is a leading Global Online Training Provider through Live Sessions. The Live classes provide a blended approach of hands on experience along with theoretical knowledge which is driven by certified professionals.



8
Write a Comment

avatar
  Subscribe  
newest oldest most voted
Notify of
James
Guest
James

Core java is most Important part of Java.I am Looking for latest interview questions, which is help for Job Purpose. Thank you for sharing great list of core java interview questions with answers.

Devid Mark
Guest
Devid Mark

This is a very helpful post for people like me who preparing for java interview. I appreciate your efforts and time that you have taken to write useful questions along with answers. I would definitely suggest this blog to my friends. Keep it up!!

Rosy disuza
Guest
Rosy disuza

difference between an Inner Class and a Sub-Class I think An Inner class is a class which is nested within another class. An Inner class has access rights for the class which is nesting it and it can access all variables and methods defined in the outer class
I’m not sure so please give me confirmation

aliya mehra
Guest
aliya mehra

This blog is very helpful for my interview i read it and went to attend my interview with a company for java developer . and i feel it most of question are mentioned in this blog and i’m heartily thanks for this blog’s owner

Jessica Roberts
Guest
Jessica Roberts

This core java questions & answers tutorial is very informative and covers all the important concepts of core java. Java is a programming language expressly designed for use in the distributed environment of the Internet. Thank you!!

Blake Simpson
Guest
Blake Simpson

Thank you so much for sharing everything in details. I want to switch to core java and looking for some interesting books. Can you suggest me some books or provide me with a way to learn it quickly?

Trending Blogs

Top 30 Core Java Interview Questions and...
Top 20 AWS Interview Question and Answers...
Spring MVC Interview Questions and Answers
Top 30 Manual Testing Interview Questions &...

Related Posts

Top 30 Manual Testing Interview Questions &...
Top 15 Security Testing Interview Questions and...
C# Interview Questions and Answers
Top 30 Core Java Interview Questions and...
Top 20 Big Data Hadoop Interview Questions...