java 2nd test.pptx for imp questions and it's answer
RanjitGadge
12 views
13 slides
Oct 20, 2024
Slide 1 of 13
1
2
3
4
5
6
7
8
9
10
11
12
13
About This Presentation
Java imp paper questions answers
Size: 1009.26 KB
Language: en
Added: Oct 20, 2024
Slides: 13 pages
Slide Content
Q1.Describe life cycle of thread Thread Life Cycle Thread has five different states throughout its life. 1. Newborn State 2 . Runnable State 3. Running State 4 . Blocked State 5 . Dead State Thread should be in any one state of above and it can be move from one state to another by different methods and ways. Newborn state : When a thread object is created it is said to be in a new born state. When the thread is in a new born state it is not scheduled running from this state it can be scheduled for running by start() or killed by stop(). If put in a queue it moves to runnable state. Runnable State : It means that thread is ready for execution and is waiting for the availability of the processor i.e. the thread has joined the queue and is waiting for execution. If all threads have equal priority, then they are given time slots for execution in round robin fashion. The thread that relinquishes control joins the queue at the end and again waits for its turn. A thread can relinquish the control to another before its turn comes by yield().
Q1.Describe life cycle of thread
Q1.Describe life cycle of thread Running State: It means that the processor has given its time to the thread for execution. The thread runs until it relinquishes control on its own or it is pre-empted by a higher priority thread. Blocked state : A thread can be temporarily suspended or blocked from entering into the runnable and running state by using either of the following thread method. 1) suspend() : Thread can be suspended by this method. It can be rescheduled by resume(). 2) wait() : If a thread requires to wait until some event occurs , it can be done using wait method and can be scheduled to run again by notify(). 3) sleep(): We can put a thread to sleep for a specified time period using sleep(time) where time is in ms. It re-enters the runnable state as soon as period has elapsed /over Dead State : Whenever we want to stop a thread form running further we can call its stop().The statement causes the thread to move to a dead state. A thread will also move to dead state automatically when it reaches to end of the method. The stop method may be used when the premature death is required.
Describe param tag with example The PARAM element is used to provide "command-line" arguments to a Java applet, which is embedded in a document with the APPLET element. It has two attributes: NAME specifies the name of the argument, and VALUE specifies the value for this argument. The value of <PARAM> tag can be retrieved with the help of getParameter () method Syntax: < param name=”name” value=”value”> Example: < param name=”color” value=”red”>
What is error and exception Error:- “error is a situation which prevents the normal excution of program. An error may produce an incorrect output or may terminate the execution of the program. There are two type of error Compile time error Run time error Exception :- “ An exception is an event, which occurs during the execution of a program, that stop the flow of the program's instructions and takes appropriate actions if handled .” All exception classes are considered as the subtype of the java.lang.Exception class The exception class is extended from the throwable class All the Exception normally handled by compiler.
Write a program using try catch and finally class simpletrycatch3 { public static void main(String args []) { int a=0,b=0,c; try { a= Integer.parseInt ( args [0]); b= Integer.parseInt ( args [1]); c=a/b; System.out.println ("c="+c); } catch( ArithmeticException e) { System.out.println (e); } catch( ArrayIndexOutOfBoundsException e) { System.out.println ("insufficient arguments"); } catch( NumberFormatException e) { System.out.println ("Invalid argument format"); } finally { c= a+b ; System.out.println ("add="+c); } } }
Compare application and applet
Polygon syntax and example Polygon is a closed figure with finite set of line segments joining one vertex to the other. The polygon comprises of set of (x, y) coordinate pairs where each pair is the vertex of the polygon . The side of the polygon is the line drawn between two successive coordinate pairs and a line segment is drawn from the first pair to the last pair . drawPolygon ( int x[] , int y[] , int numberofpoints )
Applet life cycle In Java, an applet is a special type of program embedded in the web page to generate dynamic content. Applet is a class in Java. The applet life cycle can be defined as the process of how the object is created, started, stopped, and destroyed during the entire execution of its application. It basically has five core methods namely init (), start(), stop(), paint() and destroy().These methods are invoked by the browser to execute. Along with the browser, the applet also works on the client side, thus having less processing time.
Applet life cycle
Applet life cycle init (): The init () method is the first method to run that initializes the applet. It can be invoked only once at the time of initialization. The web browser creates the initialized objects, i.e., the web browser (after checking the security settings) runs the init () method within the applet. start(): The start() method contains the actual code of the applet and starts the applet. It is invoked immediately after the init () method is invoked. Every time the browser is loaded or refreshed, the start() method is invoked. It is also invoked whenever the applet is maximized, restored, or moving from one tab to another in the browser. It is in an inactive state until the init () method is invoked. stop(): The stop() method stops the execution of the applet. The stop () method is invoked whenever the applet is stopped, minimized, or moving from one tab to another in the browser, the stop() method is invoked. When we go back to that page, the start() method is invoked again. destroy(): The destroy() method destroys the applet after its work is done. It is invoked when the applet window is closed or when the tab containing the webpage is closed. It removes the applet object from memory and is executed only once. We cannot start the applet once it is destroyed. paint(): The paint() method belongs to the Graphics class in Java. It is used to draw shapes like circle, square, trapezium, etc., in the applet. It is executed after the start() method and when the browser or applet windows are resized.
Applet life cycle Applet Life Cycle Working The Java plug-in software is responsible for managing the life cycle of an applet. An applet is a Java application executed in any web browser and works on the client-side. It doesn't have the main() method because it runs in the browser. It is thus created to be placed on an HTML page. The init (), start(), stop() and destroy() methods belongs to the applet.Applet class. The paint() method belongs to the awt.Component class. In Java, if we want to make a class an Applet class, we need to extend the Applet Whenever we create an applet, we are creating the instance of the existing Applet class. And thus, we can use all the methods of that class.
Compare character stream classes and byte stream class