Вы находитесь на странице: 1из 20

Question Bank

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).

Q5. How can you force garbage collection?


A. You can't force GC, but could request it by calling System.gc(). JVM does not
guarantee that GC will be started immediately.
Q6. How do you know if an explicit object casting is needed?
A. If you assign a superclass object to a variable of a subclass's data type, you need to do
explicit casting. For example:
Object a; Customer b; b = (Customer) a;
When you assign a subclass to a variable having a supeclass type, the casting is

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?

A.There's no difference, Sun Microsystems just re-branded this version.

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.

Q19. When should the method invokeLater()be used?


A. This method is used to ensure that Swing components are updated through the eventdispatching thread.

Q20. How can a subclass call a method or a constructor defined in a superclass?


A. Use the following syntax: super.myMethod(); To call a constructor of the superclass,
just write super(); in the first line of the subclass's constructor

For senior-level developers:


Q21. What's the difference between a queue and a stack?
A. Stacks works by last-in-first-out rule (LIFO), while queues use the FIFO rule
Q22. You can create an abstract class that contains only abstract methods. On the
other hand, you can create an interface that declares the same methods. So can you
use abstract classes instead of interfaces?
A. Sometimes. But your class may be a descendent of another class and in this case the
interface is your only option.
Q23. What comes to mind when you hear about a young generation in Java?
A. Garbage collection.
Q24. What comes to mind when someone mentions a shallow copy in Java?
A. Object cloning.
Q25. If you're overriding the method equals() of an object, which other method you
might also consider?
A. hashCode()
Q26. You are planning to do an indexed search in a list of objects. Which of the two
Java collections should you use:
ArrayList or LinkedList?
A. ArrayList
Q27. How would you make a copy of an entire Java object with its state?
A. Have this class implement Cloneable interface and call its method clone().
**Q28. How can you minimize the need of garbage collection and make the memory
use more effective?
A. Use object pooling and weak object references.
Q29. There are two classes: A and B. The class B need to inform a class A when

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-tier components run on the client machine.

Web-tier components run on the J2EE server.

Business-tier components run on the J2EE server.

Enterprise information system (EIS)-tier software runs on the EIS server.

Q32 What is J2EE?


- J2EE is an environment for developing and deploying enterprise applications. The J2EE
platform consists of a set of services, application programming interfaces (APIs), and
protocols that provide the functionality for developing multitiered, web-based
applications.
Q33 What are the components of J2EE application?
- A J2EE component is a self-contained functional software unit that is assembled into a
J2EE application with its related classes and files and communicates with other
components. The J2EE specification defines the following J2EE components:
Application clients and applets are client components.
Java Servlet and JavaServer Pages technology components are web components.
Enterprise JavaBeans components (enterprise beans) are business components.
Resource adapter components provided by EIS and tool vendors.
Q34 What do Enterprise JavaBeans components contain?

- Enterprise JavaBeans components contains Business code, which is logic


that solves or meets the needs of a particular business domain such as banking, retail, or
finance, is handled by enterprise beans running in the business tier. All the business code
is contained inside an Enterprise Bean which receives data from client programs,
processes it (if necessary), and sends it to the enterprise information system tier for
storage. An enterprise bean also retrieves data from storage, processes it (if necessary),
and sends it back to the client program.
Q35 Is J2EE application only a web-based?
- No, It depends on type of application that client wants. A J2EE application can be webbased or non-web-based. if an application client executes on the client machine, it is a
non-web-based J2EE application. The J2EE application can provide a way for users to
handle tasks such as J2EE system or application administration. It typically has a
graphical user interface created from Swing or AWT APIs, or a command-line interface.
When user request, it can open an HTTP connection to establish communication with a
servlet running in the web tier.
Q36 Are JavaBeans J2EE components?
- No. JavaBeans components are not considered J2EE components by the J2EE
specification. They are written to manage the data flow between an application client or
applet and components running on the J2EE server or between server components and a
database. JavaBeans components written for the J2EE platform have instance variables
and get and set methods for accessing the data in the instance variables. JavaBeans
components used in this way are typically simple in design and implementation, but
should conform to the naming and design conventions outlined in the JavaBeans
component architecture.
Q37 Is HTML page a web component?
- No. Static HTML pages and applets are bundled with web components during
application assembly, but are not considered web components by the J2EE specification.
Even the server-side utility classes are not considered web components, either.
Q38 What can be considered as a web component?
- J2EE Web components can be either servlets or JSP pages. Servlets are Java
programming language classes that dynamically process requests and construct
responses. JSP pages are text-based documents that execute as servlets but allow a more
natural approach to creating static content.
Q39 What is the container?
- Containers are the interface between a component and the low-level platform specific
functionality that supports the component. Before a Web, enterprise bean, or application

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

