Ads 468x60px

Pages

Thursday, 28 June 2012

servlets interview questions


17) What is a Scriptlet?
A scriptlet can contain any number of language statements, variable or expressions that are valid in the page scripting language. Within scriptlet tags, you can declare variables to use later in the file, write expressions valid in the page scripting language, use any of the JSP implicit objects or any object declared with a <jsp:useBean>.  Generally a scriptlet can contain any java code that are valid inside a normal java method. This will become the part of generated servlet's service method.








18) What's the difference between forward and sendRedirect?
forward is server side redirect and sendRedirect is client side redirect. When you invoke a forward request, the request is sent to another resource on the server, without the client being informed that a different resource is going to process the request. This process occurs completely with in the web container And then returns to the calling method. When a sendRedirect method is invoked, it causes the web container to return to the browser indicating that a new URL should be requested. Because the browser issues a completely new request any object that are stored as request attributes before the redirect occurs will be lost. This extra round trip a redirect is slower than forward. Client can disable sendRedirect

19) Is JSP extensible ?
Yes, it is. JSP technology is extensible through the development of custom actions, or tags, which are encapsulated in tag libraries.

20) What is the life cycle of servlet?
Each servlet has the same life cycle: first, the server loads and initializes the servlet by calling the init method. This init() method will be executed only once during the life time of a servlet. Then when a client makes a request, it executes the service method. finally it executes the destroy() method when server removes the servlet.

21) Can we call destroy() method on servlets from service method ?
Yes

22) What is the need of super.init (config) in servlets ?
Then only we will be able to access the ServletConfig from our servlet. If there is no ServletConfig our servlet will not have any servlet nature

23) What is the difference between GenericServlet and HttpServlet?
GenericServlet supports any protocol. HttpServlet supports only HTTP protocol. By extending GenericServlet we can write a servlet that supports our own custom protocol or any other protocol.

24) Can we write a constructor for servlet ?
Yes. But the container will always call the default constructor only. If default constructor is not present , the container will throw an exception.

25) What is the difference between <%@ include ...> (directive include) and <jsp:include> ?
@ include is static include. It is inline inclusion. The contents of the file will get included on Translation phase. It is something like inline inclusion. We cannot have a dynamic filename for directive include. <jsp:include> is dynamic include. Here the included file will be processed as a separate file and the response will be included. We can have a dynamic filename for <jsp:include>. We can aslo pass parameters to <jsp:include

26) Can I just abort processing a JSP?
Yes. You can put a return statement to abort JSP processing

27) How do I prevent the output of my JSP or Servlet pages from being cached by the browser?
By setting appropriate HTTP header attributes we can prevent caching by the browser

<%
response.setHeader("Cache-Control","no-store"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
%>

28) How to refer the "this" variable within a JSP page?
Under JSP 1.0, the page implicit object page is equivalent to "this", and returns a reference to the servlet generated by the JSP page.

29) How many JSP scripting elements and what are they?
There are three scripting elements in JSP . They are declarations, scriptlets, expressions.

30) Can we implement an interface in JSP ?
No

31) What is the difference between ServletContext and PageContext?
ServletContext gives the information about the container and PageContext gives the information about the Request

32) How do you pass data (including JavaBeans) to a JSP from a servlet?
By forwarding the request to the servlet ( the data must be there in the request scope) we can pass the data from a JSP to servlet. Also we can use a session to pass the data.

33) How to pass information from JSP to included JSP?
By using <jsp:param> tag
Servlet Life Cycle Methods
The following are the life cycle methods of a servlet instance:
  • init()
  • service()
  • destroy()
We will look into the each method in detail.


init()

This method is called once for a servlet instance. When first time servlet is called, servlet container creates instance of that servlet and loaded into the memory. Future requests will be served by the same instance without creating the new instance. Servlet by default multithreaded application.init() method is used for inilializing servlet variables which are required to be passed from the deployment descriptor web.xml. ServletConfig is passed as the parameter to init() method which stores all the values configured in the web.xml. It is more convenient way to initialize the servlet.


service()

This method is called for the each request. This is the entry point for the every servlet request and here we have to write our businesslogic or any other processes. This method takes HttpServletRequest and HttpServletresponse as the parameters. It is not mandatory to write this method, normally developers are interested in writing doGet() or doPost() methods which is by default called from the service() method. If you override service(), it is your reponsibility to call the appropriate methods. If you are not overridden the service() method, based on the types of the request the methods will be called.


