Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Questions and Answers Q.1) What are the Applet's life cycle methods? e. co m A. init(), start() and destroy() B. init(), start() and paint() C. init(), start(), paint(). stop() and destroy() D. init(), start() and stop() w .a p tio nl in ANSWER : init(), start(), paint(). stop() and destroy() SOLUTION : The applet's voyage starts here. In this method, the applet object is created by the browser. Because this method is called before all the other methods, programmer can utilize this method to instantiate objects, initialize variables, setting background and foreground colors in GUI etc.; the place of a constructor in an application. It is equivalent to born state of a thread. start(): In init() method, even through applet object is created, it is in inactive state. An inactive applet is not eligible for microprocessor time even though the microprocessor is idle. To make the applet active, the init() method calls start() method. In start() method, applet becomes active and thereby eligible for processor time. paint(): This method takes a java.awt.Graphics object as parameter. This class includes many methods of drawing necessary to draw on the applet window. This is the place where the programmer can write his code of what he expects from applet like animation etc. This is equivalent to runnable state of thread. stop(): In this method the applet becomes temporarily inactive. An applet can come any number of times into this method in its life cycle and can go back to the active state (paint() method) whenever would like. It is the best place to have cleanup code. It is equivalent to the blocked state of the thread. destroy(): This method is called just before an applet object is garbage collected. This is the end of the life cycle of applet. It is the best place to have cleanup code. It is equivalent to the dead state of the thread. Q.2) The syntax of paint()method is.. w A. public void paint() B. public void paint(String s) C. public void paint(Graphics g) D. public void paint(Graphics g,String s) w ANSWER : public void paint(Graphics g) SOLUTION : This method is called when the contents of the component should be painted; such as when the component is first being shown or is damaged and in need of repair. The clip rectangle in the Graphics parameter is set to the area which needs to be painted. Subclasses of Component that override this method need not call super.paint(g). For performance reasons, Components with zero width or height aren't considered to need painting when they are first shown, and also aren't considered to need repair. Q.3) AppletViewer tool is available in which of the folder of JDK : A. bin B. lib C. source D. class ANSWER : bin SOLUTION : The CLASSPATH environment variable tells the Java Virtual Machine and other Java applications (for example, the Java tools located in the jdk1.1.x/bin directory) where to find the class libraries, including user-defined class libraries. Q.4) which package contains color class? Page 1 Questions and Answers A. java.applet B. java.awt C. java.graphics D. java.lang e. co m ANSWER : java.awt SOLUTION : The Abstract Window Toolkit (AWT) is a set of Java classes that allow a programmer to create a Graphical User Interface and accept user input through the keyword and the mouse. Q.5) Which of the following methods set the frame surface color to pink? in A. setBackground(Color.pink); B. setColor(PINK); C. Background(pink); D. None of the above tio nl ANSWER : setBackground(Color.pink); SOLUTION : It is used to set background color of an applet window. Syntax: void setBackground(Color newcolor) Q.6) The(0,0) coordinates of applet window is located .. w .a p A. at the center of the applet B. at the center of the right edge of the applet C. at the center of the left edge of the applet D. at the upper-left corner of the applet w ANSWER : at the upper-left corner of the applet SOLUTION : (0,0) coordinates of applet window is located at the upper-left corner of the applet w Q.7) What is the length of the application box made by this program? import java.awt.*; import java.applet.*; public class myapplet extends Applet { Graphic g; g.drawString("A Simple Applet",20,20); } A. 20 B. Default value C. Compilation Error D. Runtime Error ANSWER : Compilation Error SOLUTION : To implement the method drawString we need first need to define abstract method of AWT that is paint() method.Without paint() method we cannot define and use drawString or any Graphic class methods. Q.8) which of the following is an optional attribute of applet tag? A. Code Page 2 Questions and Answers ANSWER : Name SOLUTION : Defines the name for an applet (to use in scripts) e. co m B. Name C. Width D. Height Q.9) Which class is used to get dimensions of an applet? A. Dimension B. metrics C. Applet D. fontMetrics tio nl in ANSWER : Dimension SOLUTION : The Dimension class encapsulates the width and height of a component (in integer precision) in a single object. The class is associated with certain properties of components. Several methods defined by the Component class and the LayoutManager interface return a Dimension object. Q.10) To display text in the applet status bar method is used. w .a p A. showStatus() B. showStatusBar() C. drawStatus() D. drawStatusBar() ANSWER : showStatus() SOLUTION : Displays a message in the status line of the browser or applet viewer. w Applets display status lines with the showStatus method, inherited in the JApplet class from the Applet class. w Here is an example of its use: showStatus(";MyApplet: Loading image file "; + file); Q.11) What is the output of this program? import java.lang.reflect.*; class Additional_packages { public static void main(String args[]) { try { Class c = Class.forName("java.awt.Dimension"); Constructor constructors[] = c.getConstructors(); for (int i = 0; i < constructors.length; i++) System.out.println(constructors[i]); } catch (Exception e){ System.out.print("Exception"); } } } A. Program prints all the constructors of java.awt.Dimension.package. B. Program prints all the possible constructors of class Class. Page 3 Questions and Answers C. Program prints Exception D. Runtime Error e. co m ANSWER : Program prints all the constructors of java.awt.Dimension.package. SOLUTION : Output: $ javac Additional_packages.java $ java Additional_packages public java.awt.Dimension(java.awt.Dimension) public java.awt.Dimension() public java.awt.Dimension(int,int) Q.12) Which of these package is used for graphical user interface? in A. java.applet B. java.awt C. java.awt.image D. java.io w .a p Q.13) Applet work on tio nl ANSWER : java.awt SOLUTION : Contains all of the classes for creating user interfaces and for painting graphics and images. A user interface object such as a button or a scrollbar is called, in AWT terminology, a component. The Component class is the root of all AWT components. See Component for a detailed description of properties that all AWT components share. A. server side B. client side C. None of the above D. All of the above w w ANSWER : client side SOLUTION : Web browsers first supported applets. Created with the Java programming language (similar to C++), these small lumps of code run on any system that can interpret the 'bytecodes'that a Java compiler produces. Because Java-enabled Web browsers run on Windows, Macintosh, and Unix operating systems, Java applets can be viewed on any of these platforms. Although some vendors are developing full-blown applications with Java, the primary use of the language today is in creating applets that only run inside Web pages. Currently Java applets don't have any standard way to communicate between each other, though Sun has proposed a standard called Java Beans that achieves this. Microsoft already supports applet interaction through the same component object model (COM) that it uses for communication between ActiveX controls and other OLE/COM components. Java applets in today's Web browsers run inside of a 'sandbox', which limits their functionality to operations that can't hurt the computer they're running on. Both Netscape Navigator and Internet Explorer support Java applets, although their methods of connecting script code to applets differ greatly. Q.14) Which method can be used to draw a rectangle in the a Applet? A. drawRect() B. drawPolygon() C. drawLine() D. all of these ANSWER : all of these Page 4 Questions and Answers e. co m SOLUTION : Polygons are shapes with many sides. A polygons may be defined as a set of connected lines. The end of first line is the beginning of second line, and so on, Syntax: drawPolygon(int[] xPoints, int[] yPoints, int nPoints) Draws a closed polygon defined by arrays of x and y coordinates drawRect() - draws a hollow rectangle g.drawLine(x,y,width,height) in drawLine() draws a straight line g.drawLine(x1,y1,x2,y2 Q.15) Which of these package is used for all the text related modifications? tio nl A. java.text B. java.awt C. java.lang.text D. java.text.mofify w .a p ANSWER : java.text SOLUTION : Provides classes and interfaces for handling text, dates, numbers, and messages in a manner independent of natural languages. This means your main application or applet can be written to be language-independent, and it can rely upon separate, dynamically-linked localized resources. This allows the flexibility of adding localizations for new localizations at any time. These classes are capable of formatting dates, numbers, and messages, parsing; searching and sorting strings; and iterating over characters, words, sentences, and line breaks. This package contains three main groups of classes and interfaces: w w Classes for iteration over text Classes for formatting and parsing Classes for string collation Q.16) Which of these class allows us to get real time data about private and protected member of a class? A. java.io B. GetInformation C. ReflectPermission D. MembersPermission ANSWER : ReflectPermission SOLUTION : The ReflectPermission class allows reflection of a private or protected members of a class. This was added after java 2.0 . Q.17) Which of these package is used for analyzing code during run-time? A. java.applet B. java.awt C. java.io D. java.lang.reflect ANSWER : java.lang.reflect SOLUTION : Reflection is the ability of a software to analyze itself. This is provided byjava.lang.reflevt Page 5 Questions and Answers package. Q.18) Which of the following components allow multiple selections? e. co m A. Non-exclusive Checkboxes B. Radio buttons C. Choice D. Text Boxes ANSWER : Non-exclusive Checkboxes SOLUTION : When the user can select many options from a list of checkboxes, the checkboxes are being used nonexclusively. in Q.19) The implementation-specific properties like ascent, descent of a font object is implemented by nl A. Font class B. Regular class C. FontMetrics class D. Graphics class w .a p tio ANSWER : FontMetrics class SOLUTION : It is sometimes necessary to know the attributes of fonts used within a program. In such case, the FontMetrics class proves useful. An object of this class is created by using getFontMetrics() method. The object will contain relevant information about a font including height of a character, width of string in pixels and so on. Q.20) Which one of the following is a valid declaration of an applet? w A. Public class MyApplet extends java.applet.Applet { B. public Applet MyApplet { C. public class MyApplet extends applet implements Runnable { D. public class MyApplet extends java.applet.Applet { w ANSWER : public class MyApplet extends java.applet.Applet { SOLUTION : public class MyApplet extends java.applet.Applet { Explanation:The no-arg constructor is called by the browser when the Web page containing this applet is initially loaded, or reloaded Q.21) The Applet class is in...package A. java.applet B. java.awt C. java.io D. java.util ANSWER : java.applet SOLUTION : Provides the classes necessary to create an applet and the classes an applet uses to communicate with its applet context. The applet framework involves two entities: the applet and the applet context. An applet is an embeddable window (see the Panel class) with a few extra methods that the applet context can use to initialize, start, and stop the applet. The applet context is an application that is responsible for loading and running applets. For example, the applet context could be a Web browser or an applet development environment. Page 6 Questions and Answers Q.22) The constructor for Font class is.. e. co m A. Font(String name) B. Font(string name,int style,int size) C. Font(String name,int size) D. Font(String name,int style) tio A. run B. java C. appletviewer D. applet nl Q.23) To run an applet.command is used. in ANSWER : Font(string name,int style,int size) SOLUTION : Name of the Font can be a particular font such as Times New Roman, Arial and so on. Style can be Font.BOLD, Font.ITALIC etc. These styles are integers in the Font class. For better effects, one can combine two or more of them.pointSize for fonts can be like 11, 12, 14, 16 and so on. Java does not have any fixed height for fonts instead they depend directly on the number of pixels used. For example, a 12 point font in 1280 x 768 resolution screen would be twice as tall as a 12 point font in 640 x 480 resolution. w .a p ANSWER : appletviewer SOLUTION : The appletviewer command connects to the documents or resources designated by urls and displays each applet referenced by the documents in its own window. Note: if the documents referred to by urls do not reference any applets with theOBJECT, EMBED, or APPLET tag, then appletviewer does nothing.. w Q.24) Which of these package is used for handling security related issues in a program? w A. java.security B. java.lang.security C. java.awt.image D. java.io.security ANSWER : java.security SOLUTION : java.security handles certificates, keys, digests, signatures, and other security functions. Q.25) To display text on the applet.method is used. A. showString() B. drawString() C. println() D. printString() ANSWER : drawString() SOLUTION : Returns DrawString for specified text at specified location Q.26) What is the output of this program? import java.lang.reflect.*; class Additional_packages { public static void main(String args[]) { try { Page 7 Class c = Class.forName("java.awt.Dimension"); Method methods[] = c.getMethods(); for (int i = 0; i < methods.length; i++) System.out.println(methods[i]); } catch (Exception e){ System.out.print("Exception"); } } } e. co m Questions and Answers A. Program prints all the constructors of ava.awt.Dimension.package. B. Program prints all the methods of java.awt.Dimension.package. C. Program prints all the data members of java.awt.Dimension package. in D. program prints all the methods and data member of java.awt.Dimension package. w w w .a p tio nl ANSWER : Program prints all the methods of java.awt.Dimension package. SOLUTION : Output: $ javac Additional_packages.java $ java Additional_packages public int java.awt.Dimension.hashCode() public boolean java.awt.Dimension.equals(java.lang.Object) public java.lang.String java.awt.Dimension.toString() public java.awt.Dimension java.awt.Dimension.getSize() public void java.awt.Dimension.setSize(double,double) public void java.awt.Dimension.setSize(int,int) public void java.awt.Dimension.setSize(java.awt.Dimension) public double java.awt.Dimension.getHeight() public double java.awt.Dimension.getWidth() public java.lang.Object java.awt.geom.Dimension2D.clone() public void java.awt.geom.Dimension2D.setSize(java.awt.geom.Dimension2D) public final native java.lang.Class java.lang.Object.getClass() public final native void java.lang.Object.notify() public final native void java.lang.Object.notifyAll() public final native void java.lang.Object.wait(long) public final void java.lang.Object.wait(long,int) public final void java.lang.Object.wait() Q.27) Which method is called first by an applet? A. start() B. run() C. init() D. paint() ANSWER : init() SOLUTION : A method is a named group of Java statements that can be called. It is similar to a subroutine or function in other programming languages. The term init() is a method name in Java. The name is followed by Java code within { and } . A method has a name, such as init, and parentheses, such as ( ). The parentheses may contain arguments if the method is intended to receive some information to use in its statements. The init() method has no arguments inside the parentheses. That means that no data are passed to the init() method. Still, a method must have the parentheses to be identified as a method in Java. Q.28) Which of the following creates a List with 3 visible items and multiple selection disabled? Page 8 Questions and Answers ANSWER : new List(3, false) SOLUTION : Display only 3 record from the list. Q.29) What is the output of this program? w .a p tio nl in import java.lang.reflect.*; class Additional_packages { public static void main(String args[]) { try { Class c = Class.forName("java.awt.Dimension"); Field fields[] = c.getFields(); for (int i = 0; i < fields.length; i++) System.out.println(fields[i]); } catch (Exception e){ System.out.print("Exception"); } } } e. co m A. new List(3, false) B. new List(true, 3) C. new List(3, True) D. new List(false,3) A. Program prints all the constructors of java.awt.Dimension package. B. Program prints all the methods of java.awt.Dimension package. C. Program prints all the data members of java.awt.Dimension package. D. program prints all the methods and data member of java.awt.Dimension package. w w ANSWER : Program prints all the data members of java.awt.Dimension package. SOLUTION : Output: $ javac Additional_packages.java $ java Additional_packages public int java.awt.Dimension.width public int java.awt.Dimension.height Page 9