1)What are the Java 8 Features in java?
*For Each() method in Iterable Interface.
*Default and Static methods in interface.
*Functional Interface and Lambada Expression.
*Collection API Improvements.
NOTE: We can use default and static keyword to create Interface with Implementation.
2)Define a Concrete Class?
*used for Specific Requirement.
*Object of Concrete Class can be created directly
*Containing fully defined methods or implementation methods.
3)Steps for remove duplicates elements in java?
public class RemoveDuplicates
{
ArrayList<object> a1= new ArrayList<object>();
al.add("JAVA"); //you can add any number of the data you want
System.out.println("the elements are:" +a1);
for(int i=0; i<a1.size(); i++)
{
if(a1.get(i).equals(a1.get(j)))
{
a1.remove(j);
j--;
}
}
}
System.out.println("After Removing the duplicates elements:" +a1 );
}
}
4) Define halt() function?
public void halt(int staus):
Forcibly terminates the currrently running JVM.
This method never returns normally.
5) exit() function;
public void exit(int status):
This method terminates the currently running Java Virtual Machine.
java.lang.sysyem.exit();
6)Do all properties of an Immutable Object need to be final?
Not necessary no need make all the object as a final, you can achieve the same functionality by making the member non-final but non-private and not modifying them except in the constructor.
7)How does the substring() method inside String works?
A string is supported by a char array in the back-end. They are used to store real character array, the first index of the array, the number of characters in the String. When the substring() method is called, it creates a new string, but the string's value still points to the same array in the heap. A String is used for the characters and cann't be changed once declared and it is used for a security puropose.
8) what is method overloading in java?
*A class has a multiple methods with a same name but with different parameters.
Advantage:
*It will increases the readability of the program.
Two ways to overload the method:
- By changing number of arguments
- By changing the data type
9)Why method overloading is not possible to change the return type of the method? It is not possible to change the return type because it cause a ambitguity problem.
10)what is method overridding?
* If the name of the method in the subclass(child class) and super class(parent class) are same name then it is called as a overridding.
* It is a runtime polymorphism.
11)Define covariant return type?
The covariant return type specifies that the return type may vary in the same direction as the subclass.
12)What is a final keyword?
*Final keyword is used to restrict the user.
*Final keyword can used in
*class
*variable
*method
13)What is Encapsulation?
It is process of wrapping code and data together into a single unit.
It provides control over the data.
14)Define Exception handling in java?
*Exception handling in java is one of the powerful mechanism to handle the runtime errors so that normal flow of the application can be maintained.
*Exception is an abnormal condition.
*Exception Handling is a mechanism to handle runtime errors such as ClassNotFound etc.
Types of Exception:
- Checked Exception
- Unchecked Exception
- Error
15)Define Checked Exception?
* Classes that extend Throwable class except RuntimeException and Error are known as checked exceptions
e.g.IOException, SQLException etc.
*Checked exceptions are checked at compile-time.
16)Define Unchecked Exception?
Classes that extend RuntimeException are known as unchecked exceptions e.g. ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException etc.
*Unchecked exceptions are not checked at compile-time rather they are checked at runtime.
17)Define Error?
It is irrecoverable. This mistake was done by user and can't be solved.
eg: outofmemoryerror.
18)How can we handled a Exception?
We can handle Exception by using a try and catch block.
19)What is a Finallay block?
*It is used to executed the important code such as closing a connection.
*finally block always executed whether exception is handled or not.
20)What is Finalize?
It is used to perform clean up processing just before object garbage is collected.
It is used to remove the unwanted memory space.
21)what is collection in java?
*A collection is represent a collection of a objects into the single unit.
*A collection is a unified architecture for storing and manipulating a objects.
*It is set of a classes and interface.
22) what are the types of the collections?
*List :
Arraylist
Linked List
Vector
*Set
Hashset
LinkedHashSet
SortedSet
*Queue
Deque
ArrayDeque
23)Define Enum?
*Enum is define as a set of date and time.
24)Define Constructor?
Constructor is same as a class name and used to initialize the object ant the time of the object creation.
25)Define Abstraction?
Abstraction is used to hide the unwanted details and showing only functionality to the user.
Abstract(0 to 100%)
interface(100%)
26) Define Interface?
All unwanted implementation are called as a interface.
Interface can be declared as by using a name interface.
ex:
interface Date
{
void run();
void display();
}
Comments
Post a Comment