• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/163

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

163 Cards in this Set

  • Front
  • Back
What is the difference between procedural and object-oriented programs?-
Procedural Program -

programming logic follows certain procedures and instructions are executed one after another, and data is exposed to the whole program.

Object Oriented Programming -

Object-oriented programming (OOP) is a organized around objects rather than "actions" and data rather than logic

An object is a unit of program, and data is accessible within the object and which in turn assures the security of the code.
What is Encapsulation?
Definition 1:
• encapsulation is the ability to package data, that have related behaviors in an object bundle, while controlling/restricting access to them (both data and function) from other objects

Definition 2:

• is a concept which enforces protecting variables, and functions from outside of a class, in order to better manage that piece of code, so that it has the least amount of impact or no impact at all on other parts of program due to change in the protected code.
What is Inheritance?
• Inheritance is the process by which one object acquires the properties of another object.
What is Polymorphism?
• Polymorphism is the feature that allows one interface to be used for generalized Class actions.
What is the difference between Assignment and Initialization?-


What is an Instance variable?
• Assignment can be done as many times as desired
• Initialization can be done only once.

Instance variable is the variable declared inside a class, but outside a method:
What is OOPs?
Object oriented programming organizes a program around its data,

i. e. , objects and a set of well defined interfaces to that data.

An object-oriented program can be characterized as data controlling access to code.
What is a Class
Class -

is a template for multiple objects with similar features and it is a blue print for objects. It defines a type of object according to the data the object can hold and the operations the object can perform.
What is a Constructor?
Constructor -

is a special kind of method that determines how an object is initialized when created.
What is are the Primitive data types?
Primitive data -

types are 8 types and they are:

byte, short, int, long,
float, double, boolean, char.
What is an Object and how do you allocate memory to it?-
• Object is an instance of a class and is a software unit that combines a structured set of data with a set of operations for inspecting and manipulating that data.

• When an object is created using new operator, memory is allocated to it.
What is the difference between constructor and method?
• Constructor is automatically invoked when an object is created

• Method has to be called explicitly.
What are methods?
Methods are functions that operate on instances of the classes where they are defined.

Objects can communicate with each other using methods and can call methods in other classes.
how are methods defined?
Method definition has four parts. They are

1. name of the method

2. type of object or primitive type the method returns,

3. list of parameters

4. the body of the method.

A method’s signature is a combination of the first three parts mentioned above.
What is the use of bin and lib in JDK?-
• Bin contains all Java tools and utilities such as , appletviewer, awt tool, etc.,

• Lib contains the API and all packages.
What is casting?
Casting is used to convert a value of one type to another.
How many ways can an argument be passed to a subroutine and explain them?
An argument can be passed in two ways. They are passing by value and passing by reference.

• Passing by value: This method copies the value of an argument into the formal parameter of the subroutine.

• Passing by reference: In this method, a reference to an argument (not the value of the argument) is passed to the parameter.
What is the difference between an argument and a parameter?
• While defining method, variables passed in the method are called Parameters.

• While using those methods, values passed to those variables are called Arguments.
What are different types of access modifiers?
• public: Anything declared as public can be accessed from anywhere.

• private: Anything declared as private can’t be seen outside of its class.

• protected: Anything declared as protected can be accessed by classes in the same package, and subclasses in the other packages.

• default modifier : Can be accessed only to classes in the same package.
14. What is final?
• final is a keyword can be used for class, method and variables.

• A final class cannot be subclassed and it prevents other programmers from subclassing a secure class to invoke insecure methods.

• A final method can’t be overridden.

• A final variable can’t change from its initialized value.
What is finalize() ?
finalize() method

is used just before an object is destroyed and can be called just prior to garbage collection.

• the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded
What is finally?
finally, is a key word used in exception handling,

block of code is created that will be executed after a try/catch block has completed, and before the code following the try/catch block.

The finally block will execute whether or not an exception is thrown.
What is UNICODE
Unicode is used for internal representation of characters and strings, and it uses 16 bits to represent each other.
What is Garbage Collection and how to call it explicitly?
When an object is no longer referred to by any variable, java automatically reclaims memory used by that object. This is known as garbage collection

System. gc() method may be used to call it explicitly.
What is finalize() method?
finalize () method is used just before an object is destroyed and can be called just prior to garbage collection.
What is a Transient Modifiers?-
Transient:

The transient modifier applies only to variables, and they are not stored as part of its object’s Persistent state.

Transient variables are not serialized.
What is a Volatile Modifiers
Volatile:

