Core Java Interview Questions and Answers for Experienced
Core Java Interview Questions and Answers for Experienced

Java | Core Java Interview Questions and Answers for Experienced

Q:- What is Java?
Java is a general-purpose, high-level, object-oriented, platform independent programming language.

Java was originally developed by James Gosling at Sun Microsystems (which has since been acquired by Oracle Corporation) and released in 1995.

Q:- What is the most important features of Java?
1. Simple

Java is very popular general-purpose programming language.

2. Object-Oriented
  1. Java is a pure object-oriented
  2. Everything in java is an Object
  3. All programs and data reside inside the objects and classes.
3. Distributed
  1. Java facilitates it's users to create distributed applications in Java
  2. RMI and EJB are used for creating distributed applications
4. Robust

Java gives importance to memory management by using the technique called Garbage Collection and Exception handling etc.

5. Secure

Java is secure becasue of

  1. Byte-code concept
  2. It doesn't use explicit pointers
  3. Exception handling concepts
  4. Garbage collection mechanism
  5. Type-safe reference casting in JVM
6. Platform Independent

Java compiler generates an platform independent code called bytecode.

7. Portable
Java works on concept - Write Once Run Everywhere

Java Bytecode can be run on any machine. It is the Bytecode which makes it platform independent.

8. Compiled and Interpreted
Generally, computer languages are either compiled or interpreted. but java combines both compilers and interpreters.
9. Performance

The use of bytecode makes the performance high.

10. Multi-Threading

Multithreading means handling more than one thread simultaneously. Java supports Multithreading.

You may also like Oracle DBA Interview Questions
Q:- How to write very first simple program in Java?
/* This is a very first simple Java program. FileName : "FirstProgram.java". */ public class FirstProgram { public static void main(String args[]) { System.out.println("Core Java Interview Questions and Answers for Experienced"); } } //Output: Core Java Interview Questions and Answers for Experienced
Q:- What is Java Virtual Machine (JAM)?
  • Java Virtual Machine is a machine that enables the computer to run the Java program.
  • JVM acts like a run-time engine which calls the main method present in the Java code.
  • JVM compiles source-code into byte-code which is machine independent.
Q:- What is the difference between JDK, JVM and JRE?
  1. JDK (Java Development Kit): JDK is used for developing Java Applications and Applets. It includes the Java Runtime Environment (JRE).
  2. JVM (Java Virtual Machine): JVM compiles Java Source-code into Byte-code.
  3. JRE (Java Runtime Environment): It is used to provide the runtime environment.
Q:- What are the primitive data types in Java?

Primitive data types are:

Data Type Size
byte 1 byte
boolean 1 bit
char 2 bytes
short 2 bytes
int 4 bytes
long 8 bytes
float 4 bytes
double 8 bytes
Q:- What is the use of instanceof keyword in Java?

The instanceof keyword is used to check wheather an object belongs to a class or not.

Q:- How to define a constant variable in Java?
A constant is a variable whose value cannot be changed once value assigned.

Java doesn't have built-in support for constants. but you can achieve this by declaring variable as static final.

static final int MAX_LENGTH = 50;
You may also like Node.js Interview Questions
Q:- What is the purpose of declaring a variable as final?

A final variable's value can't be changed. final variables should be initialized before using them.

Q:- I don't want my class to be inherited by any other class. What should i do?

You can declared your class as final.

Q:- What is the impact of declaring a method as final?

A method declared as final can't be overridden.

Q:- Difference between final, finally and finalize()?

final is a modifier it can be applied to a class or a method or a variable.

  • final class can't be inherited
  • final method can't be overridden
  • final variable can't be changed

finally is an exception handling code section which gets executed whether an exception is raised or not by the try block.

finalize() is a method of Object class which will be executed by the JVM just before garbage collecting object to give a final chance for resource releasing activity.

Q:- Print a message even before main() is executed. How will you achieve that in Java?

You can print the message inside static block. It will execute when the class gets loaded into the memory and even before the creation of an object.

Hence it will be executed before the main() method. And it will be executed only once.

public class PrintMessage { static { System.out.println("Core Java Interview Questions"); System.exit(0); } } //Note - //1. The System.exit(0) exits the program before the JVM starts to look for main() //2. This will not work with JDK7 - Because, In JDK7 the code would not execute as it looks for the main method before any other thing. //Output: Core Java Interview Questions
You may also like Java Programming Questions and Answers for Written Test
Q:- Does Java support multiple inheritance?
When one class extends more than one classes then this is called multiple inheritance.

C++ supports multiple inheritance but java doesn't support multiple inheritance.

Q:- What is a Marker Interface?

Marker Interface is an empty interface (no field or methods).

Q:- Which object oriented Concept is achieved by using overloading and overriding?

Polymorphism.

Q:- Why does Java not support operator overloading?

It reduces the code readability and maintainability.

Q:- What is Externalizable?

Externalizable is an Interface that extends Serializable Interface. And sends data into Streams in Compressed Format.

It has two methods
// to read object from stream void readExternal(ObjectInput in) // to write object into stream void writeExternal(ObjectOutput out)
Q:- What is a local, member and a class variable?
Local Variable:
Variables declared within a method are "local" variables.
Member Variable:
Variables declared within the class i.e not within any methods are "member" variables (global variables).
Class Variable:
Variables declared within the class i.e not within any methods and are defined as "static" are class variables.
Q:-What is the difference between a static and a non-static inner class?
A non-static inner class may have object instances that are associated with instances of the class's outer class. A static inner class does not have any object instances.
You may also like MongoDB Interview Questions
Q:- What is Upcasting and Downcasting?

Upcasting means Generalization or Widening and Downcasting means specialization or narrowing.

Q:- How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?
Unicode:
Unicode requires 16 bits and ASCII require 7 bits Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits.
UTF-8:
UTF-8 represents characters using 8, 16, and 18-bit patterns.
UTF-16:
UTF-16 uses 16-bit and larger bit patterns.
Q:- Is null a keyword?

The null value is not a keyword.

Q:- What is the numeric promotion?

Numeric promotion means converting a smaller numeric type into a larger numeric type.

Q:- What is the difference between a public and a non-public class?

A public class can be access outside of its package. A non-public class can not be accessed outside of its package.

Q:- What restrictions are placed on method overriding?
  1. Overridden methods must have the same name, argument list, and return type.
  2. The overriding method may not limit the access of the method it overrides.
  3. The overriding method may not throw any exceptions that may not be thrown by the overridden method.
Q:- What is a Java package and how is it used?

A java package encapsulates a group of similar types of classes, interfaces and sub packages.

Use of Packages:
  • A Package is used to create a separate namespace for groups of classes and interfaces.
  • A Package are also used to manage and control related classes and interfaces into a single API unit.
Type of Package:
  1. Built-in package: javax, lang, awt, swing, io, util, sql etc
  2. User-defined package
Q:-Which package is imported by default?

java.lang package

Q:-What is the base class of all classes?

java.lang.Object

Q:-What modifiers may be used with top-level class in Java?
A top-level class may be:
  1. public
  2. abstract
  3. final
Q:- What is this keyword?

In Java, this keyword provides the reference to the current object.

Q:- What is the difference between Serialization and Deserialization?

Serialization is used to convert a java object into stream and using Deserialization you can convert stream data into Object.

Q:- What is Garbage Collection?
In computer programming, garbage collection is a form of automatic memory management.

Garbage Collection is the process of checking heap memory and destroying unused objects. In Java, this process of deallocating memory is automatically handled by the garbage collector.

You may also like RESTful Web Services Interview Questions