Java Interview
Java Interview
Static: with the help of static method can be accessed without creating the instance of the class
String args[] : Array of string type this contains the command line arguments that we can pass by
running the program.
An object is instance of the class. Object has state and behaviour.it is a logical entity. eg. dog
A Class is template or blueprint form which objects are created. Eg. Animal
Used for memory management (memory is allocation is done only one time at the time loading of
class)
Can be used with class, variable (also known as class variable), methods and block
(single copy of the static variable is created and shared among all the classes.)
Used to refer common properties of all object which is not unique of each object
Default :
Parameterised:
This() can be used to return current class instance from the method.
Local variable:
Instance variable:
7. What is inheritance?
Inheritance is a process by which one class acquires the data-members and properties of the other
class. Mainly used for the reusability of the code.
8. What is encapsulation?
Such data can be accessed to other class by setting getter and setter method as public
9. What is polymorphism?
The most common oops concept used in java is having more than one method with same name in
single class.
Types:
Used to set the visibility of classes, data member, constructor and methods in other class
Can have methods and variables just like a class but methods declared in interface are by default
abstract (only method signature)
The variables declared in the interface are public, static and final.
Can be used to achieved loose coupling
14.
Can have protected and public abstract method Can have only public abstract method
Can have static, final or static final variable with Can have only public static final variable
any access specifier
Final variable are nothing but constants, once initialise value remain cannot be changed
Final class if a class is declared as final than that class couldn’t be sub-classed. No class can extend
the final class.
Every java programme has atleast one thread called the main thread
String is a sequence of characters, it is an immutable object and cannot be changed once it is created
Using new keyword: String str =new String(“testing world welcome you”);
String builder and StringBuffer classes are used for string manipulation.
These are mutable objects which provide methods such as substring, insert, append, delete for
String manipulation.
Array Array-List
Is a fixed length data structure Belongs to variable length Collection class
Can contains both primitive datatype and objects Only supports object entries
Performance is faster Performance is slower
Store specific type of items Store any type of items
Do not support. Supports additional operations like indexOf,
Remove()
Syntax: Syntax:
Collection framework is the combination of classes and interfaces which is used to store and
manipulate the data in the form of object.
List Set
List is an ordered collection it maintains the Set is an unordered collection
insertion order
Allows duplicates Do not allow duplicates
List Implementation: arraylist, linkedlist Set implementation are
hashset,linkedhashset,treeset…
List allow any number of null value Can have only one null value
List-iterator used to traverse a list in both Iterator to traverse a set
direction
List interface has one legacy class called vector Set do not have any legacy class
Set contains value whereas Map contains key and value both.
Set contains unique value whereas Map contains unique key with duplicate values
Set hold single number of null values whereas Map can includes a single null key with n numbers of
null values.
23.
HashMap HashTable
Synchronised : no Synchronised : yes
Allow null: one null key with n number of null Not alllowed
values
Maintain insertion order No order maintained
Inherits: AbstractMap class Dictionary class
Checked exception:
Unchecked Exception:
Not Checked during compile time, the compiler doesn’t force to handle these exception