Volatile modifier applies only to variables and it tells the compiler that the variable modified can be changed unexpectedly by other parts of the program
What is method overloading?
Method overloading:

When a method in a class has the same method name, but with with different arguments is said to be method overloading.
What is method overriding?
Method overriding :

When a method in a class has the same method name , and the same arguments is said to be method overriding.
What is difference between overloading and overriding?
a)
• Overloading, there is a relationship between methods available in the same class

• Overriding, there is relationship between a superclass method and subclass method.
b)
• Overloading does not block inheritance from the superclass

• Overriding blocks inheritance from the superclass.
c)
• Overloading, separates the methods that share the same name
• Overriding, subclass method replaces the superclass.
d)
• Overloading must have different method signatures
• Overriding must have same signature.
What is meant by Inheritance and what are its advantages?
• Inheritance is the process of inheriting all the features from a class.

• The advantages of inheritance are reusability of code and accessibility of variables and methods of the super class by subclasses.
What is the difference between this() and super()?
• this() can be used to invoke a constructor of the same class

• super() can be used to invoke a super class constructor.
What is the difference between superclass and subclass?
• Super class : is a class that is inherited

• Sub class : is a class that does the inheriting.
What modifiers may be used with top-level class?
1. Public
2. abstract
3. final
What is an inner class?
• They are Classes that are defined in other classes, including those defined in methods are called inner classes.
They can have any accessibility modifiers including private.
What is an Anonymous class ?
• Anonymous class is a class defined inside a method without a name.

It is instantiated and declared in the same place and cannot have EXPLICIT CONSTRUCTORS.
What is a package?
It is a collection of classes and interfaces that provides a high-level layer of access protection and name space management.
What is a reflection package?
java. lang. reflect package has the ability to analyze itself in runtime.
What is interface and its use?
Interface is similar to a class, but can only contain method’s signature only, not the methods bodies

• it is a formal set of method and constant declarations that must be defined by the class that implements it.

Interfaces are useful for:

a) Declaring methods that one or more classes are expected to implement

b) Capturing similarities between unrelated classes without forcing a class relationship.

c) Determining an object’s programming interface without revealing the actual body of the class.
What is an abstract class?
is a class designed with implementation gaps for subclasses to fill in

• It is deliberately left incomplete.
What is the difference between Integer and int?
a)
• Integer is a class defined in the java. lang package,

• int is a primitive data type defined in the Java language itself. Java does not automatically convert from one to the other.

b)
Integer is a class defined in the java. lang package,

• Integer can be used as an argument for a method that requires an object

• int can be used for calculations.
What is a cloneable interface and how many methods does it contain?
It is not having any method because it is a TAGGED or MARKER interface.
What is the difference between abstract class and interface?
a)
• All the methods declared inside an interface are abstract

• Abstract class must have at least one abstract method and others may be concrete or abstract.

b)
• In abstract class, the key word abstract must be used for the methods

• Interface does not need the use the keyword for the methods.

c)
• Abstract class must have subclasses
• whereas interface can’t have subclasses.
Can you have an inner class inside a method and what variables can you access?
Yes, we can have an inner class inside a method, and final variables can be accessed.
What is the difference between String and String Buffer?
a)
• String objects are constants and are immutable
• StringBuffer objects are not.

b)
• String class supports constant strings

• StringBuffer class supports growable and modifiable strings.
What is the difference between Array and vector?
Array ==> is a set of related data type and is static
Vector ==> is a growable array of objects and is dynamic.
What is the difference between exception and error?
• The EXCEPTION class

defines mild error conditions that your program encounters.

Exceptions can occur when trying to open the file, which does not exist, the network connection is disrupted, operands being manipulated are out of prescribed ranges, the class file you are interested in loading is missing.

• The ERROR class

defines serious error conditions that you should not attempt to recover from. In most cases it is advisable to let the program terminate when such an error is encountered.
What is the difference between process and thread?
• Process is a program in execution

• Thread is a separate path of execution in a program.
What is multithreading and what are the methods for inter-thread communication and what is the class in which these methods are defined?
• Multithreading is the mechanism iwhere more than one thread run independent of each other within the process.

• wait (), notify () and notifyAll () methods can be used for inter-thread communication and these methods are in Object class.

• wait() : When a thread executes a call to wait() method, it surrenders the object lock and enters into a waiting state.

• notify() or notifyAll() : To remove a thread from the waiting state, some other thread must make a call to notify() or notifyAll() method on the same object.
What is the class and interface in java to create thread and which is the most advantageous method?
• Thread class and Runnable interface can be used to create threads

