core java coding interview questions and answers for freshers
Q. What do you know about Java Programming Language?
Java is a general-purpose, object-oriented programming language, designed by using James Gosling in 1991. The first model of Java used to be launched on May 23, 1995. Earlier, Java used to be named Oak.
Q. some important features of Java.
1. Java is type primarily based object-oriented, compiled
& Interpreted programming language.
2. Platform Independent & Portable.
3. Java makes use of the idea of Multithreading.
4. Java is dynamic – as it can more than one application and applications dynamically. Ex- Libraries.
5. Java is Robust & Secure.
Q. What are Identifiers in Java?
Identifiers are the identify given to a class, method, or variable.
Identifiers can begin with alphabets, $ sign, but can’t begin with numbers or any different sign, without underscore.
Q. Explain the procedure of compilation of a Java Code?
For compiling a source code, Java makes use of each compiler as properly as an interpreter. Java application takes place at two stages: Compiler & Interpreter. Compiler modifications a source code to byte code (.class file) and Interpreter modifications byte code to computing device code.
Q. What are access modifiers in Java?
In Java, Access modifiers, specifies the accessibility or scope of a field, the method, constructor, or a class
Q. Name some access modifiers in Java?
There are 4 access modifiers in Java Programming Language :
1. public
2. protected
3. default
4. private
Q. What is a Class?
Class is a specification or a template of an object. The class contains variables and methods.
Q. What is an Object?
The object is an occasion (dynamic memory allocation) of a class. The process of developing objects out of class is recognized as instantiation. The object has a state, behavior, and identification.
Q. Explain Encapsulation with an instance?
Encapsulation is a mechanism where the data and the code that acts on the data will bind together.
Example: Class is an instance of encapsulation. As the class is the collection of information members and member functions, consequently class binds them together.
Q. Explain Inheritance with example?
Inheritance refers to the process in which the child class inherits the properties of its father or mother class. A class that is inherited is known as a superclass. The class that does the inheriting is known as a subclass. Inheritance is done via the use of the keyword extends.
Q. What is JDK?
JDK is a Java Development kit. It is the collection of programming tools, JRE(java run time environment), JVM(java virtual machine).
Q. What is Procedural oriented programming?
It is the methodology the place programming has performed the usage of approaches & functions
Q. Is Java an object-oriented or object-based totally programming language?
Object-Based programming language does now not support all features of OOPs like Polymorphism and Inheritance. Java is an object-oriented programming language. Some of the object’s primarily based programming languages are JavaScript, Visual Basics.
Q. Explain Polymorphism with example?
Polymorphism represents the ability to assume several different forms of a program.
Example: Overloading of methods is an example of Polymorphism. Other examples include abstract classes and interfaces.
Q. What is Method Overloading?
Method Overloading means having two or more methods with the same name in the same class with different arguments. A method can be overloaded in the same class or in a subclass.
Q. What is Method Overriding?
Method overriding takes place when a sub-class declares a method that has the same kind of arguments as a method declared by one of its superclasses.
Q. Explain the role of implements keywords?
implements keyword is used to developed inheritance between interface and class
Q. Explain Constructor?
A constructor is defined as a special method that is used for initializing the objects of a class. The constructor has the same name as its class. The constructor does not have any return type.
Q. What is the role of the super key-word?
The super keyword is used to access the method or member variables from the superclass. If a method overrides one of the methods in its superclass, the method can invoke the overridden method via the use of the super keyword.
Q. What is a static block?
Static block is a block of code, which is executed exactly once i.e when the class is first loaded into JVM. Before the main method, the static block executes.
Syntax :
static
{
System. out.println(” This is a static block.”);
}
Q.List Even Numbers Java Example
This List Even Numbers Java Example shows how to find and list even numbers between 1 and any given number.
public class ListEvenNumbers {
public static void main(String[] args) {
//define limit
int limit = 50;
System.out.println(“Printing Even numbers between 1 and ” +
limit);
for(int i=1; i <= limit; i++){
// if the number is divisible by 2 then it is even
if( i % 2 == 0){
System.out.print(i + ” “);
} }
}}
/*
The output of the List Even Numbers Java Example would be
Printing Even numbers between 1 and 50
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50
*/
Q. What is an exception?
An exception is an event, which occurs during the execution of a
the program, that disrupts the normal flow of the program’s instructions.
Q. What is an error?
An Error indicates that a non-recoverable condition has occurred that should not be caught.