
Java | Core Java Interview Questions and Answers for Experienced
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.
Java is very popular general-purpose programming language.
- Java is a pure object-oriented
- Everything in java is an Object
- All programs and data reside inside the objects and classes.
- Java facilitates it's users to create distributed applications in Java
- RMI and EJB are used for creating distributed applications
Java gives importance to memory management by using the technique called Garbage Collection and Exception handling etc.
Java is secure becasue of
- Byte-code concept
- It doesn't use explicit pointers
- Exception handling concepts
- Garbage collection mechanism
- Type-safe reference casting in JVM
Java compiler generates an platform independent code called bytecode.
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.
The use of bytecode makes the performance high.
Multithreading means handling more than one thread simultaneously. Java supports Multithreading.
You may also like Oracle DBA Interview Questions
- 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.
- JDK (Java Development Kit): JDK is used for developing Java Applications and Applets. It includes the Java Runtime Environment (JRE).
- JVM (Java Virtual Machine): JVM compiles Java Source-code into Byte-code.
- JRE (Java Runtime Environment): It is used to provide the runtime environment.
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 |
The instanceof keyword is used to check wheather an object belongs to a class or not.
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.
You may also like Node.js Interview Questions
A final variable's value can't be changed. final variables should be initialized before using them.
You can declared your class as final.
A method declared as final can't be overridden.
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.
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.
You may also like Java Programming Questions and Answers for Written Test
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.
Marker Interface is an empty interface (no field or methods).
Polymorphism.
It reduces the code readability and maintainability.
Externalizable is an Interface that extends Serializable Interface. And sends data into Streams in Compressed Format.
You may also like MongoDB Interview Questions
Upcasting means Generalization or Widening and Downcasting means specialization or narrowing.
The null value is not a keyword.
Numeric promotion means converting a smaller numeric type into a larger numeric type.
A public class can be access outside of its package. A non-public class can not be accessed outside of its package.
- Overridden methods must have the same name, argument list, and return type.
- The overriding method may not limit the access of the method it overrides.
- The overriding method may not throw any exceptions that may not be thrown by the overridden method.
A java package encapsulates a group of similar types of classes, interfaces and sub 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.
- Built-in package: javax, lang, awt, swing, io, util, sql etc
- User-defined package
java.lang package
java.lang.Object
- public
- abstract
- final
In Java, this keyword provides the reference to the current object.
Serialization is used to convert a java object into stream and using Deserialization you can convert stream data into Object.
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