• Runnable interface is the most advantageous method to create threads because there is no need to extend thread class here.
What are the states associated in the thread?
Thread contains

1. Ready
2. Running
3. Waiting
4. Dead states.
What is synchronization?
Synchronization:

is the mechanism that ensures that only one thread is accessing the resources at one time.
When will you need to synchronize a piece of your code?
you synchronize your code when you will expect it to be accessed by different threads.

The reason is that other these threads may change a particular piece of data causing data corruption.
What is deadlock?
When two threads are waiting on each other and can’t precede, the program is said to be deadlock.
What is daemon thread and which method is used to create the daemon thread?
Daemon thread is a low priority thread which runs
periodically in the back ground doing the garbage collection operations for the java runtime system.

• setDaemon method is used to create a daemon thread.
Are there any global variables in Java, which can be accessed by other part of your program?
• No, it is not the main method in which you define variables.

• Global variables are not possible because concept of encapsulation would be eliminated here.

Answer: 2

A:
Global variables are globally accessible. Java does not support globally accessible variables due to following reasons:

The global variables breaks the referential transparency

Global variables create collisions in namespace.
What is an applet?
Applet is a dynamic , interactive program that runs inside a web page, and is displayed by a java capable browser.
What is the difference between applications and applets?
a)
• Application must be run on local machine

• Applet needs no explicit installation on local machine.
b)
• Applications must be run explicitly within a java-compatible virtual machine
• Applets loads and runs itself automatically in a java-enabled browser.
d)
• Applications starts execution with its main method

• Applets starts execution with its init method.
e)
• Applications can run with or without graphical user interface

• Applet must run within a graphical user interface.
How does applet recognize the height and width?
By using the getParameters() method.
When do you use codebase in applet?
When the applets class file is not located in the same directory, codebase is used.
What is the lifecycle of an applet?
1. init() method - Can be called when an applet is first loaded

2. start() method- Can be called each time an applet is started.

3. paint() method - Can be called when the applet is minimized or maximized.

3. stop() method - Can be used when the browser moves off the applet’s page.

4. destroy() method - Can be called when the browser is finished with the applet.
How do you set security in applets?-
By using setSecurityManager() method
What is an event and what are the models available for event handling?
An event is an event object that describes a state of change in a source.

In other words, event occurs when an action is generated such as, l pressing button, clicking mouse, selecting a list, etc.

There are two types of models for handling events and they are:

1. event-inheritance model
2. event-delegation model
What are the advantages of the event-delegation model over the event-inheritance model?
The event-delegation model has two advantages over the event-inheritance model. They are:

1. It enables event handling by objects other than the ones that generate the events.

• This allows a clean separation between a component’s design and its use.

2. It performs much better in applications where many events are generated.

• This performance improvement is due to the fact that the event-delegation model does not have to be repeatedly process unhandled events as is the case of the event-inheritance.
What is source and listener?
source :

A source is an object that generates an event. This occurs when the internal state of that object changes in some way.

listener:

is an object that is notified when an event occurs.

It has two major requirements.

First, it must have been registered with one or more sources to receive notifications about specific types of events.

Second, it must implement methods to receive and process these notifications.
What is adapter class?
An adapter class provides an empty implementation of all methods in an event listener interface.

• Adapter classes are useful when you want to receive and process only some of the events that are handled by a particular event listener interface.

• You can define a new class to act listener by extending one of the adapter classes and implementing only those events in which you are interested.
What is meant by controls and what are different types of controls in AWT?
Controls:

Are components that allow a user to interact with your application.

• AWT supports the following types of controls:

Examples: Labels, Push Buttons, Check Boxes, Choice Lists, Lists, Scrollbars, Text Components.

These controls are subclasses of Component
What is the difference between choice and list?
• Choice is displayed in a compact form that requires you to pull it down to see the list of available choices and only one item may be selected from a choice.

• List may be displayed in such a way that several list items are visible and it supports the selection of one or more list items.
What is the difference between scrollbar and scrollpane?
• Scrollbar is a Component, but not a Container

• Scrollpane is a Container, that handles its own events, and performs its own scrolling.
What is a layout manager and what are different types of layout managers available in java AWT?
A layout manager is an object that is used to organize components in a container.

The different layouts are available

1. FlowLayout
2. BorderLayout
3. CardLayout
4. GridLayout
5. GridBagLayout.
How are the elements of different layouts organized?
FlowLayout: The elements of a FlowLayout are organized in a top to bottom, left to right fashion.

