16. Describe different states of a thread.
Ans:
A thread in Java can be in either
of the following states:
Ready : When a thread is created,
it’s in Ready state.
Running : A thread currently
being executed is in running state.
Waiting : A thread waiting for
another thread to free certain resources is in waiting state.
Dead : A thread which has gone
dead after execution is in dead state.
17. Can variables be used in Java without initialization?
Ans:
In Java, if a variable is used in
a code without prior initialization by a valid value, program doesn’t compile
and gives an error as no default value is assigned to variables in Java.
18. Can a class in Java be inherited from more than one class?
Ans:
In Java, a class can be derived
from only one class and not from multiple classes. Multiple inheritances is not
supported by Java.
19. Is JDK required on each machine to run a Java program?
Ans:
JDK is development Kit of Java
and is required for development only and to run a Java program on a machine,
JDK isn’t required. Only JRE is required.
20. What is an Exception? Which are the two subclasses under Exception class?
Ans:
An exception is a problem that
arises during the execution of a program. Exceptions are caught by handlers
positioned along the thread's method invocation stack.
The Exception class has two main
subclasses : IOException class and RuntimeException Class.
21. Define Packages in Java? Why Packages are used?
A Package can be defined as a
grouping of related types classes, interfaces, enumerations and annotations
providing access protection and name space management.
Packages are used in Java
in-order to prevent naming conflicts, to control access, to make
searching/locating and usage of classes, interfaces, enumerations and
annotations, etc., easier.
22. What is an applet?
Ans:
An applet is a Java program that
runs in a Web browser. An applet can be a fully functional Java application
because it has the entire Java API at its disposal.
23. What is the difference between an Applet and an Application?
Ans:
1) Applets can be embedded in
HTML pages and downloaded over the Internet whereas Applications have no
special support in HTML for embedding or downloading.
2) Applets can only be executed
inside a java compatible container, such as a browser or appletviewer whereas
Applications are executed at command line by java.exe or jview.exe.
3) Applets execute under strict
security limitations that disallow certain operations(sandbox model security)
whereas Applications have no inherent security restrictions.
4) Applets don't have the main()
method as in applications. Instead they operate on an entirely different
mechanism where they are initialized by init(), started by start(), stopped by
stop() or destroyed by destroy().
24. What is Java Beans ?
Ans:
JavaBeans are classes that
encapsulate many objects into a single object (the bean).
According to JavaSoft, "A
Java Bean is a reusable software component that can be manipulated visually in
a builder tool."
25. How are Java source code files named?
Ans:
A Java source code file takes the name of a public class or interface
that is defined within the file. A source code file may contain at most one
public class or interface. If a public class or interface is defined within a
source code file, then the source code file must take the name of the public
class or interface. If no public class or interface is defined within a source
code file, then the file must take on a name that is different than its classes
and interfaces. Source code files use the .java extension.
EmoticonEmoticon