destroy()

This method will be called once for a instance. It is used for releasing any resources used by the servlet instance. Most of the times it could be database connections, Fill IO operations, etc. destroy() is called by the container when it is removing the instance from the servlet container. Servlet instance is deleted or garbage collected by the container only when the web server issues shut down or the instance is not used for a long time.

Typical uses for HTTP Servlets include:
  • Processing and/or storing data submitted by an HTML form.
  • Providing dynamic content, e.g. returning the results of a database query to the client.
  • Managing state information on top of the stateless HTTP, e.g. for an online shopping cart system which manages shopping carts for many concurrent customers and maps every request to the right customer.
Servlets have several advantages over CGI:
  • A Servlet does not run in a separate process. This removes the overhead of creating a new process for each request.
  • A Servlet stays in memory between requests. A CGI program (and probably also an extensive runtime system or interpreter) needs to be loaded and started for each CGI request.
  • There is only a single instance which answers all requests concurrently. This saves memory and allows a Servlet to easily manage persistent data.
  • A Servlet can be run by a Servlet Engine in a restrictive Sandbox (just like an Applet runs in a Web Browser's Sandbox) which allows secure use of untrusted and potentially harmful Servlets.

servlets interview questions


5)What is session?
The session is an object used by a servlet to track a user's interaction with a Web application across multiple HTTP requests. The session is stored on the server.

6)What is servlet mapping?
 The servlet mapping defines an association between a URL pattern and a servlet. The mapping is used to map requests to Servlets.





7)What is servlet context
The servlet context is an object that contains a information about the Web application and container.  Using the context, a servlet can log events, obtain URL references to resources, and set and store attributes that other servlets in the context can use.

8)What is a servlet?
servlet is a java program that runs inside a web container.

9)Can we use the constructor, instead of init(), to initialize servlet?
Yes. But you will not get the servlet specific things from constructor. The original reason for init() was that ancient versions of Java couldn’t dynamically invoke constructors with arguments, so there was no way to give the constructor a ServletConfig. That no longer applies, but servlet containers still will only call your no-arg constructor. So you won’t have access to a ServletConfig or ServletContext.

10)How many JSP scripting elements are there and what are they?
 There are three scripting language elements: declarations, scriptlets, expressions.

11)How can I implement a thread-safe JSP page?
You can make your JSPs thread-safe adding the directive <%@ page isThreadSafe="false" % > within your JSP page.

12)What is the difference in using request.getRequestDispatcher() and context.getRequestDispatcher()?
In request.getRequestDispatcher(path) in order to create it we need to give the relative path of the resource. But in   resourcecontext.getRequestDispatcher(path) in order to create it we need to give the absolute path of the resource.

13)What are the lifecycle of JSP?
When presented with JSP page the 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.

14)What are context initialization parameters?
Context initialization parameters are specified by the <context-param> in the web.xml file, these are initialization parameter for the whole application.

15)What is a Expression?
Expressions are act as place holders for language expression, expression is evaluated each time the page is accessed. This will be included in the service method of the generated servlet

16)What is a Declaration?
 It declares one or more variables or methods for use later in the JSP source file. A declaration must contain at least one complete declarative statement. You can declare any number of variables or methods within one declaration tag, as long as semicolons separate them. The declaration must be valid in the scripting language used in the JSP file. This will be included in the declaration section of the generated servlet.

17)How do I include static files within a JSP page?
 Static resources should always be included using the JSP include directive. This way, the inclusion is performed just once during the translation phase. 


servlets interview questions


13)How will you include a static file in a JSP page?
You can include a static resource to a JSP using <jsp:directive > or <%@ inlcude >.

14)How you can perform browser redirection?
We can use the method sendRedirect of HttpServletResponse or forward method of RequestDispatcher

15)Can we use  ServletOutputStream object from a JSP page?
No. You are supposed to use JSPWriter object (given to you in the form of the implicit object out) only for replying to clients.

16)How can you stop JSP execution in the middle of processing a request?
We can use the return statement to stop the processing of JSP. Because JSP is compiled to servlet and all the statements will go inside service method, any time you can stop the processing using return statement.

