Core Java Interview Questions
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 of the industry. This questionnaire will substantially contribute to achieve 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 development of general desktop applications. Simply speaking, it refers to the subset of Java SE technologies which consists of both general purpose API’s and special purpose API’s. 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 which covers everything from OOP concepts to special operators, from data types to wrapper classes, from 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 development of portable desktop applications. In addition to the general purpose API’s, 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 2020
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. Are Jvm's Platform Independent?
JVM's are not platform independent. JVM's 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 which is for development purpose and it includes 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?
Pointer is a reference handle to a memory location. Improper handling of pointers leads to memory leaks and reliability issues hence Java doesn't support the usage of pointers.
7. What Is The Base Class Of All Classes?
8. Does Java Support Multiple Inheritance?
Java doesn't support multiple inheritance.
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 Difference Between Path And Classpath?
Path and Classpath are operating system level environment variales. Path is used define where the system can find the executables(.exe) files and classpath is used to specify the location .class files.
12. What Are Local Variables?
Local varaiables are those which are declared within a block of code like methods. Local variables should be initialised 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 can't be changed also. static final int PI = 2.14; is an example for constant.
16. Should A Main Method Be Compulsorily Declared In All Java Classes?
No not required. main method should be defined only if the source class is a java application.
17. What Is The Return Type Of The Main Method?
Main method doesn't return anything hence declared void.
18. Why Is The Main Method Declared Static?
main method is called by the JVM even before the instantiation of the class hence it is declared as static.
19. What is object-oriented paradigm?
It is a programming paradigm based on objects having data and methods defined in the class to which it belongs. Object-oriented paradigm aims to incorporate the advantages of modularity and reusability. Objects are the instances of classes which interacts 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 object's 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.
- The examples of the object-oriented paradigm are C++, Simula, Smalltalk, Python, C#, etc.
20. What is an object?
The Object is the real-time entity having some state and behavior. In Java, Object is an instance of the class having the instance variables as 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.
21. What is the difference between an object-oriented programming language and object-based programming language?
There are the following basic differences between the object-oriented language and object-based language.
- Object-oriented languages follow all the concepts of OOPs whereas, the object-based language doesn't follow all the concepts of OOPs like inheritance and polymorphism.
22. 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.
23. 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.
24. 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 which 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 task 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 which 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.
25. Does constructor return any value?
yes, The constructor implicitly returns the current instance of the class (You can't use an explicit return type with the constructor).
26. Is constructor inherited?
No, The constructor is not inherited.
27. Can you make a constructor final?
No, the constructor can't be final.
28. 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.
- class Test
- int i;
- public Test(int k)
- public Test(int k, int m)
- System.out.println("Hi I am assigning the value max(k, m) to i");
- public class Main
- public static void main (String args)
- Test test1 = new Test(10);
- Test test2 = new Test(12, 15);
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.
29. 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.
30. 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 member 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 the 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 package.
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 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.
So here’s the good news, our article on Core Java Interview Questions have been designed specially to get you acquainted with the nature of questions you may encounter during your interview. We have covered 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 for your professional career and will be glad to help you with any queries related to Core Java Interview questions.