Important Question of Java Programing
Important Question of Java Programing
PROGRAMING
(22412)
1. Define error. List types of error
Ans:- Errors are mistakes that can make a program go wrong.
Errors may be logical or may be typing mistakes. An error
may produce an incorrect output or may terminate the
execution of the program abruptly or even may cause the
system to crash.
Errors are broadly classified into two categories:
1. Compile time errors
2. Runtime errors
2. Define thread. Mention 2 ways to create thread.
Ans:- 1. Thread is a smallest unit of executable code or a single task is
also called as thread.
2. Each tread has its own local variable, program counter and
lifetime.
3. A thread is similar to program that has a single flow of control.
There are two ways to create threads in java:
1) By extending thread class
Syntax: - class Mythread extends Thread
{
-----
}
2) Implementing the Runnable Interface
Syntax: class MyThread implements Runnable
{
public void run()
{
------ .
}
3. Explain Life cycle of the applet with neat diagram ?
Ans :- When an applet begins, the AWT calls the following methods, in
this sequence:
1) init( )
2) start( )
3) paint( )
When an applet is terminated, the following sequence of method
calls takes place:
4) stop( )
5) destroy( )
init (): The init( ) method is the first method to be called. This is
where you should initialize Variables. This method is called
only once during the run time of your applet.
start( ): The start( ) method is called after init( ).It is also called to
restart an applet after it has Been stopped. Whereas init( )
is called once—the first time an applet is loaded—start( )
is called each time an applet’s HTML document is
displayed onscreen.
Paint (): The paint ( ) method is called each time your applet’s
output must be redrawn. Paint ( ) is also called when the
applet begins execution. Whatever the cause, whenever
the applet must redraw its output, paint( ) is called. The
paint ( ) method has one parameter of type Graphics.
Stop (): when stop ( ) is called, the applet is probably running.
You should use stop ( ) to suspend threads that don’t
need to run when the applet is not visible.
destroy(): The destroy ( ) method is called when the environment
determines that your applet needs to be removed
completely from memory.
4. Explain the following with syntax?
i) drawLine
ii) drawOval
iii) drawArc
iv) drawstring
Ans: i) drawLine(): It is a method from Graphics class and is used to
draw line between the points(x1, y1) and (x2, y2).
Syntax : drawLine(int x1, int y1, int x2, int y2)
ii) drawOval(): Its is a method from Graphics class and is used to
draw oval or ellipse and circle.
Syntax : drawOval(int x, ,int y, int width, int height)
It is used to draw oval with the specified width and
height. If width and height are given equal, then it
draws circle otherwise oval/ellipse.
iii) drawRect(): It is a method from Graphics class and it draws a
rectangle with the specified width and height.
Syntax : drawRect(int x, int y, int width, int height)
iv) drawArc(): It is a method from Graphics class and is used to
draw a circular or elliptical arc.
Syntax : drawArc (int x, int y, int width, int height, intstartAngle,
intsweepAngle)
where first fourare x, y, width and height as in case of oval or rect.
The next two are start angle and sweep angle.When sweep angle is
positive, it moves in anticlockwise direction. It is given as
negative, It moves in clockwise direction.
5.