You are on page 1of 8

Q. why java is not full object oriented? A.

Java supports primitive data types such as byte, short, int, long, float, double, char & boolean. For Object oriented language everything must be declared in objectS. That's why java is not fully object oriented language Q. Why Java is case sensitive? A. Java is a platform independent. It can be used in any machines irrespective of platform. So it is a case sensitive. Java converts the java file into byte codes that is the reason it is case sensitive because different literals have different Unicodes and thus byte codes. Q. How many different types of JDBC drivers are present? Discuss them. A. there are 4 types of JDBC driver 1.JDBC-ODBC bridge 2.Native API Driver Specification 3.Network Protocol Driver 4.Native ProtocolDriver Q. Explain Servlet and JSP life cycle? A. Life cycle of the SERVLETS:1)the class is loaded. 2)the constructor is called(create object of that class), 3)container then calls the init() method that creates the servletconfig and servletcontext objects used for accessing the init parameter within the web app. 4)container calls the service() method by creating the thread for each new request. 5)after the service() method the container calls the destroy() method. Life cycle of the JSP:1)create a file with .jsp extension....that file is then translated into.java file. 2)that file is then compiled thereby creating the .class file 3)that class is loaded. 4)then jspinit() method is called. 5)then container calls the jspservice() method 6)finally jspdestroy() method is called. Servlet Lifecycle first the url is collected from the user generates an http request, this request is mapped with the appropriate servlet and loaded in the address space of the server. once the servlet is loaded the following 3 phases starts 1. init(): 2.service() 3 destroys() Jsp Life cycle JSP engine does the following 7 phases. Page translation: -page is parsed, and a java file which is a servlet is created. Page compilation: page is compiled into a class file Page loading : This class file is loaded. Create an instance :- Instance of servlet is created jspInit() method is called

_jspService is called to handle service calls _jspDestroy is called to destroy it when the servlet is not required. Q. How will you pass values from HTML page to the Servlet? A. We can pass values to servlet from HTMLpage using "request.getParameter(string);" method.Which is a method in the HttpServletRequest interface.

from above answer we can retrieve value send from html in servlet. But their are two method for sending value to servlet: 1.by using hidden form element like <input type="hidden" name="name" value="value"> 2.or by simple NameOfServlet?name1=value&name2=value2 Q. Why we can not override static method? A. Static methods are not appeared in sub classes. we can't inherited static methods. So Over riding is not possible with out inheritance. Q. What is the disadvantage of threads? A. threads are OS dependent so they are executed in different timings in different systems Threads are really operating system dependent and it should follow the existing cpu life cycle that varies from system to system. Q. Difference: Java Beans, Servlets A. java bean is a reusable component,where as the servlet is the java program which extends the server capability the java beans has the setter/getter methods that are used in the servlets to be initialized Q. What is the difference between concat and append? A. concat method is for String class and it creates new String object having value as one string added at the end of another one, while append method is for StringBuffer. it updates the same StringBuffer object and its value becomes: second string appended at the end of first string. Q. What is the difference between attribute and parameter ? A. attribute - is a member of a class parameter - is a member of a method signature argument - is used to send values to the method from the caller. parameter - is a place holder for the incoming values for a method from the caller. Q. What is the difference between Hashmap and Hashtable ?

A. Another big difference is that HashMap allows null key and null values whereas HashTable does not permit null key and null values. ?HashMap is not Synchronized where as hashTable is. 3?HashMap allows null as both key and value, where as HashTable does?nt allow null. 4?HashMap retrieval is not in order (random). HashTable provide ordered retrieval. Q.Why pointers are not used in java? A. Pointers are not used in java, why because java is a platform independent language and also it is a one type of internet based language. Q. Plz give me detail difference between Tomcat & Weblogic server A. Tomcat is a web-server,this is 3-tier Architecture. where as Weblogic is an Application Server,this is n-tier Architecture.In Tomcat we cannot deploy an EJB.but in Weblogic we can. Q. What is super class of an Exception class? A. The super class for Exception class is Throwable Q. what is servelet? A. Servlet is java web application component.or a java program which implements the Servlet interface.The duty of servlet is as follows: 1. Retriving the client request. 2. Processing the client request. 3. Generate the response w.r.t client request. 4. Sending the appropriate response to the client. And servlet act as a Controller in the MVC architecture. Q. What is java virtual machine and what are its uses? A. JVM is part of the java runtime system that is responsible for interpreting the byte code and converting into equivalent machine code that can be executed on any machine. Q. Diff between ArrayList and Vector? A. 1.Arraylist is not synchronized while vector is. 2.Arraylist has no default size while vector has a default size of 10 3.Use Vector only if it will be accessed by multiple threads at a time else ArrayList is always better. Q. Can the abstract class be final? A. No, abstract class can't be final because we declare it abstract to override the member functions. Q. What is the meaning of "final" keyword? A. Final keyword is used for define constant variables and method and no body can change that variable and method within program. Final class cannot be extended. Final method cannot be overriden and value of final variable cannot be changed Q. What is the abstraction? Give example?

