Core Java

Here we are going to list down the frequently most asked Core Java Interview Questions for professionals. The questions are created and submitted by professionals to help you to ace the job interview.

Q.1 What is the first step in a JDBC program
Establish the connection between Java and SQL using JDBC Driver classes
Q.2 How many panels are visible when card layout is applied
1
Q.3

Given:

static class A

{

void process() throws Exception

{

throw new Exception();

}

}


static class B extends A

{

void process()

{

System.out.println("B");

}

}


public static void main(String[] args)

{

new B().process();

}


What is the result?

The code runs with no output.
Q.4

Given:

int x= 10;

do {

x--;

}

while (x < 10);


How many times will line 'x--;' be executed?

more than ten times
Q.5

Given:

int x= 0;

int y = 10;

do {

y--;

++x;

}

while (x < 5);

System.out.print(x + "," + y);


What is the result?

5,6
Q.6

Given:

public class Test

{

public enum Dogs {collie, harrier};

public static void main(String [] args)

{

Dogs myDog = Dogs.collie;

switch (myDog)

{

case collie:

System.out.print("collie ");

case harrier:

System.out.print("harrier ");

}

}

}


What is the result?

collie harrier
Q.7 How does Java helps in enabling high performance?
Java helps in enabling high performance by using Just In Time (JIT) compiler. JIT compiler is used to convert the instructions into bytecodes.
Q.8 What do you understand by Local variable and Instance variable?
Local variables refers to those variables that are defined in the method and scope of the variables that have existed inside the method itself. Where on the other hand an instance variable is defined inside the class and outside the method and scope of the variables exist throughout the class.
Q.9 What do you understand by Overloading?
The process of overloading occurs for different classes or within the same class. In order to implement method overloading, subclass method should satisfy some conditions with the Super class method (or) methods in the same class itself like -
1. Must have same method name
2. Must have different argument type
3. May have different return types
Q.10 Why is Java said to be 'Platform Independent'?
Java is said to be platform independent due to its byte codes that can run on any system irrespective of its underlying operating system.
Q.11 Explain the utility of static methods and variables in Java programming language
The shared methods or variables of a class are shared amongst all the objects of the class.
Q.12 Why is Java not considered as 100% Object-oriented?
Java is said to be not 100% Object-oriented since it makes use of eight primitive data types like Boolean, byte, char, int, float, double, long, short which are not considered as objects.
Q.13

List the output of the following Java programming language program?

class Test

{

public static void main (String args[])

{

for(int i=0; 0; i++)

{

System.out.println("Hello User1");

}

}

}