17)How can I invoke a JSP error page from a servlet? You can invoke the JSP error page and pass the exception object to it from within a servlet. For that you need to create a request dispatcher for the JSP error page, and pass the exception object as a javax.servlet.jsp.jspException request attribute

18)How does JSP handle runtime exceptions? Using errorPage attribute of page directive JSP handles runtime exceptions. We need to specify isErrorPage=true if the current page is intended to use as a JSP error page.

19)What is the difference between JSP and Servlets ?
JSP is used mainly for presentation only. A JSP can only be HttpServlet that means the only supported protocol in JSP is HTTP. But a servlet can support any protocol like HTTP, FTP, SMTP etc.

20) What is difference between custom JSP tags and beans?
 Custom JSP tag is a tag you defined. You define how a tag, its attributes and its body are interpreted, and then group your tags into collections called tag libraries that can be used in any number of JSP files. To use custom JSP tags, you need to define three separate components: the tag handler class that defines the tag's behavior ,the tag library descriptor file that maps the XML element names to the tag implementations and the JSP file that uses the tag library

JavaBeans are Java utility classes you defined. Beans have a standard format for Java classes. You use tags

Custom tags and beans accomplish the same goals -- encapsulating complex behavior into simple and accessible forms. There are several differences:

Custom tags can manipulate JSP content; beans cannot. Complex operations can be reduced to a significantly simpler form with custom tags than with beans. Custom tags require quite a bit more work to set up than do beans. Custom tags usually define relatively self-contained behavior, whereas beans are often defined in one servlet and used in a different servlet or JSP page. Custom tags are available only in JSP 1.1 and later, but beans can be used in all JSP 1.x versions.

21) What are the different ways for session tracking?
Cookies, URL rewriting, HttpSession, Hidden form fields

22)What mechanisms are used by a Servlet Container to maintain session information?
Cookies, URL rewriting, and HTTPS protocol information are used to maintain session information

23)Difference between GET and POST?
 In GET your entire form submission can be encapsulated in one URL, like a hyperlink. query length is limited to 255 characters, not secure, faster, quick and easy. The data is submitted as part of URL.

servlets interview questions

8)What is the difference between Context init parameter and Servlet init parameter?
Servlet init parameters are for a single servlet only. No body out side that servlet can access that. It is declared inside the <servlet> tag inside Deployment Descriptor, where as context init parameter is for the entire web application. Any servlet or JSP in that web application can access context init parameter. Context parameters are declared in a tag <context-param> directly inside the <web-app> tag. The methods for accessing context init parameter is getServletContext ().getInitParamter (“name”) where as method for accessing servlet init parameter is getServletConfig ().getInitParamter (“name”);


9)What are the different ways for getting a servlet context?
We will get ServletContext by calling getServletConfig ().getServletContext (). This is because a ServletConfig always hold a reference to ServletContext. By calling this.getServletContext () also we will get a ServletContext object.


10)What is the difference between an attribute and a parameter?
The return type of attribute is object, where the return type of parameter is String. The method to retrieve attribute is getAttribute () where as for parameter is getParamter (). We have a method setAttribute to set an attribute. But there is no setters available for setting a parameter.


11)How to make a context thread safe?
Synchronizing the ServletContext is the only solution to make a ServletContext thread safe. 
Eg: synchronized (getServletContext ()) {
      // do whatever you want with thread safe context.
}


12)What is the difference between setting the session time out in deployment descriptor and setting the time out programmatically?
In DD time out is specified in terms of minutes only. But in programmatically it is specified in seconds. A session time out value of zero or less in DD means that the session will never expire. To specify session will never expire programmatically it must be negative value.

servlets interview questions


1)What is the difference between ServletContext and ServletConfig?
The ServletConfig gives the information about the servlet initialization parameters. The servlet engine implements the ServletConfig interface in order to pass configuration information to a servlet. The server passes an object that implements the ServletConfig interface to the servlet's init() method. The ServletContext gives information about the container. The ServletContext interface provides information to servlets regarding the environment in which they are running. It also provides standard way for servlets to write events to a log file.