Java Web Start-enabled rich clients, powered by Java Web Start


technology.

Wireless clients, based on Mobile Information Device Profile (MIDP)


technology.

Q47 What is deployment descriptor?


- A deployment descriptor is an Extensible Markup Language (XML) text-based file with
an .xml extension that describes a components deployment settings. A J2EE application
and each of its modules has its own deployment descriptor. For example, an enterprise
bean module deployment descriptor declares transaction attributes and security
authorizations
for an enterprise bean. Because deployment descriptor information is declarative, it can
be changed without modifying the bean source code. At run time, the J2EE server reads
the deployment descriptor and acts upon the component accordingly.
Q48 What is the EAR file?
- An EAR file is a standard JAR file with an .ear extension, named from Enterprise
ARchive file. A J2EE application with all of its modules is delivered in EAR file.
Q49 What is JTA and JTS?
- JTA is the abbreviation for the Java Transaction API. JTS is the abbreviation for the
Jave Transaction Service. JTA provides a standard interface and allows you to demarcate
transactions in a manner that is independent of the transaction manager implementation.
The J2EE SDK implements the transaction manager with JTS. But your code doesnt call
the JTS methods directly. Instead, it invokes the JTA methods, which then call the lowerlevel JTS routines. Therefore, JTA is a high level transaction interface that your
application uses to control transaction. and JTS is a low level transaction interface and
ejb uses behind the scenes (client code doesnt directly interact with JTS. It is based on
object transaction service(OTS) which is part of CORBA.
Q50 What is JAXP?
- JAXP stands for Java API for XML. XML is a language for representing and describing
text-based data which can be read and handled by any program or tool that uses XML
APIs. It provides standard services to determine the type of an arbitrary piece of data,
encapsulate access to it, discover the operations available on it, and create the appropriate
JavaBeans component to perform those operations.
Q51 What is J2EE Connector?
- The J2EE Connector API is used by J2EE tools vendors and system integrators to create

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?

A: Transient variable can't be serialize. For example if a variable is declared as transient n


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.
Q57 Name the containers which uses Border Layout as their default layout?
A: Containers which uses Border Layout as their default are:
window, Frame and Dialog classes.
Q58: What do you understand by Synchronization?
A: 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.
}
}
Q59: What is Collection API?
A: 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.
Q60: Is Iterator a Class or Interface? What is its use?
A: Iterator is an interface which is used to step through the elements of a Collection.
Q61: What is similarities/difference between an Abstract class and Interface?
A: Differences are as follows:
1) Interfaces provide a form of multiple inheritance. A class can extend only one other
class.
2) Interfaces are limited to public methods and constants with no implementation.
Abstract classes can have a partial implementation, protected parts, static methods, etc.
3) A Class may implement several interfaces. But in case of abstract
class, a class may extend only one abstract class.

4) Interfaces are slow as it requires extra indirection to to find corresponding method in


in the actual class. Abstract classes are fast.
Similarities:
Either Abstract classes or Interface can be instantiated.
Q62: How to define an Abstract class?
A: 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();
}
Q63: How to define an Interface?
A: 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.
Example of Interface:
public interface sampleInterface
{
public void functionOne();
public long CONSTANT_onfiltered= 1000;
}
Q64: Explain the user defined Exceptions?
A: 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
}
Q65: Explain the new Features of JDBC 2.0 Core API?
A: The JDBC 2.0 API includes the complete JDBC API, which includes both core and
Optional Package API, and provides industrial 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 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.

Q66: Explain garbage collection?


A: 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.
Q67: How you can force the garbage collection?
A: Garbage collection automatic process and can't be forced.
Q68: What is OOPS?
A: OOP is the common abbreviation for Object-Oriented Programming.
Q69: Describe the principles of OOPS.
A: There are three main principals of oops which are called Polymorphism, Inheritance
and Encapsulation.
Q70: Explain the Encapsulation principle.
A: 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.
Q71: Explain the Inheritance principle.
A: Inheritance is the process by which one object acquires the properties of another
object.
Q72: Explain the Polymorphism principle.
A: 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".
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