Compile-time error is generated as an integer value of 0 is provided to the loop's second part instead of a Boolean.
Q.14 What do you understand by wrapper classes?
Wrapper classes are used to convert the Java primitives into the reference types (objects). Such that every primitive data type has a class defined to it. These are referred as wrapper classes since they “wrap” the primitive data type into an object of that class. .
Q.15 Illustrate the reason for keeping the main method as static
Static method does not needs object, for being called to execute hence, the main method is static else JVM will need memory to create the object and then call main() object.
Q.16 Give reason for not using pointers in Java?
Java does not prefer to use pointers since they are considered as unsafe and increases the complexity of the program. From the beginning Java has been known for its simplicity of code, therefore adding the concept of pointers will be contradicting. Also Java Virtual Machine (JVM) is responsible for implicit memory allocation, therefore in order to avoid direct access to memory by the user, pointers are not suggested in Java.
Q.17 Why the abstract methods are not made static in Java programming language?
Abstract methods if made static, can be called directly and as they are undefined hence, it is of no use
Q.18 Explain JIT compiler in Java.
JIT is abbreviated for Just-In-Time compiler in Java. JIT compiler is a program that helps in converting the Java bytecode into instructions that are sent directly to the processor. The JIT compiler is enabled by default in Java and activated whenever a Java method is invoked. JIT compiler then compiles the bytecode of the invoked method into native machine code, compiling it “just in time” to execute. Therefore when the method has been compiled, the JVM summons the compiled code of that method directly rather than interpreting it. That is the reason why it is considered responsible for the performance optimization of Java applications at the run time.
Q.19 Why the constructor is not declared final in Java programming language?
As the constructor is never inherited hence, it is not declared as final else, it will be a compile time error.
Q.20 Define access modifiers in Java.
Access modifiers are special keywords in Java that are used to restrict the access of a class, constructor, data member and method in another class. In general, Java supports four types of access modifiers -
1. Default
2. Private
3. Protected
4. Public
Q.21 Why the interface is not declared final in Java programming language?
As interface needs a class for implementation hence, it cannot be declared final in Java programming language else it will be a compile time error.
Q.22 What do you understand by Object Oriented Programming?
Object-oriented programming also referred as OOPs is a programming model where the programs are organized around objects rather than logic and functions. Such that the primary focus of OOPs is on the objects that are required to be manipulated instead of logic. This Object Oriented Programming approach is suitable for the programs with large and complex codes and needs to be actively updated or maintained.
Q.23 Differentiate amongst the final and abstract method in Java programming language
The main difference being that the abstract method cannot be declared as final else it would not be able to be overridden in the subclass.
Q.24 How would you define Java String Pool?
Java String pool is defined as a collection of Strings that are stored in heap memory. Such that whenever a new object is created, String pool first checks whether the object is already present in the pool or not. If it is present, then the same reference is returned to the variable otherwise new object is created in the String pool and then respective reference is returned.
Q.25 Describe HTTP-tunnelling use in RMI
HTTP-tunnelling manage the HTTP connections by using the proxy servers and allow only inbound TCP connections. They do not need any configuration if present in firewall environment
Q.26 What do you understand by constructor chaining in Java?
Constructor chaining is defined as the process of calling one constructor from another with reference to the current object. Such that constructor chaining is only possible only through legacy where a subclass constructor is responsible for invoking the superclass’ constructor first. Now, there could be any number of classes in the constructor chain. The constructor chaining can be achieved in two ways namely -
1. Within the same class using this()
2. From base class using super()
Q.27 Describe JRMP in Java programming language
JRMP expands to Java Remote Method Protocol, is stream-based protocol of Java programming language running under RMI for remote object look-up and reference over TCP/IP. Both client and server in JRMP should use Java objects only.
Q.28 Define a Classloader in Java.
Java ClassLoader is defines a subset of JVM (Java Virtual Machine) that which responsible for loading the class files. Therefore whenever a Java program is executed it is first loaded by the classloader. Java provides three built-in classloaders,
1. Bootstrap ClassLoader
2. Extension ClassLoader
3. System/Application ClassLoader
Q.29 Differentiate amongst a Scrollbar and a ScrollPane in Java programming language
A ScrollPane is container managing events and executing scrolling whereas Scrollbar is only a component.
Q.30 Give reason why Java Strings are considered immutable in nature?
The Java string objects are considered immutable in nature which implicates that once the String object is created its state cannot be modified. Therefore whenever you try to update the value of that object instead of updating the values of that particular object, Java would create a new string object. Java String objects are immutable as String objects are generally cached in the String pool. Such that String literals are usually shared between multiple clients, action from one client might affect the rest. It enhances security, caching, synchronization, and performance of the application.
Q.31 How will you differ amongst time slicing and pre-emptive scheduling?
Time slicing involves execution of a task on basis of priority or other parameters for a specific time or time slice whereas in pre-emptive scheduling highest priority task performs till it finishes or goes to a wait state and next higher priority task executes.
Q.32 What do you understand by Map, in Java?
Map is an interface of Util package which maps unique keys to values. Such that the Map interface is not a subset of the main Collection interface and thus behaves little different from the other collection types. Some of the characteristics of Map interface are -
1. Map do not contain duplicate keys.
2. Each key can map at max one value.
Q.33 What do you mean by context switching in Java programming language?
The term context switching in Java programming language refers to storage of a process state as other process is takes over and after which, the stored state is the point of execution of that process. It enables CPU sharing amongst processes.
Q.34 What do you understand by abstraction in Java?
In Java, abstraction refers to the quality of dealing with ideas rather than events. Abstraction primarily deals with hiding the details and showing the essential things to the user. So we can say that abstraction in Java is the process of hiding the implementation details from the user and revealing only the functionality to them. Therefore abstraction can be achieved in two ways namely -
1. Abstract Classes (0-100% of abstraction can be achieved)
2. Interfaces (100% of abstraction can be achieved)
Q.35 The sleep () method in Java programming language, is used to
The sleep () method pauses thread execution for specified time
Q.36 How do you define inheritance in Java?
In Java, Inheritance can be defined as the concept where the properties of one class can be inherited by the other. Such that It inheritance, helps to reuse the code and establish a relationship between different classes. Inheritance can be performed between two types of classes -
1. Parent class (Super or Base class)
2. Child class (Subclass or Derived class) Any class that inherits the properties is referred as Child Class whereas a class whose properties are inherited is referred as Parent class.
Q.37 Does usage of the run () method is valid in Java programming language instead of the start () method?
Yes, usage of the run () method is valid in Java programming language instead of the start () method but it is applicable as object and not as thread.
Q.38 How can we override a private or static method in Java?
We cannot override a private or static method in Java. But in case we create a similar method with the same return then type and same method arguments in child class then it will hide the superclass method. This process is referred as hiding. Also we cannot override a private method in subclass since it is not accessible there. For this we can create another private method with the same name in the child class.
Q.39 Describe the daemon threads in Java programming language
The daemon threads in Java programming language are background running threads used primarily for support to the user threads. JVM terminates the daemon threads if only the daemon thread remains.
Q.40 How do you define multiple inheritance whether it Is supported by Java?
This is the case when a child class inherits the property from multiple classes then it is referred as multiple inheritance. We must note that Java does not allow to extend multiple classes. Such that the problem with multiple inheritance is that if multiple parent classes have the same method name, such that at runtime it becomes all the more difficult for the compiler to decide which method to execute from the child class. Hence Java does not support multiple inheritance. The is commonly referred to as Diamond Problem.
Q.41 Describe the condition in which a thread in Java programming language should be interrupted
A thread in Java programming language is interrupted to come out of the sleep or wait state by using the interrupt () method.
Q.42 What do you understand by encapsulation in Java?
Encapsulation can be defined as a mechanism where we can bind our data(variables) and code(methods) together as a single unit. Such that the data is hidden from the outer world and can be accessed only via current class methods. Encapsulation helps in protecting the data from any unnecessary modification. We can achieve encapsulation in Java in the following ways -
1. Declaring the variables of a class as private.
2. Providing public setter and getter methods to modify and view the values of the variables.
Q.43 How a thread is independent in multithreaded programming under Java programming language?
Every thread has its separate stack area in memory due to which it is independent.
Q.44 What is thread safe in Java programming language?
Thread-safe refers to a method or class object though being used by multiple threads at same time but without any race condition. It is involves using synchronization, Volatile keyword, a lock based mechanism or atomic wrapper classes.
Q.45 Describe the volatile keyword in Java programming language.
The volatile keyword in Java programming language is widely used in multithreaded programming for thread-safety as it enables change in volatile variable being visible to all other threads using the same volatile variable
Q.46 Differentiate amongst synchronous programming and asynchronous programming for a thread in Java programming language.
Asynchronous programming involves task execution by multiple threads but in synchronous programming a thread executes a task and thread is available after task completion. Asynchronous programming provides maximum thread utilization.
Q.47 What is fail-fast in Java programming language?
Fail-fast in Java programming language refers to ConcurrentmodificationException being thrown on occurrence of structural changes by the iterator.
Q.48 Differentiate amongst java.util.Date and java.sql.Date data type
The java.sql.Date data type does not have time information but only date information whereas the java.util.Date has both time and date information.
Q.49 Explain the use of setMaxRows method in JDBC
The setMaxRows method in JDBC limits maximum rows being returned against a query by database.
Q.50 Illustrate JDBC locking
A lock restricts data access to specific request / session only and is classified as per application: Row and Key (applied on row updating), Page Locks (applied on page while a transaction is under processing, database server locks the entire page with that row), Table locks (applied on the table - shared and exclusive) and database locks (applied on database while a transition is processed)
Q.51 Describe CLOB and BLOB data types in JDBC under Java programming language
Both CLOB and BLOB are variable-length object data types with up to 128 GB on Oracle and 2GB on MySQL. CLOB stores large characters object like files. BLOB stores large binary object like voice, media, etc
Get Govt. Certified Take Test