BorderLayout: The elements of a BorderLayout are organized at the borders (North, South, East and West) and the center of a container.

CardLayout: The elements of a CardLayout are stacked, on top of the other, like a deck of cards.

GridLayout: The elements of a GridLayout are of equal size and are laid out using the square of a grid.

GridBagLayout: The elements of a GridBagLayout are organized according to a grid.

However, the elements are of different size and may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes.
Which containers use a Border layout as their default layout?
1. Window
2. Frame
3. Dialog

Classes use a BorderLayout as their layout.
Which containers use a Flow layout as their default layout?
1. Panel
2. Applet

Classes use the FlowLayout as their default layout.
What are wrapper classes?
Wrapper classes are classes that allow primitive types to be accessed as objects.
64. What are Vectors?
Vector:

The Vector class provides the capability to implement a growable array of objects.
What is a Hashtable?
Hashtable :

The Hashtable class implements a Hashtable data structure.
• A Hashtable indexes and stores objects in a dictionary using hash codes as the object’s keys.

Hash codes are integer values that identify objects.
What is a LinkedList?
LinkedList:

Removing or inserting elements in the middle of an array can be done using LinkedList class.

• A LinkedList stores each object in a separate link.

• whereas an array stores object references in consecutive locations.
What is Enumeration?
Enumeration:

The Enumeration interface generates a series of elements, one at a time.

It has two methods, namely

• hasMoreElements()
• and nextElement().

HasMoreElemnts() tests if this enumeration has more elements and nextElement method returns successive elements of the series.
What is the difference between set and list?
• A Set stores elements in an unordered way, and does not contain duplicate elements,

• A List stores elements in an ordered way but may contain duplicate elements.
What is a stream and what are the types of Streams and classes of the Streams?
A Stream is an abstraction that either produces or consumes information.

There are two types of Streams and they are Byte Streams and Character Streams

Byte Streams: Provide a convenient means for handling input and output of bytes.

Character Streams: Provide a convenient means for handling input & output of characters.

Byte Streams classes:

Are defined by using two abstract classes, namely InputStream and OutputStream.

Character Streams classes:

Are defined by using two abstract classes, namely Reader and Writer.
What is the difference between Reader/Writer and InputStream/Output Stream?
• The Reader/Writer class is character-oriented

• InputStream/OutputStream class is byte-oriented.
What is 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 serialization and deserialization?
these objects.
• Serialization is the process of writing the state of an object to a byte stream.

• Deserialization is the process of restoring stream of bytes back into a copy of the original object.
What is JDBC?
JDBC is a set of Java API for executing SQL statements.

This API consists of a set of classes and interfaces to enable programs to write pure Java Database applications.
What are drivers available?
a) JDBC-ODBC Bridge driver
b) Native API Partly-Java driver
c) JDBC-Net Pure Java driver
d) Native-Protocol Pure Java driver
What is the difference between JDBC and ODBC?
a) OBDC is for Microsoft and JDBC is for Java applications.

b) ODBC can’t be directly used with Java because it uses a C interface.

c) ODBC makes use of pointers which have been removed totally from Java.

d) ODBC mixes simple and advanced features together and has complex options for simple queries.

JDBC is designed to keep things simple while allowing advanced capabilities when required.

e) ODBC requires manual installation of the ODBC driver manager and driver on all client machines.
JDBC drivers are written in Java and JDBC code is automatically installable, secure, and portable on all platforms.

f) JDBC API is a natural Java interface and is built on ODBC. JDBC retains some of the basic features of ODBC.
What are the types of JDBC Driver Models and explain them?
There are two types of JDBC Driver Models and they are:

1. Two tier model
2. Three tier model

Two tier model: In this model, Java applications interact directly with the database. A JDBC driver is required to communicate with the particular database management system that is being accessed. SQL statements are sent to the database and the results are given to user.
This model is referred to as client/server configuration where user is the client and the machine that has the database is called as the server.

Three tier model: A middle tier is introduced in this model. The functions of this model are:

a) Collection of SQL statements from the client and handing it over to the database,

b) Receiving results from database to the client

c) Maintaining control over accessing and updating of the above
What type of driver did you use in project?
JDBC-ODBC Bridge driver (is a driver that uses native(C language) libraries and makes calls to an existing ODBC driver to access a database engine).
What are the types of statements in JDBC?
Statement: to be used createStatement() method for executing single SQL statement

PreparedStatement — To be used

preparedStatement() method for executing same SQL statement over and over.

CallableStatement — To be used prepareCall() method for multiple SQL statements over and over.
What is a stored procedure?
• Stored procedure is a group of SQL statements that forms a logical unit and performs a particular task.