2)What is client side refresh?
The standard HTTP protocols ways of refreshing the page, which is normally supported by all browsers. <META HTTP-EQUIV="Refresh" CONTENT="5; URL=/servlet/MyServlet/"> This will refresh the page in the browser automatically and loads the new data every 5 seconds.
3)What is the Max amount of information that can be saved in a Session Object ?
There is no such limit on the amount of information that can be saved in a Session Object.  The only limit is the Session ID length , which should not exceed more than 4K.
4)Why should we go for inter servlet communication?
The three major reasons to use inter servlet communication are: a) Direct servlet manipulation - allows to gain access to the other currently loaded servlets and perform certain tasks (through the ServletContext object) b) Servlet reuse - allows the servlet to reuse the public methods of another servlet. c) Servlet collaboration - requires to communicate with each other by sharing specific information (through method invocation)
5)What are the differences between a session and a cookie?
Session is stored in server but cookie stored in client. Session should work regardless of the settings on the client browser. There is no limit on the amount of data that can be stored on session. But it is limited in cookie. Session can store objects and cookies can store only strings. Cookies are faster than session
6)What is HttpTunneling?
HTTP tunneling is used to encapsulate other protocols within the HTTP or HTTPS protocols. Normally the intranet is blocked by a firewall and the network is exposed to the outer world only through a specific web server port, that listens for only HTTP requests. To use any other protocol, that by passes the firewall, the protocol is embedded in HTTP and send as HttpRequest.
7)How to pass information from JSP to included JSP?
By using <jsp:param> tag.

Tuesday, 26 June 2012

Java interview questions


Question: What is the difference between interface and abstract class?
Answer:
interface contains methods that must be abstract; abstract class may contain concrete methods.
interface contains variables that must be static and final; abstract class may contain non-final and final variables.
members in an interface are public by default, abstract class may contain non-public members.
interface is used to "implements"; whereas abstract class is used to "extends".
interface can be used to achieve multiple inheritance; abstract class can be used as a single inheritance.
interface can "extends" another interface, abstract class can "extends" another class and "implements" multiple interfaces.
 interface is absolutely abstract; abstract class can be invoked if a main() exists.
interface is more flexible than abstract class because one class can only "extends" one super class, but "implements" multiple interfaces.

















Question: Why do we need public static void main(String args[]) method in Java
Answer: We need
  • public: The method can be accessed outside the class / package
  • static: You need not have an instance of the class to access the method
  • void: Your application need not return a value, as the JVM launcher would return the value when it exits
  • main(): This is the entry point for the application
If the main() was not static, you would require an instance of the class in order to execute the method.
If this is the case, what would create the instance of the class? What if your class did not have a public constructor?

Question: What are the rules of serialization
Answer: Rules:
1. Static fileds are not serialized because they are not part of any one particular object
2. Fileds from the base class are handled only if hose are serializable
3. Transient fileds are not serialized

Question: What is difference between error and exception
Answer: Error occurs at runtime and cannot be recovered, Outofmemory is one such example. Exceptions on the other hand are due conditions which the application encounters such as FileNotFound exception or IO exceptions.

Question: What do you mean by object oreiented programming
Answer: In object oreinted programming the emphasis is more on data than on the procedure and the program is divided into objects.
The data fields are hidden and they cant be accessed by external functions.
The design approach is bottom up.
The functions operate on data that is tied together in data structure 

Java interview questions with answers


Question: What is casting?
Answer:
There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference.

Question: Name Container classes.
Answer:
Window, Frame, Dialog, FileDialog, Panel, Applet, or ScrollPane.

Question: What class allows you to read objects directly from a stream? 
Answer:
The ObjectInputStream class supports the reading of objects from input streams.

Question:  How are this() and super() used with constructors?
Answer:
this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.

Question:  How is it possible for two String objects with identical values not to be equal under the == operator?
Answer:
The == operator compares two objects to determine if they are the same object in memory. It is possible for two String objects to have the same value, but located indifferent areas of memory.

Question: What interface must an object implement before it can be written to a stream as an object?
Answer:
An object must implement the Serializable or Externalizable interface before it can be written to a stream as an object.

Question: What is the ResourceBundle class?
Answer:
The ResourceBundle class is used to store locale-specific resources that can be loaded by a program to tailor the program's appearance to the particular locale in which it is being run.

Question: What is the difference between a Scrollbar and a ScrollPane?
Answer:
A Scrollbar is a Component, but not a Container. A ScrollPane is a Container. A ScrollPane handles its own events and performs its own scrolling.

Question: What are the Object and Class classes used for?
Answer:
The Object class is the highest-level class in the Java class hierarchy. The Class class is used to represent the classes and interfaces that are loaded by a Java program.

