java interview
http://www.javacamp.org/jobinterview.html
What is garbage collection? What is the process that is responsible for doing that in java? - Reclaiming the unused memory by the invalid objects. Garbage collector is responsible for this process What kind of thread is the Garbage collector thread? - It is a daemon thread.
What is a daemon thread? - These are the threads which can run without user intervention. The JVM can exit when there are daemon thread by killing them abruptly. How will you invoke any external process in Java? - Runtime.getRuntime().exec(….) What is the finalize method do? - Before the invalid objects get garbage collected, the JVM give the user a chance to clean up some resources before it got garbage collected. What is mutable object and immutable object? - If a object value is changeable then we can call it as Mutable object. (Ex., StringBuffer, …) If you are not allowed to change the value of an object, it is immutable object. (Ex., String, Integer, Float, …) What is the basic difference between string and stringbuffer object? - String is an immutable object. StringBuffer is a mutable object. What is the purpose of Void class? - The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the primitive Java type void. What is reflection? - Reflection allows programmatic access to information about the fields, methods and constructors of loaded classes, and the use reflected fields, methods, and constructors to operate on their underlying counterparts on objects, within security restrictions. What is the base class for Error and Exception? - Throwable What is the byte range? -128 to 127 What is the implementation of destroy method in java.. is it native or java code? - This method is not implemented. What is a package? - To group set of classes into a single unit is known as packaging. Packages provides wide namespace ability. What are the approaches that you will follow for making a program very efficient? - By avoiding too much of static methods avoiding the excessive and unnecessary use of synchronized methods Selection of related classes based on the application (meaning synchronized classes for multiuser and non-synchronized classes for single user) Usage of appropriate design patterns Using cache methodologies for remote invocations Avoiding creation of variables within a loop and lot more. What is a DatabaseMetaData? - Comprehensive information about the database as a whole. What is Locale? - A Locale object represents a specific geographical, political, or cultural region How will you load a specific locale? - Using ResourceBundle.getBundle(…); What is JIT and its use? - Really, just a very fast compiler… In this incarnation, pretty much a one-pass compiler – no offline computations. So you can’t look at the whole method, rank the expressions according to which ones are re-used the most, and then generate code. In theory terms, it’s an on-line problem. Is JVM a compiler or an interpreter? - Interpreter When you think about optimization, what is the best way to findout the time/memory consuming process? - Using profiler What is the purpose of assert keyword used in JDK1.4.x? - In order to validate certain expressions. It effectively replaces the if block and automatically throws the AssertionError on failure. This keyword should be used for the critical arguments. Meaning, without that the method does nothing. How will you get the platform dependent values like line separator, path separator, etc., ? - Using Sytem.getProperty(…) (line.separator, path.separator, …) What is skeleton and stub? what is the purpose of those? - Stub is a client side representation of the server, which takes care of communicating with the remote server. Skeleton is the server side representation. But that is no more in use… it is deprecated long before in JDK. What is the final keyword denotes? - final keyword denotes that it is the final implementation for that method or variable or class. You can’t override that method/variable/class any more. What is the significance of ListIterator? - You can iterate back and forth. What is the major difference between LinkedList and ArrayList? - LinkedList are meant for sequential accessing. ArrayList are meant for random accessing. What is nested class? - If all the methods of a inner class is static then it is a nested class. What is inner class? - If the methods of the inner class can only be accessed via the instance of the inner class, then it is called inner class. What is composition? - Holding the reference of the other class within some other class is known as composition. What is aggregation? - It is a special type of composition. If you expose all the methods of a composite class and route the method call to the composite method through its reference, then it is called aggregation. What are the methods in Object? - clone, equals, wait, finalize, getClass, hashCode, notify, notifyAll, toString Can you instantiate the Math class? - You can’t instantiate the math class. All the methods in this class are static. And the constructor is not public. What is singleton? - It is one of the design pattern. This falls in the creational pattern of the design pattern. There will be only one instance for that entire JVM. You can achieve this by having the private constructor in the class. For eg., public class Singleton { private static final Singleton s = new Singleton(); private Singleton() { } public static Singleton getInstance() { return s; } // all non static methods … } What is DriverManager? - The basic service to manage set of JDBC drivers. What is Class.forName() does and how it is useful? - It loads the class into the ClassLoader. It returns the Class. Using that you can get the instance ( “class-instance".newInstance() ).
http://www.techinterviews.com/index.php?p=144
Core Java Interview Questions
Question: What is transient variable?Answer: Transient variable can't be serialize. For example if a variable is declared as transient in a Serializable class and the class is written to an ObjectStream, the value of the variable can't be written to the stream instead when the class is retrieved from the ObjectStream the value of the variable becomes null. Question: Name the containers which uses Border Layout as their default layout?Answer: Containers which uses Border Layout as their default are: window, Frame and Dialog classes. Question: What do you understand by Synchronization?Answer: Synchronization is a process of controlling the access of shared resources by the multiple threads in such a manner that only one thread can access one resource at a time. In non synchronized multithreaded application, it is possible for one thread to modify a shared object while another thread is in the process of using or updating the object's value. Synchronization prevents such type of data corruption.E.g. Synchronizing a function:public synchronized void Method1 () { // Appropriate method-related code. }E.g. Synchronizing a block of code inside a function:public myFunction (){ synchronized (this) { // Synchronized code here. }} Question: What is Collection API?Answer: The Collection API is a set of classes and interfaces that support operation on collections of objects. These classes and interfaces are more flexible, more powerful, and more regular than the vectors, arrays, and hashtables if effectively replaces. Example of classes: HashSet, HashMap, ArrayList, LinkedList, TreeSet and TreeMap.Example of interfaces: Collection, Set, List and Map. Question: Is Iterator a Class or Interface? What is its use?Answer: Iterator is an interface which is used to step through the elements of a Collection. Question: What is similarities/difference between an Abstract class and Interface?Answer: Differences are as follows: Interfaces provide a form of multiple inheritance. A class can extend only one other class. Interfaces are limited to public methods and constants with no implementation. Abstract classes can have a partial implementation, protected parts, static methods, etc. A Class may implement several interfaces. But in case of abstract class, a class may extend only one abstract class. Interfaces are slow as it requires extra indirection to to find corresponding method in in the actual class. Abstract classes are fast. Similarities:
Neither Abstract classes or Interface can be instantiated. Question: How to define an Abstract class?Answer: A class containing abstract method is called Abstract class. An Abstract class can't be instantiated. Example of Abstract class:abstract class testAbstractClass { protected String myString; public String getMyString() { return myString; } public abstract string anyAbstractFunction();} Question: How to define an Interface?Answer: In Java Interface defines the methods but does not implement them. Interface can include constants. A class that implements the interfaces is bound to implement all the methods defined in Interface.Emaple of Interface:
public interface sampleInterface { public void functionOne();
public long CONSTANT_ONE = 1000; } Question: Explain the user defined Exceptions?Answer: User defined Exceptions are the separate Exception classes defined by the user for specific purposed. An user defined can created by simply sub-classing it to the Exception class. This allows custom exceptions to be generated (using throw) and caught in the same way as normal exceptions. Example:class myCustomException extends Exception { // The class simply has to exist to be an exception } Question: Explain the new Features of JDBC 2.0 Core API?Answer: The JDBC 2.0 API includes the complete JDBC API, which includes both core and Optional Package API, and provides inductrial-strength database computing capabilities. New Features in JDBC 2.0 Core API:
Scrollable result sets- using new methods in the ResultSet interface allows programmatically move the to particular row or to a position relative to its current position JDBC 2.0 Core API provides the Batch Updates functionality to the java applications. Java applications can now use the ResultSet.updateXXX methods. New data types - interfaces mapping the SQL3 data types Custom mapping of user-defined types (UTDs) Miscellaneous features, including performance hints, the use of character streams, full precision for java.math.BigDecimal values, additional security, and support for time zones in date, time, and timestamp values.
Question: Explain garbage collection?Answer: Garbage collection is one of the most important feature of Java. Garbage collection is also called automatic memory management as JVM automatically removes the unused variables/objects (value is null) from the memory. User program cann't directly free the object from memory, instead it is the job of the garbage collector to automatically free the objects that are no longer referenced by a program. Every class inherits finalize() method from java.lang.Object, the finalize() method is called by garbage collector when it determines no more references to the object exists. In Java, it is good idea to explicitly assign null into a variable when no more in use. I Java on calling System.gc() and Runtime.gc(), JVM tries to recycle the unused objects, but there is no guarantee when all the objects will garbage collected. Question: How you can force the garbage collection?Answer: Garbage collection automatic process and can't be forced. Question: What is OOPS?Answer: OOP is the common abbreviation for Object-Oriented Programming. 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 specifiers are keywords that determines the type of access to the member of a class. These are: Public Protected Private Defaults Question: Describe the wrapper classes in Java.Answer: Wrapper class is wrapper around a primitive data type. An instance of a wrapper class contains, or wraps, a primitive value of the corresponding type.
Following table lists the primitive types and the corresponding wrapper classes:
Primitive Wrapper boolean java.lang.Boolean byte java.lang.Byte char java.lang.Character double java.lang.Double float java.lang.Float int java.lang.Integer long java.lang.Long short java.lang.Short void java.lang.Void
http://roseindia.net/interviewquestions/jakartastrutsinterviewquestions.shtml
Q: What is Jakarta Struts Framework?A: Jakarta Struts is open source implementation of MVC (Model-View-Controller) pattern for the development of web based applications. Jakarta Struts is robust architecture and can be used for the development of application of any size. Struts framework makes it much easier to design scalable, reliable Web applications with Java. Q: What is ActionServlet?A: The class org.apache.struts.action.ActionServlet is the called the ActionServlet. In the the Jakarta Struts Framework this class plays the role of controller. All the requests to the server goes through the controller. Controller is responsible for handling all the requests. Q: How you will make available any Message Resources Definitions file to the Struts Framework Environment?A: Message Resources Definitions file are simple .properties files and these files contains the messages that can be used in the struts project. Message Resources Definitions files can be added to the struts-config.xml file through tag.Example: Q: What is Action Class?A: The Action Class is part of the Model and is a wrapper around the business logic. The purpose of Action Class is to translate the HttpServletRequest to the business logic. To use the Action, we need to Subclass and overwrite the execute() method. In the Action Class all the database/business processing are done. It is advisable to perform all the database related stuffs in the Action Class. The ActionServlet (commad) passes the parameterized class to Action Form using the execute() method. The return type of the execute method is ActionForward which is used by the Struts Framework to forward the request to the file as per the value of the returned ActionForward object. Q: Write code of any Action Class?A: Here is the code of Action Class that returns the ActionForward object.TestAction.java package roseindia.net;
import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;
public class TestAction extends Action{ public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception{ return mapping.findForward("testAction"); }}
Q: What is ActionForm?A: An ActionForm is a JavaBean that extends org.apache.struts.action.ActionForm. ActionForm maintains the session state for web application and the ActionForm object is automatically populated on the server side with data entered from a form on the client side. Q: What is Struts Validator Framework?A: Struts Framework provides the functionality to validate the form data. It can be use to validate the data on the users browser as well as on the server side. Struts Framework emits the java scripts and it can be used validate the form data on the client browser. Server side validation of form can be accomplished by sub classing your From Bean with DynaValidatorForm class. The Validator framework was developed by David Winterfeldt as third-party add-on to Struts. Now the Validator framework is a part of Jakarta Commons project and it can be used with or without Struts. The Validator framework comes integrated with the Struts Framework and can be used without doing any extra settings.
Q. Give the Details of XML files used in Validator Framework?A: The Validator Framework uses two XML configuration files validator-rules.xml and validation.xml. The validator-rules.xml defines the standard validation routines, these are reusable and used in validation.xml. to define the form specific validations. The validation.xml defines the validations applied to a form bean.
Q. How you will display validation fail errors on jsp page?A: Following tag displays all the errors:
Q. How you will enable front-end validation based on the xml in validation.xml?A: The tag to allow front-end validation based on the xml in validation.xml. For example the code: generates the client side java script for the form "logonForm" as defined in the validation.xml file. The when added in the jsp file generates the client site validation script.
http://www.sap-img.com/java/java-interview-questions.htm
only quest......
What is the diffrence between an Abstract class and Interface ? What is user defined exception ? What do you know about the garbate collector ? What is the difference between C++ & Java ? Explain RMI Architecture? How do you communicate in between Applets & Servlets ? What is the use of Servlets ? What is JDBC? How do you connect to the Database ? In an HTML form I have a Button which makes us to open another page in 15 seconds. How will do you that ? What is the difference between Process and Threads ? What is the difference between RMI & Corba ? What are the services in RMI ? How will you initialize an Applet ? What is the order of method invocation in an Applet ? When is update method called ? How will you pass values from HTML page to the Servlet ? Have you ever used HashTable and Dictionary ? How will you communicate between two Applets ? What are statements in JAVA ? What is JAR file ? What is JNI ? What is the base class for all swing components ? What is JFC ? What is Difference between AWT and Swing ? Considering notepad/IE or any other thing as process, What will happen if you start notepad or IE 3 times? Where 3 processes are started or 3 threads are started ? How does thread synchronization occurs inside a monitor ? How will you call an Applet using a Java Script function ? Is there any tag in HTML to upload and download files ? Why do you Canvas ? How can you push data from an Applet to Servlet ? What are 4 drivers available in JDBC ? How you can know about drivers and database information ? If you are truncated using JDBC, How can you know ..that how much data is truncated ? And What situation , each of the 4 drivers used ? How will you perform transaction using JDBC ? In RMI, server object first loaded into the memory and then the stub reference is sent to the client ? or whether a stub reference is directly sent to the client ? Suppose server object is not loaded into the memory, and the client request for it , what will happen? What is serialization ? Can you load the server object dynamically? If so, what are the major 3 steps involved in it ? What is difference RMI registry and OSAgent ? To a server method, the client wants to send a value 20, with this value exceeds to 20,. a message should be sent to the client ? What will you do for achieving for this ? What are the benefits of Swing over AWT ? Where the CardLayout is used ? What is the Layout for ToolBar ? What is the difference between Grid and GridbagLayout ? How will you add panel to a Frame ? What is the corresponding Layout for Card in Swing ? What is light weight component ? Can you run the product development on all operating systems ? What is the webserver used for running the Servlets ? What is Servlet API used for conneting database ? What is bean ? Where it can be used ? What is difference in between Java Class and Bean ? Can we send object using Sockets ? What is the RMI and Socket ? How to communicate 2 threads each other ? What are the files generated after using IDL to Java Compilet ? What is the protocol used by server and client ? Can I modify an object in CORBA ? What is the functionality stubs and skeletons ? What is the mapping mechanism used by Java to identify IDL language ? Diff between Application and Applet ? What is serializable Interface ? What is the difference between CGI and Servlet ? What is the use of Interface ? Why Java is not fully objective oriented ? Why does not support multiple Inheritance ? What it the root class for all Java classes ? What is polymorphism ? Suppose If we have variable ' I ' in run method, If I can create one or more thread each thread will occupy a separate copy or same variable will be shared ? In servlets, we are having a web page that is invoking servlets username and password ? which is cheks in the database ? Suppose the second page also If we want to verify the same information whethe it will connect to the database or it will be used previous information? What are virtual functions ? Write down how will you create a binary Tree ? What are the traverses in Binary Tree ? Write a program for recursive Traverse ? What are session variable in Servlets ? What is client server computing ? What is Constructor and Virtual function? Can we call Virtual funciton in a constructor ? Why we use OOPS concepts? What is its advantage ? What is the middleware ? What is the functionality of Webserver ? Why Java is not 100 % pure OOPS ? ( EcomServer ) When we will use an Interface and Abstract class ? What is an RMI? How will you pass parameters in RMI ? Why u serialize? What is the exact difference in between Unicast and Multicast object ? Where we will use ? What is the main functionality of the Remote Reference Layer ? How do you download stubs from a Remote place ? What is the difference in between C++ and Java ? can u explain in detail ? I want to store more than 10 objects in a remote server ? Which methodology will follow ? What is the main functionality of the Prepared Statement ? What is meant by static query and dynamic query ? What are the Normalization Rules ? Define the Normalization ? What is meant by Servelet? What are the parameters of the service method ? What is meant by Session ? Tell me something about HTTPSession Class ? How do you invoke a Servelt? What is the difference in between doPost and doGet methods ? What is the difference in between the HTTPServlet and Generic Servlet ? Expalin their methods ? Tell me their parameter names also ? Have you used threads in Servelet ? Write a program on RMI and JDBC using StoredProcedure ? How do you sing an Applet ? In a Container there are 5 components. I want to display the all the components names, how will you do that one ? Why there are some null interface in java ? What does it mean ? Give me some null interfaces in JAVA ? Tell me the latest versions in JAVA related areas ? What is meant by class loader ? How many types are there? When will we use them ? How do you load an Image in a Servlet ? What is meant by flickering ? What is meant by distributed Application ? Why we are using that in our applications ? What is the functionality of the stub ? Have you used any version control ? What is the latest version of JDBC ? What are the new features are added in that ? Explain 2 tier and 3 -tier Architecture ? What is the role of the webserver ? How have you done validation of the fileds in your project ? What is the main difficulties that you are faced in your project ? What is meant by cookies ? Explain ? Problem faced in your earlier project How OOPS concept is achieved in Java Features for using Java How does Java 2.0 differ from Java 1.0 Public static void main – Explain What are command line arguments Explain about the three-tier model Difference between String & StringBuffer Wrapper class. Is String a Wrapper Class What are the restriction for static method Purpose of the file class Default modifier in Interface Difference between Interface & Abstract class Can abstract be declared as Final Can we declare variables inside a method as Final Variables What is the package concept and use of package How can a dead thread be started Difference between Applet & Application Life cycle of the Applet Can Applet have constructors Differeence between canvas class & graphics class Explain about Superclass & subclass Difference between TCP & UDP What is AppletStub Explain Stream Tokenizer What is the difference between two types of threads Checked & Unchecked exception Use of throws exception What is finally in exception handling Vector class What will happen to the Exception object after exception handling Two types of multi-tasking Two ways to create the thread Synchronization I/O Filter How can you retrieve warnings in JDBC Can applet in different page communicate with each other Four driver Manager Features of JDBC 20 Explain about stored procedures Servlet Life cycle Why do you go for servlet rather than CGI How to generate skeleton & Stub classes Explain lazy activation Firewalls in RMI
forum 4r java interview quest.........................http://forum.java.sun.com/thread.jspa?threadID=572597&tstart=30
http://www.onesmartclick.com/interviews/interviews-programming.html
Java Language Questions
--------------------------------------------------------------------------------
What is a platform? A platform is the hardware or software environment in which a program runs. Most platforms can be described as a combination of the operating system and hardware, like Windows 2000/XP, Linux, Solaris, and MacOS.
--------------------------------------------------------------------------------
What is the main difference between Java platform and other platforms? The Java platform differs from most other platforms in that it's a software-only platform that runs on top of other hardware-based platforms.
The Java platform has two components:
The Java Virtual Machine (Java VM) The Java Application Programming Interface (Java API)
--------------------------------------------------------------------------------
What is the Java Virtual Machine? The Java Virtual Machine is a software that can be ported onto various hardware-based platforms.
--------------------------------------------------------------------------------
What is the Java API? The Java API is a large collection of ready-made software components that provide many useful capabilities, such as graphical user interface (GUI) widgets.
--------------------------------------------------------------------------------
What is the package? The package is a Java namespace or part of Java libraries. The Java API is grouped into libraries of related classes and interfaces; these libraries are known as packages.
--------------------------------------------------------------------------------
What is native code? The native code is code that after you compile it, the compiled code runs on a specific hardware platform.
--------------------------------------------------------------------------------
Is Java code slower than native code? Not really. As a platform-independent environment, the Java platform can be a bit slower than native code. However, smart compilers, well-tuned interpreters, and just-in-time bytecode compilers can bring performance close to that of native code without threatening portability.
--------------------------------------------------------------------------------
What is the serialization? The serialization is a kind of mechanism that makes a class or a bean persistence by having its properties or fields and state information saved and restored to and from storage.
--------------------------------------------------------------------------------
How to make a class or a bean serializable? By implementing either the java.io.Serializable interface, or the java.io.Externalizable interface. As long as one class in a class's inheritance hierarchy implements Serializable or Externalizable, that class is serializable.
--------------------------------------------------------------------------------
How many methods in the Serializable interface? There is no method in the Serializable interface. The Serializable interface acts as a marker, telling the object serialization tools that your class is serializable.
--------------------------------------------------------------------------------
How many methods in the Externalizable interface? There are two methods in the Externalizable interface. You have to implement these two methods in order to make your class externalizable. These two methods are readExternal() and writeExternal().
--------------------------------------------------------------------------------
What is the difference between Serializalble and Externalizable interface? When you use Serializable interface, your class is serialized automatically by default. But you can override writeObject() and readObject() two methods to control more complex object serailization process. When you use Externalizable interface, you have a complete control over your class's serialization process.
--------------------------------------------------------------------------------
What is a transient variable? A transient variable is a variable that may not be serialized. If you don't want some field to be serialized, you can mark that field transient or static.
--------------------------------------------------------------------------------
Which containers use a border layout as their default layout? The Window, Frame and Dialog classes use a border layout as their default layout.
--------------------------------------------------------------------------------
How are Observer and Observable used? Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects.
--------------------------------------------------------------------------------
What is synchronization and why is it important? With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared object while another thread is in the process of using or updating that object's value. This often causes dirty data and leads to significant errors.
--------------------------------------------------------------------------------
What are synchronized methods and synchronized statements? Synchronized methods are methods that are used to control access to an object. A thread only executes a synchronized method after it has acquired the lock for the method's object or class. Synchronized statements are similar to synchronized methods. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.
--------------------------------------------------------------------------------
What are three ways in which a thread can enter the waiting state? A thread can enter the waiting state by invoking its sleep() method, by blocking on I/O, by unsuccessfully attempting to acquire an object's lock, or by invoking an object's wait() method. It can also enter the waiting state by invoking its (deprecated) suspend() method.
--------------------------------------------------------------------------------
Can a lock be acquired on a class? Yes, a lock can be acquired on a class. This lock is acquired on the class's Class object.
--------------------------------------------------------------------------------
What's new with the stop(), suspend() and resume() methods in JDK 1.2? The stop(), suspend() and resume() methods have been deprecated in JDK 1.2.
--------------------------------------------------------------------------------
What is the preferred size of a component? The preferred size of a component is the minimum component size that will allow the component to display normally.
--------------------------------------------------------------------------------
What method is used to specify a container's layout? The setLayout() method is used to specify a container's layout.
--------------------------------------------------------------------------------
Which containers use a FlowLayout as their default layout? The Panel and Applet classes use the FlowLayout as their default layout.
--------------------------------------------------------------------------------
What is thread? A thread is an independent path of execution in a system.
--------------------------------------------------------------------------------
What is multithreading? Multithreading means various threads that run in a system.
--------------------------------------------------------------------------------
How does multithreading take place on a computer with a single CPU? The operating system's task scheduler allocates execution time to multiple tasks. By quickly switching between executing tasks, it creates the impression that tasks execute sequentially.
--------------------------------------------------------------------------------
How to create multithread in a program? You have two ways to do so. First, making your class "extends" Thread class. Second, making your class "implements" Runnable interface. Put jobs in a run() method and call start() method to start the thread.
--------------------------------------------------------------------------------
Can Java object be locked down for exclusive use by a given thread? Yes. You can lock an object by putting it in a "synchronized" block. The locked object is inaccessible to any thread other than the one that explicitly claimed it.
--------------------------------------------------------------------------------
Can each Java object keep track of all the threads that want to exclusively access to it? Yes.
--------------------------------------------------------------------------------
What state does a thread enter when it terminates its processing? When a thread terminates its processing, it enters the dead state.
--------------------------------------------------------------------------------
What invokes a thread's run() method? After a thread is started, via its start() method of the Thread class, the JVM invokes the thread's run() method when the thread is initially executed.
--------------------------------------------------------------------------------
What is the purpose of the wait(), notify(), and notifyAll() methods? The wait(),notify(), and notifyAll() methods are used to provide an efficient way for threads to communicate each other.
--------------------------------------------------------------------------------
What are the high-level thread states? The high-level thread states are ready, running, waiting, and dead.
--------------------------------------------------------------------------------
What is the Collections API? The Collections API is a set of classes and interfaces that support operations on collections of objects.
--------------------------------------------------------------------------------
What is the List interface? The List interface provides support for ordered collections of objects.
--------------------------------------------------------------------------------
How does Java handle integer overflows and underflows? It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.
--------------------------------------------------------------------------------
What is the Vector class? The Vector class provides the capability to implement a growable array of objects
--------------------------------------------------------------------------------
What modifiers may be used with an inner class that is a member of an outer class? A (non-local) inner class may be declared as public, protected, private, static, final, or abstract.
--------------------------------------------------------------------------------
If a method is declared as protected, where may the method be accessed? 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.
--------------------------------------------------------------------------------
What is an Iterator interface? The Iterator interface is used to step through the elements of a Collection.
--------------------------------------------------------------------------------
How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters? 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.
--------------------------------------------------------------------------------
What is the difference between yielding and sleeping? 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.
--------------------------------------------------------------------------------
Is sizeof a keyword? The sizeof operator is not a keyword.
--------------------------------------------------------------------------------
What are wrapped classes? Wrapped classes are classes that allow primitive types to be accessed as objects.
--------------------------------------------------------------------------------
Does garbage collection guarantee that a program will not run out of memory? 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
--------------------------------------------------------------------------------
What is the difference between preemptive scheduling and time slicing? Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors.
--------------------------------------------------------------------------------
Name Component subclasses that support painting. The Canvas, Frame, Panel, and Applet classes support painting.
--------------------------------------------------------------------------------
What is a native method? A native method is a method that is implemented in a language other than Java.
--------------------------------------------------------------------------------
How can you write a loop indefinitely? for(;;)--for loop; while(true)--always true, etc.
--------------------------------------------------------------------------------
Can an anonymous class be declared as implementing an interface and extending a class? An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.
--------------------------------------------------------------------------------
What is the purpose of finalization? The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.
--------------------------------------------------------------------------------
Which class is the superclass for every class. Object
--------------------------------------------------------------------------------
What is the difference between the Boolean & operator and the && operator? 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.
--------------------------------------------------------------------------------
What is the GregorianCalendar class? The GregorianCalendar provides support for traditional Western calendars.
--------------------------------------------------------------------------------
What is the SimpleTimeZone class? The SimpleTimeZone class provides support for a Gregorian calendar.
--------------------------------------------------------------------------------
Which Container method is used to cause a container to be laid out and redisplayed? validate()
--------------------------------------------------------------------------------
What is the Properties class? 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.
--------------------------------------------------------------------------------
What is the purpose of the Runtime class? The purpose of the Runtime class is to provide access to the Java runtime system.
--------------------------------------------------------------------------------
What is the purpose of the System class? The purpose of the System class is to provide access to system resources.
--------------------------------------------------------------------------------
What is the purpose of the finally clause of a try-catch-finally statement? The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught.
--------------------------------------------------------------------------------
What is the Locale class? The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region.
--------------------------------------------------------------------------------
What must a class do to implement an interface? It must provide all of the methods in the interface and identify the interface in its implements clause.
--------------------------------------------------------------------------------
What is an abstract method? 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).
--------------------------------------------------------------------------------
What is a static method? 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.
--------------------------------------------------------------------------------
What is a protected method? A protected method is a method that can be accessed by any method in its package and inherited by any subclass of its class.
--------------------------------------------------------------------------------
What is the difference between a static and a non-static inner class? 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.
--------------------------------------------------------------------------------
What is an object's lock and which object's have locks? 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.
--------------------------------------------------------------------------------
When can an object reference be cast to an interface reference? An object reference be cast to an interface reference when the object implements the referenced interface.
--------------------------------------------------------------------------------
What is the difference between a Window and a Frame? The Frame class extends Window to define a main application window that can have a menu bar.
--------------------------------------------------------------------------------
What do heavy weight components mean? Heavy weight components like Abstract Window Toolkit (AWT), depend on the local windowing toolkit. For example, java.awt.Button is a heavy weight component, when it is running on the Java platform for Unix platform, it maps to a real Motif button. In this relationship, the Motif button is called the peer to the java.awt.Button. If you create two Buttons, two peers and hence two Motif Buttons are also created. The Java platform communicates with the Motif Buttons using the Java Native Interface. For each and every component added to the application, there is an additional overhead tied to the local windowing system, which is why these components are called heavy weight.
--------------------------------------------------------------------------------
Which package has light weight components? javax.Swing package. All components in Swing, except JApplet, JDialog, JFrame and JWindow are lightweight components.
--------------------------------------------------------------------------------
What are peerless components? The peerless components are called light weight components.
--------------------------------------------------------------------------------
What is the difference between the Font and FontMetrics classes? The FontMetrics class is used to define implementation-specific properties, such as ascent and descent, of a Font object.
--------------------------------------------------------------------------------
What happens when a thread cannot acquire a lock on an object? 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.
--------------------------------------------------------------------------------
What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy? The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.
--------------------------------------------------------------------------------
What classes of exceptions may be caught by a catch clause? A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types.
--------------------------------------------------------------------------------
What is the difference between throw and throws keywords? 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.
--------------------------------------------------------------------------------
If a class is declared without any access modifiers, where may the class be accessed? 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.
--------------------------------------------------------------------------------
What is the Map interface? The Map interface replaces the JDK 1.1 Dictionary class and is used associate keys with values.
--------------------------------------------------------------------------------
Does a class inherit the constructors of its superclass? A class does not inherit constructors from any of its superclasses.
--------------------------------------------------------------------------------
Name primitive Java types. The primitive types are byte, char, short, int, long, float, double, and boolean.
--------------------------------------------------------------------------------
Which class should you use to obtain design information about an object? The Class class is used to obtain information about an object's design.
--------------------------------------------------------------------------------
How can a GUI component handle its own events? A component can handle its own events by implementing the required event-listener interface and adding itself as its own event listener.
--------------------------------------------------------------------------------
How are the elements of a GridBagLayout organized? The elements of a GridBagLayout are organized according to a grid. However, the elements are of different sizes and may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes.
--------------------------------------------------------------------------------
What advantage do Java's layout managers provide over traditional windowing systems? Java uses layout managers to lay out components in a consistent manner across all windowing platforms. Since Java's layout managers aren't tied to absolute sizing and positioning, they are able to accommodate platform-specific differences among windowing systems.
--------------------------------------------------------------------------------
What are the problems faced by Java programmers who don't use layout managers? 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.
--------------------------------------------------------------------------------
What is the difference between static and non-static variables? 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.
--------------------------------------------------------------------------------
What is the difference between the paint() and repaint() methods? 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.
--------------------------------------------------------------------------------
What is the purpose of the File class? The File class is used to create objects that provide access to the files and directories of a local file system.
--------------------------------------------------------------------------------
What restrictions are placed on method overloading? Two methods may not have the same name and argument list but different return types.
--------------------------------------------------------------------------------
What restrictions are placed on method overriding? 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.
--------------------------------------------------------------------------------
What is casting? 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.
--------------------------------------------------------------------------------
Name Container classes. Window, Frame, Dialog, FileDialog, Panel, Applet, or ScrollPane
--------------------------------------------------------------------------------
What class allows you to read objects directly from a stream? The ObjectInputStream class supports the reading of objects from input streams.
--------------------------------------------------------------------------------
How are this() and super() used with constructors? this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.
--------------------------------------------------------------------------------
How is it possible for two String objects with identical values not to be equal under the == operator? 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.
--------------------------------------------------------------------------------
What an I/O filter? An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.
--------------------------------------------------------------------------------
What is the Set interface? The Set interface provides methods for accessing the elements of a finite mathematical set. Sets do not allow duplicate elements.
--------------------------------------------------------------------------------
What is the List interface? The List interface provides support for ordered collections of objects.
--------------------------------------------------------------------------------
What is the purpose of the enableEvents() method? The enableEvents() method is used to enable an event for a particular object. Normally, an event is enabled when a listener is added to an object for a particular event. The enableEvents() method is used by objects that handle events by overriding their event-dispatch methods.
--------------------------------------------------------------------------------
What is the difference between the File and RandomAccessFile classes? The File class encapsulates the files and directories of the local file system. The RandomAccessFile class provides the methods needed to directly access data contained in any part of a file.
--------------------------------------------------------------------------------
What interface must an object implement before it can be written to a stream as an object? An object must implement the Serializable or Externalizable interface before it can be written to a stream as an object.
--------------------------------------------------------------------------------
What is the ResourceBundle class? 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.
--------------------------------------------------------------------------------
What is the difference between a Scrollbar and a ScrollPane? 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.
--------------------------------------------------------------------------------
What is a Java package and how is it used? A Java package is a naming context for classes and interfaces. A package is used to create a separate name space for groups of classes and interfaces. Packages are also used to organize related classes and interfaces into a single API unit and to control accessibility to these classes and interfaces.
--------------------------------------------------------------------------------
What are the Object and Class classes used for? The Object class is the highest-level class in the Java class hierarchy. The Class class is used to represent the classes and interfac