A. Abstraction means to hide the unnecessary data so we use for that abstract class or abstract methods. EX:abstract class car { abstract void fun() {} }

Abstraction means hiding the details and providing the features. eg. a car driver is only concerned with driving a car, not the internal working of engine. Q: What are runtime exceptions? A: Runtime exceptions are those exceptions that are thrown at runtime because of either wrong input data or because of wrong business logic etc. These are not checked by the compiler at compile time. Q: What is the difference between error and an exception? A: An error is an irrecoverable condition occurring at runtime. Such as OutOfMemory error. These JVM errors and you can not repair them at runtime. While exceptions are conditions that occur because of bad input etc. e.g. FileNotFoundException will be thrown if the specified file does not exist. Or a NullPointerException will take place if you try using a null reference. In most of the cases it is possible to recover from an exception (probably by giving user a feedback for entering proper values etc.). Q: What are the different ways to handle exceptions? A: There are two ways to handle exceptions, 1. By wrapping the desired code in a try block followed by a catch block to catch the exceptions. and 2. List the desired exceptions in the throws clause of the method and let the caller of the method hadle those exceptions Q: What is the difference between an Interface and an Abstract class? A: An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.), but has some abstract methods. . TOP Q: What is the purpose of garbage collection in Java, and when is it used? A: The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused. A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used. Q: What are pass by reference and passby value?

A: Pass By Reference means the passing the address itself rather than passing the value. Passby Value means passing a copy of the value to be passed.

Q: Difference between Swing and Awt?

A: AWT are heavy-weight componenets. Swings are light-weight components. Hence swing works faster than AWT.

Q: What is static in java? A: Static means one per class, not one for each object no matter how many instance of a class might exist. This means that you can use them without creating an instance of a class.Static methods are implicitly final, because overriding is done based on the type of the object, and static methods are attached to a class, not an object. A static method in a superclass can be shadowed by another static method in a subclass, as long as the original method was not declared final. However, you can't override a static method with a nonstatic method. In other words, you can't change a static method into an instance method in a subclass. TOP Q: What is final? A: A final class can't be extended ie., final class may not be subclassed. A final method can't be overridden when its class is inherited. You can't change value of a final variable (is a constant). Q: What if the main method is declared as private? A: The program compiles properly but at runtime it will give "Main method not public." message. Q: What is Overriding? A: When a class defines a method using the same name, return type, and arguments as a method in its superclass, the method in the class overrides the method in the superclass. When the method is invoked for an object of the class, it is the new definition of the method that is called, and not the method definition from superclass. Methods may be overridden to be more public, not more private. Q: What is serialization? A: Serialization is a mechanism by which you can save the state of an object by converting it to a byte stream. Q: What is the common usage of serialization? A: Whenever an object is to be sent over the network, objects need to be serialized. Moreover if the state of an object is to be saved, objects need to be serilazed. Q: How does Java handle integer overflows and underflows?

A: It uses those low order bytes of the result that can fit into the size of the type allowed by the operation. Q: What are the steps in the JDBC connection? A: While making a JDBC connection we go through the following steps :