• Stored Procedures are used to encapsulate a set of operations or queries to execute on database.
• Stored procedures can be compiled and executed with different parameters and results and may have any combination of input/output parameters.
78. How to create and call stored procedures?
SEE FOLDER
What is servlet?
Servlet's are modules that extend request/response-oriented servers,

such as java-enabled web servers.

• For example, a servlet might be responsible for taking data in an HTML order-entry form and applying the business logic used to update a company’s order database.
What are the classes and interfaces for servlets?
There are two packages in servlets and they are:

1. Java. servlet and
What is the difference between an applet and a servlet?
a) Servlet's-- are to servers what applets are to browsers.

• servlet's have no graphical user interfaces.

b)
• Applets must have graphical user interfaces
What is the difference between doPost and doGet methods?
a) doGet () method is used to get information,

doPost() method is used for posting information.

b) doGet() requests can’t send large amount of information and is limited to 240-255 characters.

doPost () requests passes all of its data, of unlimited length.

c) A doGet() request is appended to the request URL in a query string and this allows the exchange is visible to the client,

a doPost() request passes directly over the socket connection as part of its HTTP request body and the exchange are invisible to the client.
What is the life cycle of a servlet?
Each Servlet has the same life cycle:

a) A server loads and initializes the servlet by init () method.

b) The servlet handles zero or more client’s requests through service() method.

c) The server removes the servlet through destroy() method.
Who is loading the init() method of servlet?
Web server
What are the different servers available for developing and deploying Servlet's?
a. Java Web Server
b. JRun
c. Apache Server
d. Netscape Information Server
e. Web Logic
How many ways can we track client and what are they?
The servlet API provides two ways to track client state and they are:
1. Using Session tracking
2. Using Cookies.
88. What is Server-Side Includes (SSI)?
Server-Side Includes allowing embedding servlets within HTML pages using a special servlet tag.

In many servlets that support servlets, a page can be processed by the server to include output from servlets at certain points inside the HTML page.
89. What are cookies and how will you use them?
Cookies are a mechanisms that a servlet uses to have a client hold a small amount of state-information associated with the user.

a) To Create a cookie with the Cookie constructor:
public Cookie(String name, String value)

b) A servlet can send a cookie to the client by passing a Cookie object to the addCookie() method of HttpServletResponse: public void HttpServletResponse. addCookie(Cookie cookie)

c) A servlet retrieves cookies by calling the getCookies() method of HttpServletRequest: public Cookie[ ] HttpServletRequest. getCookie().
Is it possible to communicate from an applet to servlet and how many ways and how?
Yes, there are three ways to communicate from an applet to servlet and they are:

1. HTTP Communication(Text-based and object-based)

2. Socket Communication

3. RMI Communication
91. What is connection pooling?
with connection pool, we can duplicate only the resources we need to duplicate rather than the entire servlet.

A connection pool can also intelligently manage the size of the pool and make sure each connection remains v
92. Why should we go for interservlet communication?
Servlet's running together in the same server communicate with each other in several ways. The three major reasons to use interservlet communication are:

a) Direct servlet manipulation -

allows gaining access to the other currently loaded servlet's and performing 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)
Is it possible to call servlet with parameters in the URL?
Yes. You can call a servlet with parameters in the syntax as (?Param1 = xxx || m2 = yyy).
What is Servlet chaining?
Servlet chaining is a technique in which two or more servlets can cooperate in servicing a single request.

In servlet chaining, one servlet’s output is piped to the next servlet’s input. This process continues until the last servlet is reached. Its output is then sent back to the client.
How do servlets handle multiple simultaneous requests?
• The server has multiple threads that are available to handle requests. When a request comes in, it is assigned to a thread, which calls a service method
• (for example: doGet(), doPost() and service()) of the servlet.)
• For this reason, a single servlet object can have its service methods called by many threads at once.
What is the difference between TCP/IP and UDP?-
• TCP/IP

is a two-way communication between the client and the server and it is a reliable and there is a confirmation regarding reaching the message to the destination. It is like a phone call.

• UDP
is a one-way communication only between the client and the server and it is not a reliable and there is no confirmation regarding reaching the message to the destination. It is like a postal mail.
What is Inet address?
Every computer connected to a network has an IP address.

• An IP address is a number that uniquely identifies each computer on the Net.
• An IP address is a 32-bit number.
98. What is Domain Naming Service (DNS)?
It is very difficult to remember a set of numbers(IP address) to connect to the Internet.