Q74: What are Access Specifiers available in Java?


A: Access specifiers are keywords that determines the type of access to the member of a
class. These are:
Public
Protected
Private
Defaults

Q75: Describe the wrapper classes in Java.


A: 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:
1. Primitive Wrapper
2. boolean java.lang.Boolean
3. byte java.lang.Byte
4. char java.lang.Character
5. double java.lang.Double
6. float java.lang.Float
7. int java.lang.Integer
8. long java.lang.Long
9. short java.lang.Short
10. void java.lang.Void
Q76 What is the relationship between local interfaces and container-managed
relationships?
- Entity beans that have container-managed relationships with other entity beans, must be
accessed in the same local scope as those related beans, and therefore typically provide a
local client view. In order to be the target of a container-managed relationship, an entity
bean with container-managed persistence must provide a local interface.
Q77 What does a remove method do for different cases of beans?

- 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

Q78 How does a container-managed relationship work?


-

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.

Q88 What is Ripple Effect?


- The process of propagating the changes in the properties of a server group during
runtime to all the associated clones is called Ripple Effect.
Q89 What level of Load Balancing is possible with EJBs?
- The workload management service provides load balancing for the following types of
enterprise beans: Homes of entity or session beans, Instances of entity beans, Instances of
stateless session beans.
Q90 What is the basic requirement for in-memory replication in Weblogic?
- The data in session should consist only of Serialized objects. Only setAttribute function
should be used to set objects in session.
Q91 How JDBC services can be used in clustered environment?

- 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.

Q102 What is the serialization?


A: 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.
Q103 What is a transient variable?
A: 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.
Q104 Which containers use a border layout as their default layout?
A:The Window, Frame and Dialog classes use a border layout as their default layout.
Q105 What is the purpose of finalization?
A: The purpose of finalization is to give an unreachable object the opportunity to perform
any cleanup processing before the object is garbage collected.
Q106 Which class is the superclass for every class.
A: Object.
Q107 What is the purpose of the finally clause of a try-catch-finally statement?
A: The finally clause is used to provide the capability to execute code no matter whether
or not an exception is thrown or caught.
Q108 What is a static method?
A: 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.
Q109 What is the difference between a Window and a Frame?
A: The Frame class extends Window to define a main application window that can have a
menu bar.
Q110 What do heavy weight components mean?
A: 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.
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.

Q121 What is scalability and performance?


A: Performance is a measure of "how fast can you perform this task." And scalability
describes how an application behaves as its workload and available computing resources
increase.
Q122 What is the benefit of subclass?
A: The benefits of subclass are :
- The sub class inherits all the public methods and the implementation.
- The sub class inherits all the protected methods and their implementation.
- The sub class inherits all the default(non-access modifier) methods and their
implementation.
- The sub class also inherits all the public, protected and default member variables
from the
- super class.
- The constructors are not part of this inheritance model.
Q123 In System.out.println(),what is System,out and println,pls explain?
A: System is a predefined final class,out is a PrintStream object acting as a field member
and println is a built-in overloaded method in the out object.
Q124 What is meant by "Abstract Interface"?
A: First, an interface is abstract. That means you cannot have any implementation in an
interface. All the methods declared in an interface are abstract methods or signatures of
the methods.
Q125 Why Java does not support pointers?
A: Because pointers are unsafe. Java uses reference types to hide pointers and
programmers feel easier to deal with reference types without pointers. This is why Java
and C-sharp shine.
Q126 Can you declare a class as private?
A: Yes, we can declare a private class as an inner class. For example,
class MyPrivate
{
private static class MyKey
{
String key = "12345";
}
public static void main(String[] args)

{
System.out.println(new MyKey().key);//prints 12345
}
}

Q127 Can Java code be compiled to machine dependent executable file?


A: Yes. There are many tools out there. If you did so, the generated exe file would be run
in the specific platform, not cross-platform.
Q128 What are the drawbacks of inheritance?
A: Since inheritance inherits everything from the super class and interface, it may make
the subclass too clustering and sometimes error-prone when dynamic overriding or
dynamic overloading in some situation. In addition, the inheritance may make peers
hardly understand your code if they don't know how your super-class acts. Usually, when
you want to use a functionality of a class, you may use subclass to inherit such function
or use an instance of this class in your class. Which is better, depends on your
specification.

Вам также может понравиться