NOTE - THIS IS NOT A PRACTICE EXAM. IT IS AN OLD EXAM. Final CS/EECS 284 --- Java Nov. 20, 1996 (1) (10 pts) Briefly explain what each of these Java keywords does. this super catch new implements private static class instanceof (2) (5 pts) Write an application that prints "I will get an A in Java" on the screen. (3) (5 pts) Write an applet that prints "I will get an A in Java" on the applet. (4) (10 pts) List 10 style rules you followed when writing (2) and (3). (5) (5 pts) Write an applet tag that would include the applet you wrote in (3) and which will write a message if the user does not have a Java enabled browser. (6) (15 pts) Tell which method in the following applet each line of code below belongs to. _______ g.drawChars(separated, i,1,x_coord,y_coord); _______ killme = new Thread(this); _______ s = getParameter("text"); _______ int y_coord = (int) (Math.random() *10 +36); _______ try {Thread.sleep(100);} _______ return true; _______ killme.start(); _______ threadSuspended = !threadSuspended; _______ repaint(); _______ resize(150,50); _______ if (s == null) s = "HotJava"; _______ int x_coord = (int) (Math.random() *10 +15 * i); _______ catch (InterruptedException e){} _______ killme = null; _______ setFont(new Font("TimesRoman",Font.BOLD,36)); /* Daniel Wyszynski Center for Applied Large-Scale Computing (CALC) 04-12-95 kwalrath: Changed string; added thread suspension. 5-9-95 */ import java.awt.*; public class NervousText extends java.applet.Applet implements Runnable { char separated[]; String s = null; Thread killme = null; boolean threadSuspended = false; //added by kwalrath public void init() { separated = new char [s.length()]; s.getChars(0,s.length(),separated,0); } // init public void start() { if(killme == null) { } } // start public void stop() { } // stop public void run() { while (killme != null) { } } // run public void paint(Graphics g) { for(int i = 0; i < s.length(); i++) { } } // paint /* Added by kwalrath. */ public boolean mouseDown(Event evt, int x, int y) { if (threadSuspended) killme.resume(); else killme.suspend(); } // mouseDown } // applet (7) (20 pts) True and False (write 0 for false and any other value for true) ____ You invoke a method by sending an object a message. ____ Threads are light weight processes. ____ Java is only good for writing applets. ____ An instance of a class is an object. ____ Class methods can only be called with class names. ____ Overloading is bad style. ____ Constructors can call other constructors. ____ An applet is always repainted immediately when repaint() is called. ____ Overriding update() is one way to reduce flicker. ____ Clipping lets you restrict the drawing area to just part of the screen. ____ The first element in a Java array is accessed with [1]. ____ The Neko applet in the book is a bird animation. ____ Double buffering is one way to reduce flicker. ____ The handleEvent method handles only mouse events. ____ The CheckboxGroup class is used to create a series of radio buttons. ____ A modal dialog prevents input to other windows until it is dismissed. ____ A class defined with the keyword final cannot be subclassed. ____ A variable defined with the keyword final cannot be changed. ____ Polymorphic abstract native interfaces will cause multiple overloads. ____ Threads rule! (8) (10 pts) List 10 Java components. (9) (5 pts) List the 3 kinds of variables in Java and give an example of each. (10) (5 pts) List the 3 methods used for controlling sounds and tell which interface they belong to.