The Domain Naming Service(DNS) is used to overcome this problem.
• It maps one particular IP address to a string of characters.
For example, www. mascom. com
implies com is the domain name reserved for US commercial sites,
mascom is the name of the company
and www is the name of the specific computer, which is mascom’s server.
What is URL?
URL stands for Uniform Resource Locator and it points to resource files on the Internet.

URL has four components:

http://www. address. com:80/index.html,
1. http - protocol name, address -
2. IP address or host name, 80 -
3. port number and index.html -
4. file path.
What is RMI and steps involved in developing an RMI object?
Remote Method Invocation (RMI)

allows java object that executes on one machine and to invoke the method of a Java object to execute on another machine.

The steps involved in developing an RMI object are:

a) Define the interfaces

b) Implementing these interfaces

c) Compile the interfaces and their implementations with the java compiler

d) Compile the server implementation with RMI compiler

e) Run the RMI registry

f) Run the application
What is RMI architecture?
RMI architecture consists of four layers and each layer performs specific functions:

1. Application layer - contains the actual object definition.

2. Proxy layer - consists of stub and skeleton.

3. Remote Reference layer - gets the stream of bytes from the transport layer and sends it to the proxy layer.

4. Transportation layer - responsible for handling the actual machine-to- machine communication.
What is a Java Bean?
A Java Bean is a software component that has been designed to be reusable in a variety of different environments.
What is a Jar file?
Jar file allows the deploying of a set of classes and their associated resources efficiently.

The elements in a jar file are compressed,

This makes downloading a Jar file much faster than separately downloading several uncompressed files.

The package java. util. zip contains classes that read and write jar files.
What is JSP?
Java Server Page (JSP)

JSP is a dynamic scripting capability for web pages that allows Java as well as a few special tags to be embedded into a web file (HTML/XML, etc).

The suffix traditionally ends with .jsp to indicate to the web server that the file is a JSP files. JSP is a server side technology - you can’t do any client side validation with it.
The advantages are:

1. The JSP assists in making the HTML more functional.
Servlets on the other hand allow outputting of HTML but it is a tedious process.

2. It is easy to make a change and then let the JSP capability of the web server you are using deal with compiling it into a servlet and running it.
What is HashMap and Map?
A Map is Interface

and Hashmap is the class that implements the map interface.
Difference between a HashMap and HashTable?
The HashMap class is roughly equivalent to Hashtable class except that it is unsynchronized and permits nulls.

(A HashMap allows null values as key and value whereas Hashtable doesnt allow).

HashMap does not guarantee that the order of the map will remain constant over time, and is unsynchronized

A Hashtable is synchronized.
Difference between Vector and ArrayList?
Vector is synchronized

arraylist is not synchronized
Difference between Swing and Awt?
AWT are heavy-weight componenets.

Swings are light-weight components.

* Hence swing works faster than AWT.
What is an Iterator?
Some of the collection classes provide traversal of their contents via a java.util.Iterator interface.

This interface allows you to walk through a collection of objects, operating on each object in turn.

**Remember when using Iterators that they contain a snapshot of the collection at the time the Iterator was obtained;

* generally it is not advisable to modify the collection itself while traversing an Iterator.
What is static in java?
Static means one per class, not one for each object

no matter how many instance of a class might exist.

This means that you can use static objects/variables without creating an instance of a class.

Static methods are implicitly final, because overriding is done based on the type of the object, and static methods are attached to a class, not an object.

A static method in a superclass can be shadowed by another static method in a subclass, as long as the original method was not declared final.

**However, you can't override a static method with a nonstatic method. In other words, you can't change a static method into an instance method in a subclass
What if the main method is declared as private?
The program will compile properly, but at runtime it will give
** “Main method not public.” message. **
If you’re overriding the method equals() of an object, which other method you might also consider?
hashCode()
Q: What is Byte Code?

Or

Q: What gives java it’s “write once and run anywhere” nature?
All Java programs are compiled into class files that contain bytecodes.

These byte codes can be run in any platform and that is the reason java is said to be platform independent.
Expain the reason for each keyword of public static void main(String args[])?
: public – main(..) is the first method called by java environment when a program is executed, so it has to accessible from java environment.

That is why the access specifier has to be public.

static : The Java environment should be able to call this method without creating an instance of the class , so this method must be declared as static.

void : main does not return anything so the return type must be void

The argument String indicates the argument type which is given at the command line

args [ ] is an array for string given during command line.
Q: What are the differences between == and .equals() ?

Or
Q: what is difference between == and equals

