logo

Core Java Interview Questions


Show

In today’s competitive world, everyone is ambitious for securing a high-paying job. A career in Java is the most sought-after in this technology world. To get into your dream job, the first and the foremost hurdle to achieve is - Cracking an Interview with confidence.

This article covering almost everything about Core Java interview questions will help you in revising for entry-level as well as experienced developers. The Core Java Interview Questions are prepared by our most experienced experts in the industry. This questionnaire will substantially contribute to achieving your dream job.

About Core Java

"Core Java" is a general term used by Sun Microsystems to describe the standard version of Java (JSE). It’s the most basic version of Java which sets the foundation for all other editions of Java plus a set of related technologies such as CORBA, Java VM, Java Naming and Directory Interface (JNDI), Tools API, etc. Core Java refers to a collection of libraries rather than just the programming language. It’s the purest form of Java primarily used for the development of general desktop applications. Simply speaking, it refers to the subset of Java SE technologies which consists of both general-purpose API and special-purpose APIs. It provides the core functionality of Java with the deep knowledge of the Java language itself.

Core Java is just a part of Java which stands for J2SE containing all the basics of Java including some principles and package details. It’s a stand-alone Java application that covers everything from OOP concepts to special operators, from data types to wrapper classes, from the Linked list to Array list, and queue to exception handling. There are three computing platforms based on the Java programming language, including the Java SE. It still is the most widely used platform based on the concept of OOP and is commonly used for the development of portable desktop applications. In addition to the general-purpose APIs, it consists of development tools, a virtual machine, and other class libraries. It also includes the Java Virtual Machine Specification.

The concepts from core Java are - OOPS concepts (Data Abstraction, Encapsulation, Inheritance, Polymorphism), Basic Java constructs like loops and data types, String handling, Collection framework, Multithreading, Exception Handling, Generics, Synchronization.

Best Core Java Interview Questions of 2024

1. What is Java?

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. What Do You Mean By Platform Independence?

Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (Linux, Solaris, etc).

3. Is Jvms Platform Independent?

JVMs are not platform-independent. JVMs are platform-specific run time implementation provided by the vendor.

4. What Is A Jvm?

JVM is Java Virtual Machine which is a run time environment for the compiled java class files.

5. What Is The Difference Between A Jdk And A Jvm?

JDK is Java Development Kit that is for development purposes and it includes an execution environment also. But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM.

6. What Is A Pointer And Does Java Support Pointers?

A pointer is a reference handle to a memory location. Improper handling of pointers leads to memory leaks and reliability issues hence Java doesnt support the usage of pointers.

7. What Is The Base Class Of All Classes?

java.lang.Object

8. Does Java Support Multiple Inheritance?

Java doesnt support multiple inheritances.

9. Is Java A Pure Object-Oriented Language?

Java uses primitive data types and hence is not a pure object-oriented language.

10. Are Arrays Primitive Data Types?

In Java, Arrays are objects.

11. What Is the Difference Between Path And Classpath?

Path and Classpath are operating system-level environment variables. The path is used to define where the system can find the executables(.exe) files and classpath is used to specify the location of .class files.

12. What Are Local Variables?

Local variables are those which are declared within a block of code-like methods. Local variables should be initialized before accessing them.

13. What Are Instance Variables?

Instance variables are those which are defined at the class level. Instance variables need not be initialized before using them as they are automatically initialized to their default values.

14. How To Define A Constant Variable In Java?

The variable should be declared as static and final. So only one copy of the variable exists for all instances of the class and the value cant be changed also. static final int PI = 2.14; is an example for constant.

15. Should The Main Method Be Compulsorily Declared In All Java Classes?

No not required. the main method should be defined only if the source class is a java application.

16. What Is The Return Type Of The Main Method?

The main method doesnt return anything hence declared void.

17. Why Is The Main Method Declared Static?

the main method is called by the JVM even before the instantiation of the class hence it is declared as static.

18. What is an object-oriented paradigm?

It is a programming paradigm based on objects having data and methods defined in the class to which it belongs. The object-oriented paradigm aims to incorporate the advantages of modularity and reusability. Objects are the instances of classes that interact with one another to design applications and programs. There are the following features of the object-oriented paradigm.

  • Follows the bottom-up approach in program design.
  • Focus on data with methods to operate upon the objects data
  • Includes the concept like Encapsulation and abstraction which hides the complexities from the user and show only functionality.
  • Implements the real-time approach like inheritance, abstraction, etc.
  • Examples of the object-oriented paradigm are C++, Simula, Smalltalk, Python, C#, etc.