Question: Does the code in finally block get executed if there is an exception and a return statement in a catch block?
Answer:
  If an exception occurs and there is a return statement in catch block, the finally block is still executed. The finally block will not be executed when the System.exit(1) statement is executed earlier or the system shut down earlier or the memory is used up earlier before the thread goes to finally block.

Question: How you restrict a user to cut and paste from the html page?
Answer:
Using javaScript to lock keyboard keys. It is one of solutions.

Java interview questions


Question: What classes of exceptions may be caught by a catch clause?
Answer:
A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types.

Question:What is the difference between throw and throws keywords? 
Answer:
The throw keyword denotes a statement that causes an exception to be initiated. It takes the Exception object to be thrown as argument. The exception will be caught by an immediately encompassing try-catch construction or propagated further up the calling hierarchy. The throws keyword is a modifier of a method that designates that exceptions may come out of the mehtod, either by virtue of the method throwing the exception itself or because it fails to catch such exceptions that a method it calls may throw.





      




Question: If a class is declared without any access modifiers, where may the class be accessed?
Answer:
A class that is declared without any access modifiers is said to have package or friendly access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package.

Question: What is the Map interface?
Answer:
The Map interface replaces the JDK 1.1 Dictionary class and is used associate keys with values.

Question: Which class should you use to obtain design information about an object?
Answer:
The Class class is used to obtain information about an object's design.

Question: What are the problems faced by Java programmers who don't use layout managers?
Answer:
Without layout managers, Java programmers are faced with determining how their GUI will be displayed across multiple windowing systems and finding a common sizing and positioning that will work within the constraints imposed by each windowing system.

Question: What is the difference between static and non-static variables?
Answer:
A static variable is associated with the class as a whole rather than with specific instances of a class. Non-static variables take on unique values with each object instance.

Question: What is the difference between the paint() and repaint() methods?
Answer:
  The paint() method supports painting via a Graphics object. The repaint() method is used to cause paint() to be invoked by the AWT painting thread.

Question:  What is the purpose of the File class?
Answer:
The File class is used to create objects that provide access to the files and directories of a local file system.

Question:  What restrictions are placed on method overloading?
Answer:
Two methods may not have the same name and argument list but different return types.

Question:  What restrictions are placed on method overriding?
Answer:
Overridden methods must have the same name, argument list, and return type. The overriding method may not limit the access of the method it overrides. The overriding method may not throw any exceptions that may not be thrown by the overridden method.

Java interview questions


Question: What is the purpose of the finally clause of a try-catch-finally statement?
Answer:
The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught.

Question: What must a class do to implement an interface?
Answer:
It must provide all of the methods in the interface and identify the interface in its implements clause.
Question: What is an abstract method?
Answer:
An abstract method is a method whose implementation is deferred to a subclass. Or, a method that has no implementation (an interface of a method).

Question: What is a static method? 
Answer:
A static method is a method that belongs to the class rather than any object of the class and doesn't apply to an object or even require that any objects of the class have been instantiated.

Question: What is the difference between a static and a non-static inner class?
Answer:
A non-static inner class may have object instances that are associated with instances of the class's outer class. A static inner class does not have any object instances.

Question:  What is an object's lock and which object's have locks?
Answer:
  An object's lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object's lock. All objects and classes have locks. A class's lock is acquired on the class's Class object.

Question: When can an object reference be cast to an interface reference?
Answer:
An object reference be cast to an interface reference when the object implements the referenced interface.

Question:  What is the difference between a Window and a Frame?
Answer:
The Frame class extends Window to define a main application window that can have a menu bar.

Question: What happens when a thread cannot acquire a lock on an object?
Answer:
If a thread attempts to execute a synchronized method or synchronized statement and is unable to acquire an object's lock, it enters the waiting state until the lock becomes available.

Question: What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?
Answer:
The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.

Question: What classes of exceptions may be caught by a catch clause?
Answer:
A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types.

java interview questions


Question: What is the purpose of the wait(), notify(), and notifyAll() methods?
Answer:
The wait(),notify(), and notifyAll() methods are used to provide an efficient way for threads to communicate each other.
Question: What is the Collections API?
Answer:
The Collections API is a set of classes and interfaces that support operations on collections of objects.
Question: What is the List interface? 
Answer:
The List interface provides support for ordered collections of objects.
Question: If a method is declared as protected, where may the method be accessed?
Answer:
A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.