Or
Q: Difference between == and equals method

Or
Q: What would you use to compare two String variables – the operator == or the method equals()?

Or
Q: 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.

i.e. present in the same memory location. It is possible for two String objects to have the same value, but located in different areas of memory.

== compares references, while .equals compares contents.

The method public boolean equals(Object obj) is provided by the Object class and can be overridden.

The default implementation returns true only if the object is compared with itself, which is equivalent to the equality operator == being used to compare aliases to the object. String, BitSet, Date, and File override the equals() method. For two String objects, value equality means that they contain the same character sequence.

For the Wrapper classes, value equality means that the primitive values are equal
Q: What if the static modifier is removed from the signature of the main method?

Or
Q: What if I do not provide the String array as the argument to the method?
Program compiles, but at runtime it will throws an error “NoSuchMethodError”.
Q: 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 GregorianCalendar class?
The GregorianCalendar provides support for traditional Western calendars.
How to convert String to Number in java program?
The valueOf() function of Integer class is is used to convert string to Number.

Here is the code example:

1 String numString = “1000″;
2 int id=Integer.valueOf(numString).intValue();
What is the SimpleTimeZone class?
The SimpleTimeZone class provides support for a Gregorian calendar.
What is the difference between a while statement and a do statement?
A while statement (pre test) checks at the beginning of a loop to see whether the next loop iteration should occur.

A do while statement (post test) checks at the end of a loop to see whether the next iteration of a loop should occur.

** The do statement will always execute the loop body at least once. **
What is implicit casting?
Implicit casting is the process of simply assigning one entity to another without any transformation guidance to the compiler.

This type of casting is not permitted in all kinds of transformations and may not work for all scenarios.

Example
view source
print?

1 int i = 1000;
2 long j = i; //Implicit casting
Is sizeof a keyword in java?
No the sizeof is not a keyword.
What is a native method?
A native method is a method that is implemented in a language other than Java.
In System.out.println(), what is System, out and println?
System is a predefined final class,

out is a PrintStream object

println is a built-in overloaded method in the out object.
Explain the different forms of Polymorphism.
Polymorphism exists in three distinct forms in Java:

Method overloading
Method overriding through inheritance
Method overriding through the Java interface
Q: What is explicit casting?
A:
Explicit casting in the process in which the complier are specifically informed to about transforming the object.

Example
1 long i = 700.20;
2 int j = (int) i; //Explicit casting
What is the Java Virtual Machine (JVM)?
A:
The Java Virtual Machine is software that can be ported onto various hardware-based platforms
Q: What do you understand by downcasting?
A:
The process of Downcasting refers to the casting from a general to a more specific type.

i.e. casting down the hierarchy
Q: Which class is the superclass of every class?
A:
Object.
Q. What are “class variables”?

or

Q. What is static in java?
A static variable is associated with the class as a whole, rather than with specific instances of a class.

Each object will share a common copy of the static variables i.e. there is only one copy per class, no matter how many objects are created from it.

Class variables or static variables are declared with the static keyword in a class. These are declared outside a class and stored in static memory.

Class variables are mostly used for constants.

Static variables are always called by the class name. This variable is created when the program starts and gets destroyed when the programs stops.



The scope of the class variable is same an instance variable. Its initial value is same as instance variable and gets a default value when it’s not initialized corresponding to the data type.

Similarly, 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
Q: What is a static method?

or

Q: What is the difference between static and non-static variables?
Static methods are implicitly final, because overriding is done based on the type of the object, and static methods are attached to a class, not an object.

A static method in a superclass can be shadowed by another static method in a subclass, as long as the original method was not declared final.

**However, you can’t override a static method with a non-static method. In other words, you can’t change a static method into an instance method in a subclass.

Non-static variables take on unique values with each object instance.
Q: What is the difference between the Boolean & operator and the && operator?
A:
If an expression involving the boolean & operator is evaluated, both operands are evaluated,

whereas the && operator is a short cut operator. 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.

If the first operand evaluates to false, the evaluation of the second operand is skipped.
Q: What if I write static public void instead of public static void?
A:
Program compiles and runs properly.
Q: What is the difference between declaring a variable and defining a variable?
A:
In declaration we only mention the type of the variable and its name without initializing it.

Defining means declaration + initialization.

E.g. String s; is just a declaration while String s = new String (”bob”); Or String s = “bob”; are both definitions.
What are the types of casting?
implicit casting and explicit casting
What is the first argument of the String array in main method?
A:
The String array is empty. It does not have any element.

