1)What is a java bean? What is an enterprise bean?What is the difference?
*java beans are local components * Ejbs are distributed components
*java beans can be a UI Component as well as no UI * Ejbs are server side components
*java beans can be serialized and it has setters and getter. * Its not the case with ejb.
2)What is entity bean?How do you write an Entity Bean?
Entity bean is referred as data . There are 2 types of entity bean,
*Container managed Persistence : Container takes care of persisting the data into the database.
*Bean Managed Persistence : we need to write the code to persist the data into the database.
Bean represents a business entity. Entity bean should be persistent, i.e its state should be persisted in database even though the server shuts down.
Eg. CreditcardBean
CreditCardVerificationBean is a session bean because it doesnt contain only data but also methods to talk to the databse.
3)What is public static void main?
It has to be called from the jvm, so the main method should be public since it should be visible from outside, also class loader uses the object of classloader and loads the class with the main() method first , jvm never uses the object of the class to call the main() method, so it has to be static. and since it never returns any value it has to be void.
If you write any other main() method signature, it is just considered as a method, not used by the jvm.
you can have number of main() methods but not with the same signature.
4)What is the structure of java class?
A.java
Class A{
public static void main(String[] args){
----------
-------------
}
}
5)Why should private method cannot be static?
It can be static , compiler will not throw any error ,if it is private static method.
depending on the scenario we can use private static methods.
6)What is platform independence?
Java classes are converted into byte codes, when the java source code is compiled .class file is created which is a bytecode, this is picked up by the class loader and loads the class into jvm, Class loader is a namespace , Class loader is basically an object, using which the classes are loaded into jvm ,Classes are loaded into method area (a place for classes in memory). The import statements, i.e the classes that we refer in the class will also get loaded will be converted into memory addresses of that particular class in the memory (i.e import statements will refer to the actual memory addresses of the imported classes) and all these conversion of memory addresses is done by byte code verifier.
And this byte code can run on any hardware or any software which makes it platform independent.
JVM has a execution engine which is nothing but an interpreter(or hot spot compiler with a cache memory) which converts the byte code into machine language.
7)What are the features of java?
*Abstraction
*Polymorphism
*Inheritance
*Encapsulation
*Security
*Multithreading
*jdbc
8)What is polymorphism?
Polymorphism means more than one form.
There are 2 types of polymorphism :
a)Method overloading
b)Method overriding
Method Overloading : 2 methods in a same class or in the child class which has same name but different number of arguments is called method overloading.
2 methods with same arguments but different returntype is not considered as method overloading.
E.g public void setName(String name){
this.name = name;
}
public String detName(String name){
this.name=name;
return name;
}
is not method overloading.
Method overriding : Method overriding happens in Super class subclass relationship.you can have the same method signature in the subclass.depending on the object passed, the appropriate method is called. E.g.
package com.java.overriding;
class Employee{
public String name;
public String getName(){
this.name = "SuperClassName";
return name;
}
}
class Address extends Employee{
public String name;
public String getName(){
this.name="SubClassName";
return name;
}
}
public class test{
public static void main(String args[]){
Employee e2 = new Employee();
System.out.println(e2.getName());
Employee e1 = new Address ();
System.out.println(e1.getName());
}
}
9)What is the difference b/w abstract class and interface?
Abstract classes can have partial implementations , Interfaces are purely abstract, they can have only public abstract methods and final static constants.
Abstract classes can extend an abstract class. Interfaces can extend multiple interfaces.
Its recommended to use interfaces when the design changes frequently. you can declare the methods , and parameters it takes and fix the contract so that as per the design, different implementing classes can implement.Also you cannot extend multiple classes, A class can extend only one class,but it can implement many interfaces. In such scenarios, we can go for interfaces.
implementing an interface takes less cpu usage since it just contains method signatures and constants.
Abstract classes are expensive when compared to interfaces as it contains some code inside it.
Abstract classes lets you provide some default behavior.
10)What are the objects available in jsp / servlets?
There are 8 implicit objects available in jsp.
request >>HttpServletRequest object associated with request
response >> HttpServletResponse object associated with response
session>> HttpSession object associated with the request
application >>servletcontext associated with application context
out >>printwriter object
config>> ServletConfig object
exception >> exception object allows the exception data to be accessed by exception page
page >> page refers to this.
pagecontext>> using this all other objects are derieved.
11)What are the ways in which you can pass the control to another jsp or another servlet?
a) using <a href="" />
b)<form action="" > </form>
c)from servlet you can use
RequestDispatcher rd = getServletContext().getRequestDispatcher(URI);
rd.forward(req,res) >> To forward the control to another servlet
rd.include(req,res)>> To include a jsp inside your jsp.
or
res.sendRedirect(URL); >> If some page is moved to another jsp, then you can point to the new jsp using this send redirect and providing the URL.
*java beans are local components * Ejbs are distributed components
*java beans can be a UI Component as well as no UI * Ejbs are server side components
*java beans can be serialized and it has setters and getter. * Its not the case with ejb.
2)What is entity bean?How do you write an Entity Bean?
Entity bean is referred as data . There are 2 types of entity bean,
*Container managed Persistence : Container takes care of persisting the data into the database.
*Bean Managed Persistence : we need to write the code to persist the data into the database.
Bean represents a business entity. Entity bean should be persistent, i.e its state should be persisted in database even though the server shuts down.
Eg. CreditcardBean
CreditCardVerificationBean is a session bean because it doesnt contain only data but also methods to talk to the databse.
3)What is public static void main?
It has to be called from the jvm, so the main method should be public since it should be visible from outside, also class loader uses the object of classloader and loads the class with the main() method first , jvm never uses the object of the class to call the main() method, so it has to be static. and since it never returns any value it has to be void.
If you write any other main() method signature, it is just considered as a method, not used by the jvm.
you can have number of main() methods but not with the same signature.
4)What is the structure of java class?
A.java
Class A{
public static void main(String[] args){
----------
-------------
}
}
5)Why should private method cannot be static?
It can be static , compiler will not throw any error ,if it is private static method.
depending on the scenario we can use private static methods.
6)What is platform independence?
Java classes are converted into byte codes, when the java source code is compiled .class file is created which is a bytecode, this is picked up by the class loader and loads the class into jvm, Class loader is a namespace , Class loader is basically an object, using which the classes are loaded into jvm ,Classes are loaded into method area (a place for classes in memory). The import statements, i.e the classes that we refer in the class will also get loaded will be converted into memory addresses of that particular class in the memory (i.e import statements will refer to the actual memory addresses of the imported classes) and all these conversion of memory addresses is done by byte code verifier.
And this byte code can run on any hardware or any software which makes it platform independent.
JVM has a execution engine which is nothing but an interpreter(or hot spot compiler with a cache memory) which converts the byte code into machine language.
7)What are the features of java?
*Abstraction
*Polymorphism
*Inheritance
*Encapsulation
*Security
*Multithreading
*jdbc
8)What is polymorphism?
Polymorphism means more than one form.
There are 2 types of polymorphism :
a)Method overloading
b)Method overriding
Method Overloading : 2 methods in a same class or in the child class which has same name but different number of arguments is called method overloading.
2 methods with same arguments but different returntype is not considered as method overloading.
E.g public void setName(String name){
this.name = name;
}
public String detName(String name){
this.name=name;
return name;
}
is not method overloading.
Method overriding : Method overriding happens in Super class subclass relationship.you can have the same method signature in the subclass.depending on the object passed, the appropriate method is called. E.g.
package com.java.overriding;
class Employee{
public String name;
public String getName(){
this.name = "SuperClassName";
return name;
}
}
class Address extends Employee{
public String name;
public String getName(){
this.name="SubClassName";
return name;
}
}
public class test{
public static void main(String args[]){
Employee e2 = new Employee();
System.out.println(e2.getName());
Employee e1 = new Address ();
System.out.println(e1.getName());
}
}
9)What is the difference b/w abstract class and interface?
Abstract classes can have partial implementations , Interfaces are purely abstract, they can have only public abstract methods and final static constants.
Abstract classes can extend an abstract class. Interfaces can extend multiple interfaces.
Its recommended to use interfaces when the design changes frequently. you can declare the methods , and parameters it takes and fix the contract so that as per the design, different implementing classes can implement.Also you cannot extend multiple classes, A class can extend only one class,but it can implement many interfaces. In such scenarios, we can go for interfaces.
implementing an interface takes less cpu usage since it just contains method signatures and constants.
Abstract classes are expensive when compared to interfaces as it contains some code inside it.
Abstract classes lets you provide some default behavior.
10)What are the objects available in jsp / servlets?
There are 8 implicit objects available in jsp.
request >>HttpServletRequest object associated with request
response >> HttpServletResponse object associated with response
session>> HttpSession object associated with the request
application >>servletcontext associated with application context
out >>printwriter object
config>> ServletConfig object
exception >> exception object allows the exception data to be accessed by exception page
page >> page refers to this.
pagecontext>> using this all other objects are derieved.
11)What are the ways in which you can pass the control to another jsp or another servlet?
a) using <a href="" />
b)<form action="" > </form>
c)from servlet you can use
RequestDispatcher rd = getServletContext().getRequestDispatcher(URI);
rd.forward(req,res) >> To forward the control to another servlet
rd.include(req,res)>> To include a jsp inside your jsp.
or
res.sendRedirect(URL); >> If some page is moved to another jsp, then you can point to the new jsp using this send redirect and providing the URL.