Java-interview-questions | Brothers Study Zone


Q) What is javac ?
The javac is a compiler that compiles the source code of your program and generates bytecode. In simple words javac produces the java byte code from the source code written *.java file. JVM executes the bytecode to run the program.
Q) What is class?
A class is a blueprint or template or prototype from which you can create the object of that class. A class has set of properties and methods that are common to its objects.
Q) What is the base class of all classes?
java.lang.Object is the base class (super class) of all classes in java.
Q) What is a wrapper class in Java?
A wrapper class converts the primitive data type such as int, byte, char, boolean etc. to the objects of their respective classes such as Integer, Byte, Character, Boolean etc.
Q) What is a path and class Path in Java?
Path specifies the location of .exe files. Class path specifies the location of byte code (.class files).
Q) Different Data types in Java.
·         byte – 8 bit
·         short – 16 bit
·         char – 16 bit Unicode
·         int – 32 bit (whole number)
·         float – 32 bit (real number)
·         long – 64 bit (Single precision)
·         double – 64 bit (double precision)
Q) What is Unicode?
Java uses Unicode to represent the characters. Unicode defines a fully international character set that can represent all of the characters found in human languages.
Q) What are Literals?
Any constant value that is assigned to a variable is called literal in Java. For example 
// Here 101 is a literal
int num = 101

Q) What is an Array?
An array is a collection (group) of fixed number of items. Array is a homogeneous data structure which means we can store multiple values of same type in an array but it can’t contain multiple values of different types. For example an array of int type can only hold integer values.
Q) What is BREAK statement in java?
The break statement is used to break the flow sequence in Java.
·         break statement is generally used with switch case data structure to come out of the statement once a case is executed.
·         It can be used to come out of the loop in Java

Q) What is method overriding in Java?

When a sub class (child class) overrides the method of super class (parent class) then it is called overriding. To override a method, the signature of method in child class must match with the method signature in parent class. 

Q) Can we override a static method?

No, we cannot override a static method in Java.

Q) What is method overloading?

When a class has more than one methods with the same name but different number, sequence or types of arguments then it is known as method overloading. 

Q) What is an abstract class in Java?

An abstract class is a class which can’t be instantiated (we cannot create the object of abstract class), we can only extend such classes. It provides the generalised form that will be shared by all of its sub classes, leaving it to each subclass to fill in the details. We can achieve partial abstraction using  abstract classes, to achieve full abstraction we use interfaces.

Q) What is Interface in java?

An interface is used for achieving full abstraction. A class implements an interface, thereby inheriting the abstract methods of the interface. 

Q) What is the difference between abstract class and interface?

1) abstract class can have abstract and non-abstract methods. An interface can only have abstract methods.
2) An abstract class can have static methods but an interface cannot have static methods.
3) abstract class can have constructors but an interface cannot have constructors.

Q) Name the access modifiers that can be applied to the inner classes?

public , private , abstract, final, protected.

Q) What is a constructor in Java?

Constructor is used for creating an instance of a class , they are invoked when an instance of class gets created. Constructor name and class name should be same and it doesn’t have a return type.

Q) Can we inherit the constructors?

No, we cannot inherit constructors.

Q) Can we mark constructors final?

No, Constructor cannot be declared final.

Q) What is default and parameterized constructors?

Default: Constructors with no arguments are known as default constructors, when you don’t declare any constructor in a class, compiler creates a default one automatically.
Parameterized: Constructor with arguments are known as parameterized constructors.

Q) Can a constructor call another constructor?

Yes. A constructor can call the another constructor of same class using this keyword. For e.g. this() calls the default constructor.
Note: this() must be the first statement in the calling constructor.

Q) THIS keyword?

The this keyword is a reference to the current object.
Q) Explain super keyword in Java super keyword references to the parent class. There are several uses of super keyword:
·         It can be used to call the super class(Parent class) constructor.
·         It can be used to access a method of the super class that has been hidden by subclass (Calling parent class version, In case of method overriding).
·         To call the constructor of parent class.
Q) Use of final keyword in Java?
Final methods – These methods cannot be overridden by any other method.
Final variable – Constants, the value of these variable can’t be changed, its fixed.
Final class – Such classes cannot be inherited by other classes. These type of classes will be used when application required security or someone don’t want that particular class.
Q) What is an Object class?
This is a special class defined by java; all other classes are subclasses of object class. Object class is superclass of all other classes. Object class has the following methods
·         objectClone () – to creates a new object that is same as the object being cloned.
·         boolean equals(Object obj) – determines whether one object is equal to another.
·         finalize() – Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.
·         toString () – Returns a string representation of the object.
Q) What are Packages in Java?
A Package can be defined as a grouping of related types (classes, interfaces, enumerations and annotations).  

Q) How can we create a thread in java?

There are following two ways of creating a thread:
1)  By Implementing Runnable interface.
2)  By Extending Thread class

Q) What is deadlock?

Deadlock describes a situation where two or more threads are blocked forever, waiting for each other.



Tausif

Hi! My name is TAUSIF AHMAD I have completed B.Tech in Computer Science from Maulana Azad National Urdu University Hyderabad. I am always ready to have new experiences meet new people and learn new things. 1. I am very interested in Frontend Development. 2. I love video editing and graphics designing. 3. I enjoy challenges that enables to grow. 4. I am part time Blogger.

Post a Comment (0)
Previous Post Next Post