Академический Документы
Профессиональный Документы
Культура Документы
Q1. How could Java classes direct program messages to the system console, but
error messages, say to a file?
A. The class System has a variable out that represents the standard output, and the
variable err that represents the standard error device. By default, they both point at the
system console. This how the standard output could be re-directed:
Stream st = new Stream(new FileOutputStream("output.txt")); System.setErr(st);
System.setOut(st);
Q2. What's the difference between an interface and an abstract class?
A. An abstract class may contain code in method bodies, which is not allowed in an
interface. With abstract classes, you have to inherit your class from it and Java does not
allow multiple inheritance. On the other hand, you can implement multiple interfaces in
your class.
Q3. Why would you use a synchronized block vs. synchronized method?
A. Synchronized blocks place locks for shorter periods than synchronized methods.
Q4. Explain the usage of the keyword transient?
A. This keyword indicates that the value of this member variable does not have to be
serialized with the object. When the class will be de-serialized, this variable will be
initialized with a default value of its data type (i.e. zero for integers).
performed automatically.
Q7. What's the difference between the methods sleep() and wait()
A. The code sleep(1000); puts thread aside for exactly one second. The code wait(1000),
causes a wait of up to one second. A thread could stop waiting earlier if it receives the
notify() or notifyAll() call. The method wait() is defined in the class Object and the
method sleep() is defined in the class Thread.
Q8. Can you write a Java class that could be used both as an applet as well as an
application?
A. Yes. Add a main() method to the applet.
*Q9. What's the difference between constructors and other methods?
A. Constructors must have the same name as the class and can not return a value. They
are only called once while regular methods could be called many times.
Q10. Can you call one constructor from another if a class has multiple constructors
A. Yes. Use this() syntax.
Q11. Explain the usage of Java packages.
A. This is a way to organize files when a project consists of multiple modules. It also
helps resolve naming conflicts when different packages have classes with the same
names. Packages access level also allows you to protect data from being used by the nonauthorized classes.
Q12. If a class is located in a package, what do you need to change in the OS
environment to be able to use it?
A. You need to add a directory or a jar file that contains the package directories to the
CLASSPATH environment variable. Let's say a class Employee belongs to a package
com.xyz.hr; and is located in the file c:\dev\com\xyz\hr\Employee.java. In this case,
you'd need to add c:\dev to the variable CLASSPATH. If this class contains the method
main(), you could test it from a command prompt window as follows:
c:\>java com.xyz.hr.Employee
Q13. What's the difference between J2SDK 1.5 and J2SDK 5.0?
Q14. What would you use to compare two String variables - the operator == or the
method equals()?
A. I'd use the method equals() to compare the values of the Strings and the == to check if
two variables point at the same instance of a String object.
Q15. Does it matter in what order catch statements for FileNotFoundException and
IOExceptipon are written?
A. Yes, it does. The FileNoFoundException is inherited from the IOException.
Exception's subclasses have to be caught first.
Q16. Can an inner class declared inside of a method access local variables of this
method?
A. It's possible if these variables are final.
Q17. What can go wrong if you replace && with & in the following code:
String a=null; if (a!=null && a.length()>10) {...}
A. A single ampersand here would lead to a NullPointerException.
Q18. What's the main difference between a Vector and an ArrayList
A. Java Vector class is internally synchronized and ArrayList is not.
some important event has happened. What Java technique would you use to
implement it?
A. If these classes are threads I'd consider notify() or notifyAll(). For regular classes you
can use the Observer interface.
Q30. What access level do you need to specify in the class declaration to ensure that
only classes from the same directory can access it?
A. You do not need to specify any access level, and Java will use a default package
access level.
Q31 What makes J2EE suitable for distributed multitiered Applications?
- The J2EE platform uses a multitiered distributed application model. Application logic is
divided into components according to function, and the various application components
that make up a J2EE application are installed on different machines depending on the tier
in the multitiered J2EE environment to which the application component belongs. The
J2EE application parts are:
client component can be executed, it must be assembled into a J2EE application and
deployed into its container.
Q40 What are container services?
- A container is a runtime support of a system-level entity. Containers provide
components with services such as lifecycle management, security, deployment, and
threading.
Q41 What is the web container?
- Servlet and JSP containers are collectively referred to as Web containers. It manages the
execution of JSP page and servlet components for J2EE applications. Web components
and their container run on the J2EE server.
Q42 What is Enterprise JavaBeans (EJB) container?
- It manages the execution of enterprise beans for J2EE applications.
Enterprise beans and their container run on the J2EE server.
Q43 What is Applet container?
- IManages the execution of applets. Consists of a Web browser and Java Plugin running
on the client together.
Q44 How do we package J2EE components?
- J2EE components are packaged separately and bundled into a J2EE application for
deployment. Each component, its related files such as GIF and HTML files or server-side
utility classes, and a deployment descriptor are assembled into a module and added to the
J2EE application. A J2EE application is composed of one or more enterprise bean,Web,
or application client component modules. The final enterprise solution can use one J2EE
application or be made up of two or more J2EE applications, depending on design
requirements. A J2EE application and each of its modules has its own deployment
descriptor. A deployment descriptor is an XML document with an .xml extension that
describes a components deployment settings.
Q45 What is a thin client?
- A thin client is a lightweight interface to the application that does not have such
operations like query databases, execute complex business rules, or connect to legacy
applications.
Q46 What are types of J2EE clients?
- Following are the types of J2EE clients:
Applets
Application clients
resource adapters that support access to enterprise information systems that can be
plugged into any J2EE product. Each type of database or EIS has a different resource
adapter. Note: A resource adapter is a software component that allows J2EE application
components to access and interact with the underlying resource manager. Because a
resource adapter is specific to its resource manager, there is typically a different resource
adapter for each type of database or enterprise information system.
Q52 What is JAAP?
- The Java Authentication and Authorization Service (JAAS) provides a way for a J2EE
application to authenticate and authorize a specific user or group of users to run it. It is a
standard Pluggable Authentication Module (PAM) framework that extends the Java 2
platform security architecture to support user-based authorization.
Q53 What is Java Naming and Directory Service?
- The JNDI provides naming and directory functionality. It provides applications with
methods for performing standard directory operations, such as associating attributes with
objects and searching for objects using their attributes. Using JNDI, a J2EE application
can store and retrieve any type of named Java object. Because JNDI is independent of
any specific implementations, applications can use JNDI to access multiple naming and
directory services, including existing naming and
directory services such as LDAP, NDS, DNS, and NIS.
Q54 What is Struts?
- A Web page development framework. Struts combines Java Servlets, Java Server
Pages, custom tags, and message resources into a unified framework. It is a cooperative,
synergistic platform, suitable for development teams, independent developers, and
everyone between.
Q55 How is the MVC design pattern used in Struts framework?
- In the MVC design pattern, application flow is mediated by a central Controller. The
Controller delegates requests to an appropriate handler. The handlers are tied to a Model,
and each handler acts as an adapter between the request and the Model. The Model
represents, or encapsulates, an applications business logic or state. Control is usually
then forwarded back through the Controller to the appropriate View. The forwarding can
be determined by consulting a set of mappings, usually loaded from a database or
configuration file. This provides a loose coupling between the View and Model, which
can make an application significantly easier to create and maintain. Controller: Servlet
controller which supplied by Struts itself; View: what you can see on the screen, a JSP
page and presentation components; Model: System state and a business logic JavaBeans.
Q56 What is transient variable?
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 userdefined 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.
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".
Q73: Explain the different forms of Polymorphism.
A: 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
- Stateless Session : Does not do anything to the bean as moving the bean from free pool
to cache are managed by the container depending on load. Stateful Session: Removes the
bean from the cache. Entity Bean: Deletes the bean (data) from persistent storage
An entity bean accesses related entity beans by means of the accessor methods for its
container-managed relationship fields, which are specified by the cmr-field elements
of its abstract persistence schema defined in the deployment descriptor. Entity bean
relationships are defined in terms of the local interfaces of the related beans, and the
view an entity bean presents to its related beans is defined by its local home and local
interfaces. Thus, an entity bean can be the target of a relationship from another entity
bean only if it has a local interface.
Q79 What is the new basic requirement for a CMP entity bean class in 2.0 from
that of ejb 1.1?
- It must be abstract class. The container extends it and implements methods which are
required for managing the relationships
Q80 What are the basic classes required in the client for invoking an EJB?
The home and the remote interfaces, the implementation of the Naming Context Factory,
the stubs and skeletons. In some App servers the stubs and the skeletons can be
dynamically downloaded from the server
Q81 What is the difference between Message Driven Beans and Stateless Session
beans? - In several ways, the dynamic creation and allocation of message-driven bean
instances mimics the behavior of stateless session EJB instances, which exist only for the
duration of a particular method call. However, message-driven beans are different from
stateless session EJBs (and other types of EJBs) in several significant ways:
1.Message-driven beans process multiple JMS messages asynchronously, rather than
processing a serialized sequence of method calls.
2.Message-driven beans have no home or remote interface, and therefore cannot be
directly accessed by internal or external clients. Clients interact with message-driven
beans only indirectly, by sending a message to a JMS Queue or Topic.
3.Only the container directly interacts with a message-driven bean by creating bean
instances and passing JMS messages to those instances as necessary.
4.The Container maintains the entire lifecycle of a message-driven bean; instances cannot
be created or removed as a result of client requests or other API calls.
Q82 What is the need for Clustering?
- To scale the application so that it is highly available and has high throughput.
Q83 What are the types of Scaling?
- There are two types of scaling: Vertical Scaling and Horizontal Scaling.
Q84 What is Vertical Scaling?
- When multiple server clones of an application server are defined on the same physical
m/c, it is called Vertical Scaling. The objective is to use the processing power of that m/c
more efficiently.
Q85 What is Horizontal Scaling?
- When Clones of an application server are defined on multiple physical m/c, it is called
Horizontal Scaling. The objective is to use more than one less powerful m/c more
efficiently.
Q86 What is a Server Group? - A server group is a template of an Application
Server(and its contents) i.e, it is a logical representation of the application server. It has
the same structure and attributes as the real Application Server, but it is not associated
with any node, and does not correspond to any real server process running on any node.
Q87 What is a Clone?
-
The copies of a server group are called Clones. But unlike a Server Group Clones are
associated with a node and are real server process running in that node.
- Identical DataSource has to be created in each clustered server instances and configure
to use different connection pools.
Q92 Mention some tools to cluster Web Servers?
- Web Servers can be clustered using Edge Server or DNS.
Q93 What is in-memory replication?
- The process by which the contents in the memory of one physical m/c are replicated in
all the m/c in the cluster is called in-memory replication.
Q94 Difference Between Abstraction and Encapsulation
- Abstraction is removing some distinctions between objects, so as to show their
commonalities. Encapsulation is hiding the details of the implementation of an object so
that there are no external dependencies on the particular implementation.
Q95 What is a platform?
A: 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 and XP, Linux, Solaris, and MacOS.
Q96 What is the main difference between Java platform and other platforms?
A: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:
1. The JavaVirtual Machine (Java VM)
2. The Java Application Programming Interface(Java API)
Q97 What is the Java Virtual Machine?
A:The Java Virtual Machine is a software that can be ported onto various hardware-based
platforms.
Q98 What is the Java API?
A:The Java API is a large collection of ready-made software components that provide
many useful capabilities, such as graphical user interface (GUI) widgets.
Q99 What is the package?
A: 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.
Q100 What is native code?
A: The native code is code that after you compile it, the compiled code runs on a specific
hardware platform.
Q101 Is Java code slower than native code? Can main() method be overloaded?
A: Yes. the main() method is a special method for a program entry. You can overload
main() method in any ways. But if you change the signature of the main method, the
entry point for the program will be gone.
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.
Q111 Which package has light weight components?
A: javax.Swing package. All components in Swing, except JApplet, JDialog, JFrame and
JWindow are lightweight components.
Q112 Does a class inherit the constructors of its superclass?
A: A class does not inherit constructors from any of its superclasses.
Q113 Name primitive Java types.
A: The primitive types are byte, char, short, int, long, float, double and boolean.
Q114 What restrictions are placed on method overloading?
A: Two methods may not have the same name and argument list but different return
types.
Q115 What restrictions are placed on method overriding?
A: 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.
Q116 What is casting?
A: 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.
Q117 What is the difference between a Scrollbar and a ScrollPane?
A: 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.
Q118 What is tunnelling?
A: Tunnelling is a route to somewhere. For example, RMI tunnelling is a way to make
RMI application get through firewall. In CS world, tunnelling means a way to transfer
data.
Q119 Does the code in finally block get executed if there is an exception and a return
statement in a catch block?
A: If an exception occurs and there is a return statement in catch block, the finally block
is still executed. The finally block will not be executed when the System.exit(1)
statement is executed earlier or the system shut down earlier or the memory is used
up earlier before the thread goes to finally block.
Q120 What are use cases?
A: A use case describes a situation that a program might encounter and what behavior the
program should exhibit in that circumstance. It is part of the analysis of a program. The
collection of use cases should, ideally, anticipate all the standard circumstances and many
of the extraordinary circumstances possible so that the program will be robust.
{
System.out.println(new MyKey().key);//prints 12345
}
}