Step 1 : Register the database driver by using : Class.forName(\" driver classs for that specific database\" ); Step 2 : Now create a database connection using : Connection con = DriverManager.getConnection(url,username,password); Step 3: Now Create a query using : Statement stmt = Connection.Statement(\"select * from TABLE NAME\"); Step 4 : Exceute the query : stmt.exceuteUpdate();

1. What is OOPs? - Object oriented programming organizes a program around its data, i.
e. , objects and a set of well defined interfaces to that data. An object-oriented program can be characterized as data controlling access to code. What is the use of bin and lib in JDK? - Bin contains all tools such as javac, appletviewer, awt tool, etc., whereas lib contains API and all packages. What are different types of access modifiers?- public: Any thing declared as public can be accessed from anywhere. private: Any thing declared as private cant be seen outside of its class. protected: Any thing declared as protected can be accessed by classes in the same package and subclasses in the other packages. default modifier : Can be accessed only to classes in the same package

What is final, finalize() and finally? - final : final keyword can be used for class, method and variables. A final class cannot be subclassed and it prevents other programmers from subclassing a secure class to invoke insecure methods. A final method cant be overridden. A final variable cant change from its initialized value. finalize() : finalize() method is used just before an object is destroyed and can be called just prior to garbage collection. finally : finally, a key word used in exception handling, creates a block of code that will be executed after a try/catch block has completed and before the code following the try/catch block. The finally block will execute whether or not an exception is thrown. For example, if a method opens a file upon exit, then you will not want the code that closes the file to be bypassed by the exceptionhandling mechanism. This finally keyword is designed to address this contingency

1. What is Garbage Collection and how to call it explicitly? - When an object is no


longer referred to by any variable, java automatically reclaims memory used by that object. This is known as garbage collection. System. gc() method may be used to call it explicitly.

What is finalize() method? - finalize () method is used just before an object is destroyed and can be called just prior to garbage collection.

1. What is method overloading and method overriding? - Method overloading:


When a method in a class having the same method name with different arguments is said to be method overloading. Method overriding : When a method in a class having the same method name with same arguments is said to be method overriding. What is a package? - A package is a collection of classes and interfaces that provides a high-level layer of access protection and name space management. What is deadlock?- When two threads are waiting each other and cant precede the program is said to be deadlock.

2. 3.

What is JDBC? - JDBC is a set of Java API for executing SQL statements. This API consists of a set of classes and interfaces to enable programs to write pure Java Database applications What is stored procedure? - Stored procedure is a group of SQL statements that forms a logical unit and performs a particular task. Stored Procedures are used to encapsulate a set of operations or queries to execute on database. Stored procedures can be compiled and executed with different parameters and results and may have any combination of input/output parameters.

1. What is connection pooling?- With servlets, opening a database connection is a


major bottleneck because we are creating and tearing down a new connection for every page request and the time taken to create connection will be more. Creating a connection pool is an ideal approach for a complicated servlet. With a connection pool, we can duplicate only the resources we need to duplicate rather than the entire servlet. A connection pool can also intelligently manage the size of the pool and make sure each connection remains valid. A number of connection pool packages are currently available. Some like DbConnectionBroker are freely available from Java Exchange Works by creating an object that dispenses connections and connection Ids on request. The ConnectionPool class maintains a Hastable, using Connection objects as keys and Boolean values as stored values. The Boolean value indicates whether a connection is in use or not. A program calls getConnection() method of the ConnectionPool for getting Connection object it can use; it calls returnConnection() to give the connection back to the pool. What is JSP? - JSP is a dynamic scripting capability for web pages that allows Java as well as a few special tags to be embedded into a web file (HTML/XML, etc). The suffix traditionally ends with .jsp to indicate to the web server that the file is a JSP files. JSP is a server side technology - you cant do any client side validation with it. The advantages are: a) The JSP assists in making the HTML more functional. Servlets on the other hand allow outputting of HTML but it is a tedious process. b) It is easy to make a change and then let the JSP capability of the web server you are using deal with compiling it into a servlet and running it. How can I set a cookie in JSP?- response. setHeader(Set-Cookie, cookie string); To give the response-object to a bean, write a method setResponse (HttpServletResponse response) - to the bean, and in jsp-file:<% bean. setResponse (response); %>

Question: Describe the principles of OOPS. Answer: There are three main principals of oops which are called Polymorphism, Inheritance and Encapsulation. Question: Explain the Encapsulation principle. Answer: Encapsulation is a process of binding or wrapping the data and the codes that operates on the data into a single entity. This keeps the data safe from outside interface and misuse. One way to think about encapsulation is as a protective wrapper that prevents code and data from being arbitrarily accessed by other code defined outside the wrapper. Question: Explain the Inheritance principle. Answer: Inheritance is the process by which one object acquires the properties of another object. Question: Explain the Polymorphism principle. Answer: The meaning of Polymorphism is something like one name many forms. Polymorphism enables one entity to be used as as general category for different types of actions. The specific action is determined by the exact nature of the situation. The concept of polymorphism can be explained as "one interface, multiple methods". Question: Explain the different forms of Polymorphism. Answer: From a practical programming viewpoint, polymorphism exists in three distinct forms in Java: Method overloading Method overriding through inheritance Method overriding through the Java interface

Question: What are Access Specifiers available in Java? Answer: Access specifies are keywords that determine the type of access to the member of a class. These are: Public Protected Private Defaults

You might also like