Question:  What is an Iterator interface?
Answer:
  The Iterator interface is used to step through the elements of a Collection.

Question:  How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?
Answer:
Unicode requires 16 bits and ASCII require 7 bits. Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits. UTF-8 represents characters using 8, 16, and 18 bit patterns. UTF-16 uses 16-bit and larger bit patterns.

Question:  What is the difference between yielding and sleeping? 
Answer:
When a task invokes its yield() method, it returns to the ready state. When a task invokes its sleep() method, it returns to the waiting state.

Question:  Is sizeof a keyword? 
Answer:
  The sizeof operator is not a keyword.

Question: What are wrapped classes?
Answer:
Wrapped classes are classes that allow primitive types to be accessed as objects.

Question: Does garbage collection guarantee that a program will not run out of memory? 
Answer:
No, it doesn't. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection.

Question: Name Component subclasses that support painting.
Answer:
The Canvas, Frame, Panel, and Applet classes support painting.

Question: What is a native method?
Answer:
A native method is a method that is implemented in a language other than Java.

Question: How can you write a loop indefinitely?
Answer:
for(;;)--for loop; while(true)--always true, etc.

Question: . Can an anonymous class be declared as implementing an interface and extending a class?
Answer:
An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.

java interview questions with answers


Question: What is a native method?
Answer:
A native method is a method that is implemented in a language other than Java.

Question: How can you write a loop indefinitely?
Answer:
for(;;)--for loop; while(true)--always true, etc.

Question: . Can an anonymous class be declared as implementing an interface and extending a class?
Answer:
An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.

Question: What is the purpose of finalization?
Answer:
The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.





             





Question: What is the difference between the Boolean & operator and the && operator? 
Answer:
If an expression involving the Boolean & operator is evaluated, both operands are evaluated. Then the & operator is applied to the operand. When an expression involving the && operator is evaluated, the first operand is evaluated. If the first operand returns a value of true then the second operand is evaluated. The && operator is then applied to the first and second operands. If the first operand evaluates to false, the evaluation of the second operand is skipped.
Operator & has no chance to skip both sides evaluation and && operator does. If asked why, give details as above.

Question: What is the GregorianCalendar class?
Answer:
The GregorianCalendar provides support for traditional Western calendars.

Question: What is the SimpleTimeZone class?
Answer:
The SimpleTimeZone class provides support for a Gregorian calendar.

Question: What is the Properties class?
Answer:
The properties class is a subclass of Hashtable that can be read from or written to a stream. It also provides the capability to specify a set of default values to be used.

Question: What is the purpose of the Runtime class?
Answer:
The purpose of the Runtime class is to provide access to the Java runtime system.

Question:  What is the purpose of the System class? 
Answer:
The purpose of the System class is to provide access to system resources.

java interview questions


Question: What is the purpose of the wait(), notify(), and notifyAll() methods?
Answer:
The wait(),notify(), and notifyAll() methods are used to provide an efficient way for threads to communicate each other.

Question: What is the Collections API?
Answer:
The Collections API is a set of classes and interfaces that support operations on collections of objects.

Question: What is the List interface? 
Answer:
The List interface provides support for ordered collections of objects.

Question: If a method is declared as protected, where may the method be accessed?
Answer:
A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.

Question:  What is an Iterator interface?
Answer:
  The Iterator interface is used to step through the elements of a Collection.

Question:  How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?
Answer:
Unicode requires 16 bits and ASCII require 7 bits. Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits. UTF-8 represents characters using 8, 16, and 18 bit patterns. UTF-16 uses 16-bit and larger bit patterns.

Question:  What is the difference between yielding and sleeping? 
Answer:
When a task invokes its yield() method, it returns to the ready state. When a task invokes its sleep() method, it returns to the waiting state.

Question:  Is sizeof a keyword? 
Answer:
  The sizeof operator is not a keyword.

Question: What are wrapped classes?
Answer:
Wrapped classes are classes that allow primitive types to be accessed as objects.

Question: Does garbage collection guarantee that a program will not run out of memory? 
Answer:
No, it doesn't. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection.

Question: Name Component subclasses that support painting.
Answer:
The Canvas, Frame, Panel, and Applet classes support painting.