This is unlike C/C++ where the first element by default is the program name. If we do not provide any arguments on the command line, then the String array of main method will be empty but not null.
Q: How can one prove that the array is not null but empty?
A:
Print array.length. It will print 0. That means it is empty. But if it would have been null then it would have thrown a NullPointerException on attempting to print array.length.
Can an application have multiple classes having main method?
A:
Yes. While starting the application we mention the class name to be run.

The JVM will look for the main method only in the class whose name you have mentioned. Hence there is not conflict amongst the multiple classes having main method.
Q: When is static variable loaded? Is it at compile time or runtime?
A:
Static variable are loaded when classloader brings the class to the JVM. It is not necessary that an object has to be created.

They are loaded at runtime.
Static variables will be allocated memory space when they have been loaded. class is first initialized. A class can have any number of static blocks.
When exactly a static block is loaded in Java?
The code in a static block is loaded/executed only once

i.e. when the Static block is not member of a class, they do not have a return statement and they cannot be called directly.

Cannot contain this or super. They are primarily used to initialize static fields.
Explain working of Java Virtual Machine (JVM)?

.
A:
JVM is an abstract computing machine like any other real computing machine which first converts .java file into .class file by using Compiler (.class is nothing but byte code file.) and Interpreter reads byte codes
Q: Does JVM maintain a cache by itself?

Does the JVM allocate objects in heap?

Is this the OS heap or the heap maintained by the JVM? Why
A:
Yes, the JVM maintains a cache by itself.

It creates the Objects on the HEAP, but references to those objects are on the STACK.
Q: What is phantom memory?
A:
Phantom memory is false memory.

Memory that does not exist in reality.
Can a method be static and synchronized?
A:
A static method can be synchronized. If you do so, the JVM will obtain a lock on the java.lang.

Class instance associated with the object. It is similar to saying:
view source
print?

synchronized(XYZ.class) {
}
What is difference between String and StringTokenizer?
A:
A StringTokenizer is utility class used to break up string.

Example:

StringTokenizer st = new StringTokenizer(”Hello World”);
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());
}

Output:
view source
print?
Hello World
what is the basic difference between stack and queue?
Stack is a LIFO (last in first out) data structure.


Queue is a FIFO (first in first out) data structure
: How to find middle element of linked list in one pass?
One of the most popular question from data structures and algorithm, mostly asked on telephonic interview.

** In order to find middle element of linked list in one pass you need to maintain two pointer, one increment at each node while other increments after two nodes at a time, by having this arrangement, when first pointer reaches end, second pointer will point to middle element of linked list. **



Since many programmer know that, in order to find length of linked list we need to first traverse through linkedlist till we find last node, which is pointing to null, and then in second pass we can find middle element by traversing only half of length. They get confused when interviewer ask him to do same job in one pass.
Checking Array for duplicate elements Java
. We will use unique property of Java collection class Convert the array into Set which doesn’t allow duplicates to check java array for duplicate elements. Here are five ways we can check if an array has duplicates or not:


1) brute force method which compares each element of Array to all other elements and return true if it founds duplicates. Though this is not an efficient choice it is the one which first comes in mind.

2) Another quick way of checking if a Java array contains duplicates or not is to convert that array into Set. Since Set doesn’t allow duplicates size of corresponding Set will be smaller than original Array if Array contains duplicates otherwise size of both Array and Set will be same.

3) One more way to detect duplication in java array is adding every element of array into HashSet which is a Set implementation. Since add(Object obj) method of
: How do you find duplicates in array if there is more than one duplicate?
One way of solving this problem is using a

Hashtable or HashMap data structure. You can traverse through array, and store each number as key and number of occurrence as value.

At the end of traversal you can find all duplicate numbers, for which occurrence is more than one.

In Java if a number already exists in HashMap then calling get(index) will return number otherwise it return null. this property can be used to insert or update numbers in HashMap.
What is difference between Singly Linked List and Doubly Linked List data structure?
The Main difference between singly linked list and doubly linked list is ability to traverse.

In a single linked list, node only points towards next node, and there is no pointer to previous node, which means you can not traverse back on a singly linked list.

doubly linked list maintains two pointers, towards next and previous node, which allows you to navigate in both direction in any linked list.
: What is binary search tree?
Binary Search Tree has some special properties

e.g. left nodes contains items whose value is less than root , right sub tree contains keys with higher node value than root, and there should not be any duplicates in the tree.

Apart from definition, interview can ask you to implement binary search tree in Java and questions on tree traversal e.g. IN order, preorder, and post order traversals are quite popular data structure question.