19. What is an object?

The Object is the real-time entity having some state and behavior. In Java, an object is an instance of the class having the instance variables like the state of the object and the methods as the behavior of the object. The object of a class can be created by using the new keyword.

20. What is the difference between an object-oriented programming language and an object-based programming language?

There are the following basic differences between object-oriented language and object-based language.

  • Object-oriented languages follow all the concepts of OOPs whereas, the object-based language doesnt follow all the concepts of OOPs like inheritance and polymorphism.
  • Object-oriented languages do not have inbuilt objects whereas Object-based languages have inbuilt objects, for example, JavaScript has window objects.
  • Examples of object-oriented programming are Java, C#, Smalltalk, etc. whereas the examples of object-based languages are JavaScript, VBScript, etc.

21. What will be the initial value of an object reference which is defined as an instance variable?

All object references are initialized to null in Java.

22. What is the constructor?

The constructor can be defined as the special type of method that is used to initialize the state of an object. It is invoked when the class is instantiated, and the memory is allocated for the object. Every time, an object is created using the new keyword, the default constructor of the class is called. The name of the constructor must be similar to the class name. The constructor must not have an explicit return type.

23. How many types of constructors are used in Java?

Based on the parameters passed in the constructors, there are two types of constructors in Java.

  • Default Constructor: default constructor is the one that does not accept any value. The default constructor is mainly used to initialize the instance variable with the default values. It can also be used for performing some useful tasks on object creation. A default constructor is invoked implicitly by the compiler if there is no constructor defined in the class.
  • Parameterized Constructor: The parameterized constructor is the one that can initialize the instance variables with the given values. In other words, we can say that the constructors which can accept the arguments are called parameterized constructors.

24. Does the constructor return any value?

yes, The constructor implicitly returns the current instance of the class (You cant use an explicit return type with the constructor).

25. Is the constructor inherited?

No, The constructor is not inherited.

26. Can you make a constructor final?

No, the constructor cant be final.

27. Can we overload the constructors?

Yes, the constructors can be overloaded by changing the number of arguments accepted by the constructor or by changing the data type of the parameters. Consider the following example.

  1. class Test
  2. {
  3. int i;
  4. public Test(int k)
  5. {
  6. i=k;
  7. }
  8. public Test(int k, int m)
  9. {
  10. System.out.println("Hi I am assigning the value max(k, m) to i");
  11. if(k>m)
  12. {
  13. i=k;
  14. }
  15. else
  16. {
  17. i=m;
  18. }
  19. }
  20. }
  21. public class Main
  22. {
  23. public static void main (String args[])
  24. {
  25. Test test1 = new Test(10);
  26. Test test2 = new Test(12, 15);
  27. System.out.println(test1.i);
  28. System.out.println(test2.i);
  29. }
  30. }

In the above program, The constructor Test is overloaded with another constructor. In the first call to the constructor, The constructor with one argument is called, and I will be initialized with the value 10. However, In the second call to the constructor, The constructor with the 2 arguments is called, and I will be initialized with the value 15.

28. What is the static method?

  • A static method belongs to the class rather than the object.
  • There is no need to create the object to call the static methods.
  • A static method can access and change the value of the static variable.

29. What are the restrictions that are applied to the Java static methods?

Two main restrictions are applied to the static methods.

  • The static method can not use non-static data members or call the non-static method directly.
  • this and super cannot be used in static context as they are non-static.

Career scopes and salary scale

There are a lot of career opportunities for Core Java talent. Once you get a sound knowledge about Java, it will open all doors for learning lots of tools and technology around Java. Java is the best choice when coming to working with various domains and high pay packages.

Most of the reputed companies like Google, Amazon, IBM, Infosys, CTS, and TCS, etc. are using java as their preferred Programming Language. Java Programmer Salary in the technology industry is one of the most lucrative in this world. The average pay for a Java Programmer is around $67,129 per year. Experience strongly influences income for this job segment. The average salary for an experienced Java Developer in the USA is more than $102,000. For entry-level developers, salaries are still extremely competitive and often far higher than other entry-level roles.

Conclusion

So here’s the good news, our article on Core Java Interview Questions has been designed specially to get you acquainted with the nature of questions you may encounter during your interview. We have covered an entire variety of Core Java Interview Questions and answers which will eventually help you qualify for the interview and provide you with a successful career outlook. We wish you all the best in your professional career and will be glad to help you with any queries related to Core Java Interview questions.