UNIX / LINUX COMMAND

Friday, September 24, 2010




Short-answer Questions for JAVA

Wednesday, September 15, 2010

1. 	What will be the output of the following code?
		byte x = 64, y;
		y = (byte) (x << 2);
		System.out.println(y);

2. What will be the output of the following code: byte b; double d = 417.35; b = (byte) d; System.out.println(b);
3. Given the value of a variable, write a statement, without using if construct, which will produce the absolute value of the variable.
4. What is wrong with the following code? switch(x) { case 1: n1 = 10; n2 = 20; case 2: n3 = 30; break; n4 = 40; }
5. What will be the output of the following program code? int m = 100; int n = 300; while (++m < — —n); System.out.println(m);
6. What does the following fragment display String s = “six:” + 3 + 3; System.out.println(s);
7. What is the output of the following code? String s; System.out.println(“s = ” + s);
8. What is the output of the following code? String s = new String( ); System.out.println(“s = ” + s);
9. What is the problem with the following snippet? class Q { public static void main(String args[ ]) { int i = 5, j = 10; if ((i<=j)||(i=10)); System.out.println(“OK”); System.out.println(“NOT OK”); } }
10. What will be the output of the following code snippet? int x = 10; int y = 20; if ((x10) System.out.println(x); else System.out.println(y
11. Show the output the following code: int a, b; a = 5; b = 10; if(a > 5) if(b > 5) { System.out.println(“b is ” + b); } else System.out.println(“a is ” + a);
12. State the output of the following code: int a = 10; int b = 5; if(a > b) { if(b > 5) System.out.println(“b is ” + b); } else System.out.println(“a is” + a);
13. Give the output of the following code: int m = 100; while(true) { if(m < 10) break; m = m — 10; } Systm.out.println(“m is ” + m);
14. Give the output of the following code: int m = 100; while(true) { if(m < 10) continue; m = m — 10; } System.out.println(“m is ” + m);
15. Using a single line of code, complete the following class so that it returns x+y if the value of x is equal to y, otherwise returns 0: public class XY { public return int fun(int x, int y) { .......... (one line code her) } }
16. Given a package named EDU.Student, how would you import a class named Test contained in this package? Write one line statement.
17. Consider the following class defi nition: class Student { abstract double result( ) } This code will not compile since a keyword is missing in the fi rst line. What is the keyword?
18. Consider the following class fi le? import java.awt.*; import java.io.*; package studentBase; class Test { void display( ) { System.out.println(“RESULTS”); } } Will it compile? YES or NO. Give reason, if No:
19. Consider the following code: class Product { public static void main(String args [ ]) { int x = 10, y = 20; System.out.println(mu1 (x, y)); } int mul(int a, int b) { return(a * b); } } Will it compile? YES or NO. Give reason, if No:
20. Given below are two fi les: File Employee.java package purchase; public class Employee { protected double age = 35.00; } File Company.java import purchase.Employee; public class Company { public static void main(String arg[ ]) { Employee e = new Employee( ); System.out.println(“Age = ”+e.age); } } Will the fi le Company.java compile? YES or NO. Give reason, if No.
21. Consider the following code: class A { void method(int x) { System.out.println(“x = ” + x); } } class B extends A { void method(int y) { System.out.println(“y = ” + y); } void method(String s) { System.out.println(“s = ” + s); } public static void main(String args[ ]) { A a1 = new A( ); A a2 = new B( ); a1.method(10); a2.method(20); } } What will be the output, when executed?
22. There are three classes that implement and DataInput and DataOutput interfaces. Two of them are DataInputStream and DataOutputStream. Which is the third one?
23. What output will the following program produce? class Bits { public static void main(String args[ ]) { short s1 = 3; // 0000 0011 short s2 = 13; // 0000 1101 s1 = (short) (s1 ^ s2); System.out.println(“Result is”+s1); } }
24. State the output of the following program: class Condition { public static void main(String args[ ]) { int x = 10; int y = 15; System.out.println((x>y)?3.14:3)); } }
25. Which of the classes in java.io package defines a method to delete a fi le?
26. Given a valid File object reference, we can create a new fi le using two classes defi ned in java.io package. One is FileOutputStream class. Which is the other one?
27. If raf is an instance of RandomAccessFile, how can we move the fi le pointer to the end of the fi le? Write the statement
28. What will be the output of the following program when it is executed with the command line java Command Java is wonderful class Command { public staitic void main(String args[ ]) { for(int i = 1; i < args.length; i++) { System.out.print(args[i]); if( i != args.length ) { System.out.print(“ ”); }System.out.println(“ ”); } }
29. What will be the output of the following code snippet when combined with suitable declarations and run? StringBuffer city = new StringBuffer(“Madras”); StringBuffer string = new StringBuffer( ); string.append(new String(city)); string.insert(0, “Central ”); String.out.println(string);
30. Consider the following program code: class Thread1 extends Thread { public void run( ) { System.out.println(“Begin”); suspend( ); resume( ); System.out.println(“End”); } } class ThreadTest { public static void main(String args[ ]) { Thread1 T1 = new Thread1( ); T1.start( ); } } On execution, what will be the output?
31. Consider the following application: class Max { public static void main(String args[ ]) { int max = 10; max(max, 20, 30); System.out.println(max); } static void max(int max, int x1, int x2) { if(x1 > x2) max = x1; else max = x2; } } What value is printed out, when executed?
32. State the output of the following program: class Recur { public static void main(String args[ ]) { int Result = result(10); System.out.println(“Result = ”+Result); } static int result(int m) { if (m <= 2) return m; else return m + result(m—2); } }
33. Consider the class defi nition: class Default { public static void main(String args[ ]) { int m; System.out.println(“m is ” + m); } } Will this code compile? YES or NO. Give reason, if No.
34. What is the output of the following program? class Static { static int m = 0; static int n = 0; public static void main(String args[ ]) { int m = 10; int x = 20; { int n = 30; System.out.println(“m+n=”+m+n); } x = m + n; System.out.println(“x = ” + x); } }
35 Consider the following class defi nitions: class Square { private square( ) { }int area(int side) { return(side * side); } } class Constructor { public static void main(String args[ ]) { Square S1 = new Square( ); int area = S1.area(10); System.out.println(area); } } Will the code above compile and run successfully. YES or NO. Give reason, if No.
36. Write a statement to draw a rounded rectangle with the following features: width = 200 height = 100 corner horizontal diameter = 20 corner vertical diameter = 40 Select a suitable upper-left corner of the rectangle
37. Which line of the following HTML fi le contains an error? 1. < applet 2. WIDTH = 400 HEIGHT = 200 3. CODE = HelloJava.Class > 4. < param 5. NAME = “string” 6. VALUE = “Hello” >
38. Give the output of the following program: class MainString { public static void main(String args[ ]) { StringBuffer s = new StringBuffer(“String”); if(s.length()>5) && (s.append(“Buffer”).equals(“X”); // empty statement System.out.println(s); } }
39. What is the range of the value that can be assigned to a variable of type long?
40. Consider the following program : class Number { int x; void store(Number num) { num.x++; } } class MainNumber { public static void main(String args[ ]) { Number n = new Number( ); n.x = 10; n.store(n); System.out.println(n.x); } } What is the output?
41. Given the code: class Continue { public static void main(String args[ ]) { int m = 0; loop1: for(int i=0; i<10; i++) loop2: for(int j=0;j<10;j++) loop3: for(int k=0;k<10;k++) { System.out.println(++m); if( (k%10) == 0) continue loop2; } } } What is the last value printed?
42. Can an abstract method by declared fi nal? YES or NO. If NO, give reason.
43. Can an abstract method be declared static? YES or NO. If NO, give reason.
44. Consider the following try ... catch block: class TryCatch { public static void main(String args[ ]) { try { double x = 0.0; throw(new Exception(“Thrown”)); return; } catch(Exception e) { System.out.println(“Exception caught”); return; } fi nally { System.out.println(“fi nally”); } } } What will be the output?
45. Write a statement that would construct a 20 point bold Helvetica font.

Multiple-choice Questions for JAVA

Wednesday, September 8, 2010








1.         The range of values for the long type data is
A. –231 to 231 – 1         B. –264 to 264
C. –263 to 263 – 1         D. –232 to 232 – 1
2.         Which of the following represent(s) of a hexadecimal number?
A. 570                           B. (hex) 5
C. 0X9F                        D. 0X5
3.         Which of the following assignments are valid?
A. fl oat x = 123.4;        B. long m = 023;
C. int n = (int)false;        D. double y = 0X756;
                                                                                        
4.         The default value of char type variable is
A. ‘\u0020’                     B. ‘\u00ff
C. “ “                             D. ‘\u0000’
5.         What will be the result of the expression 13 & 25?
A. 38                            B. 25
C. 9                              D. 12
6.         What will be result of the expression 9 | 9?
A. 1                              B. 18
C. 9                              D. None of the above
7.         Which of the following are correct?
A. int a = 16, a >> 2 = 4
B. int b = –8, b >> 1 = –4
C. int a = 16, a >>> 2 = 4
D. int b = –8, b >>> 1 = – 4
E. All the above
8.         What will be the values of x, m, and n after execution of the
 following statements?
int x, m, n;
m = 10;
n = 15;
x = ++m + n++;
A. x = 25, m = 10, n = 15           B. x = 27, m = 10, n = 15
C. x = 26, m = 11, n = 16           D. x = 27, m = 11, n = 16
9.         If m and n are int type variables, what will be the result of
the expression
m % n
when m = 5 and n = 2?
A. 0                  B. 1
C. 2                  D. None of the above
10.        If m and n are int type variables, what will be the result of
the expression
m % n
when m = – 14 and n = –3?
A. 4                 B. 2     
C. –2                D. –4
E. None of the above
11.        Consider the following statements:
Int x = 10, y = 15;
x = ( (x
What will be the value of x after executing these statements?
A. 10                B. 25
 C. 15               D. 5
 E. Error. Cannot be executed.
12.        Which of the following operators are overloaded for String objects?
A. –                  B. +
C. + =               D. &
 E. <<               F. None of these
13.        What is the result of the expression
(1 & 2) + (3 | 4)
in base ten.
A. 1                  B. 2
 C. 8                 D. 7
 E. 3
14.        Which of the following will produce a value of 22 if x = 22.9?
A. ceil(x)           B. round(x)
C. rint(x)            D. abs(x)
 E. fl oor(x)
15.        Which of the following will produce a value of 10 if x = 9.7?
A. fl oor(x)        B. abs(x)
 C. rint(x)           D. round(x)
 E. ceil(x)
16.        Which of the following expressions are illegal?
A. (10 | 5)          B. (false && true)
C. boolean x = (boolean)10;
D. fl oat y = 12.34;
17.        Which of the following lines will not compile?
1. byte b1 = 5, b2 = 3, b3;
2. short s = 25;
3. b2 = s;
            4. b3 = b1 * b2;
            A. Line 1 only                B. Line 3 only
            C. Line 4 only
            D. Line 1 and Line 4 only
             E. Line 3 and Line 4 only
18. Which of the following are illegal loop constructs?
            A. while(int i > 0)
                {i- -; other statements;}
            B. for(int i = 10, int j = 0; i+j > 5; i = i–2, j++)
                {
                        Body statements
                }
            C. int i = 10;
                while (i)
               {
                        Body statements
               }
            D. int i = 1, sum = 0;
               do {loop statements}
                while(sum < 10 || i<5);
19.        Consider the following code
                if (number >= 0)
                if (number > 0)
                System.out.println (“Number is positive”) ;
                else
                System.out.println (“Number is negative”) ;
            What will be the output if number is equal to 0?
            A. Number is negative               B. Number is positive
            C. Both A and B                                    D. None of the above
20.        Which of the following control expressions are valid for an if statement?
            A. an integer expression                        B. a boolean expression
            C. either A or B                                     D. Neither A nor B
21.        In the following code snippet, which lines of code contain error?
            1. int j = 0;
            2. while(j < 10) {
            3. j+ +;
            4. if(j = = 5) continue loop;
            5. System.out.println(“j is” + j); }
            A. Line 2                       B. Line 3          
             C. Line 4                      D. Line 5
             E. None of the above
22.        Consider the following code:
                char c = ‘a’ ;
                switch (c)
                {
                                case ‘a’ :
                                System.out.println (“A”) ;
                                case ‘b’ :
                                System.out.println (“B”) ;
                                default:
                                System.out.println (“C”) ;
                }
            For this code, which of the following statement is true?
            A. output will be A
            B. output will be A followed by B
            C. output will be A, followed by B, and then followed by C
            D. code is illegal and therefore will not compile
23.        Consider the following class defi nition.
                class Student extends String
                {}
            What happens when we try to compile this class?
            A. Will not compile because class body is not defi ned
            B. Will not compile because the class is not declared public
            C. Will not compile because String is abstract
            D. Will not compile because String is fi nal
            E. Will compile successfully.
24.        What is wrong in the following class defi nitions?
                abstract class Print
                {
                                abstract show ( ) ;
                }
                class Display extends Print
                {}
            A. Nothing is wrong
            B. Wrong. Method show( ) should have a return type
            C. Wrong. Method show( ) is not implemented in Display
            D. Wrong. Display does not contain any members
25.        What is the error in the following class defi nition?
                abstract class XY
                {
                                abstract sum (int x, int y) { }
                }
            A. Class header is not defi ned properly
            B. Constructor is not defi ned
            C. Method is not defi ned properly
            D. No error
26.        Consider the following class defi nitions:
                class maths
                {
                                Student student1;
                }
                class Student
                {
                                String name;
                }
            This code represents:
            A. an ‘is a’ relationship
            B. a ‘has a’ relationship
            C. both                                     D. neither
27.        Consider the following class defi nition:
                class A extends B
                {
                                public A (int x) { }
                                public A (int x, int y)
                                {
                                                super (x, y) ;
                                }
                }
            Which of the following are legal statements to construct A type objects?
            A. A a = new A( );
            B. A a = new A(4, 2, 7);
            C. A a = new A(5, 6);
            D. A a = new A(10);
            E. A a = new A(Base(4, 5), 6);
28.        Which of the following are overloading the method
                int sum(int x, int y) { }
            A. int sum(int x, int y, int z) { }
            B. fl oat sum(int x, int y) { }
            C. int sum(fl oat x, fl oat y) { }
            D. int sum(int a, int b) { }
            E. fl oat sum(int x, int y, fl oat z) { }
            29. What is the error in the following code?
                class Test
                {
                                abstract void display ( ) ;
                }
            A. No error
            B. Method display( ) should be declared as static
            C. Test class should be declared as abstract    
            D. Test class should be declared as public
30.        Which of the following statements are true?
            1. We cannot use abstract classes to instantiate objects directly.
            2. The abstract methods of an abstract class must be defi ned in its subclass.
            3. We cannot declare abstract constructors.      
            4. We may declare abstract static methods.
            A. Line 1 only                B. Line 2 only
            C. Line 1 and line 2 only
             D. Line 1, line 2 and line 3 only
            E. All are true
31.        Which keyword can protect a class in a package from accessibility by
            the classes outside the package?
            A. private
            B. protected
            C. fi nal
            D. don’t use any keyword at all (make it default)
32.        We would like to make a member of a class visible in all subclasses regardless of what package
            they are in. Which one of the following keywords would achieve this?
            A. private                      B. protected
            C. public                       D. private protected
33.        The use of protected keyword to a member in a class will restrict its visibility as follows:
            A. Visible only in the class and its subclass in the same package.
            B. Visible only inside the same package.
            C. Visible in all classes in the same package and subclasses in other packages
            D. Visible only in the class where it is declared.
34.        Which of the following are not keywords?
            A. NULL                        B. implements
            C. protected                  D. extended
            E. string
35.        Which of the following are keywords?
            A. switch                       B. integer
             C. default                     D. boolean
            E. object
36.        Which of the following keywords are used to control access to a class member?
            A. default                      B. abstract
             C. protected                 D. interface
             E. public
37.        The keywords reserved but not used in the initial version of Java are:
            A. union                        B. const
            C. inner                         D. goto
            E. boolean                    F. synchronized
38.        Consider the following code:
                class ClassA
                {
                                public static void main (String args [ ] )
                                {
                                                ClassB b = classB ( ) ;
                                }
                                ClassA (int x) { }
                }
                class ClassB extends ClassA
                {}
            What will happen when we compile and run this code?
            A. Compile and run successfully
            B. Error. ClassA does not defi ne a no-argument constructor
            C. Error. ClassB does not defi ne a no-argument constructor
            D. Error. There is no code in the class ClassB
            E. Error. There is no code in the constructor ClassA (int x)
39.        A package is a collection of
            A. classes                     B. interfaces
            C. editing tools
            D. classes and interfaces
40.        Which of the following statements are true?
            A. An abstract class may not have any fi nal methods.
            B. A fi nal class may not have any abstract methods.
            C. An inner class may be declared with any accessibility keyword.
            D. Transient variables must be static.
41.        Which of the following defi nes a legal abstract class?
            A. class Vehicle {
                        abstract void display( ); }
            B. abstract Vehicle {
                        abstract void display( ); }
            C. abstract class Vehicle {
                        abstract void display( ); }
            D. class abstract Vehicle {
                        abstract void display( ); }
            E. abstract class Vehicle {
                        abstract void display( ); {
                        System.out.println(“Car”); }}
42.        Package p1 contains the following code:
                package p1;
                public class Student { Body of student }
                class Test { Body of Test }
            Now consider the following code:
                import p1.*;
                class Result
                {
                                Student s1;
                                Test t1;
                }
            This code will not compile because       
            A. Class Result should be declared public.
            B. Student class is not available.
            C. Test class is not available.
            D. Result body is not fully defi ned.
43.        Consider the following code:
                interface Area
                {
                                fl oat compute (fl oat x, fl oat y) ;
                }
                class Room implements Area
                {
                                fl oat compute (fl oat x, fl oat y)
                                {
                                                return (x & y) ;
                                }
                }
            What is wrong with the code?
            A. Interface defi nition is incomplete
            B. Method compute( ) in interface Area should be declared public
            C. Method compute( ) in class Room should be declared public
            D. All the above
44.        The concept of multiple inheritance is implemented in Java by
            A. extending two or more classes
            B. extending one class and implementing one or more interfaces
            C. implementing two or more interfaces
            D. all the above
45.        Which of the following statements are valid array declaration?
            A. int number( );
            B. fl oat average[ ];
            C. double[ ] marks;
            D. counter int[ ];
46.        Consider the following code
                int number [ ] = new int [5] ;
            After execution of this statement, which of the following are true?
            A. number[0] is undefi ned
            B. number[5] is undefi ned
            C. number[4] is null
            D. number[2] is 0
            E. number.length( ) is 5
47.        What will be the content of array variable table after executing the following code?
                for (int i=0; i<3; i++)
                for (int j=0, j<3; j++)
                if (j == i) table [i] [j] = 1;
                else table [i] [j] = 0;
            A. 0 0 0
            B. 1 0 0
            C. 0 0 1
                D. 1 0 0 0 0 0 1 1 0 0 1 0 0 1 0 0 0 0 1 1 1 1 0 0 0 0 1
48.        Which of the following classes are available in the java.lang package?
            A. Stack            B. Object
            C. Math             D. Random
            E. String           F. StringBuffer
            G. Vector
49.        Which of the following are the wrapper classes?
            A. Random       B. Byte
             C. Vector         D. Integer
             E. Short           F. Double
            G. String
50.        Which of the following contain error?
            A. int x[ ] = int[10];
            B. int[ ] y = new int[5];
            C. fl oat d[ ] = {1, 2, 3};
            D. x = y = new int [10];
            E. int a[ ] = {1, 2}; int b[ ]; b = a;
            F. int i = new int(10);
51.        Which of the following methods belong to the String class?
            A. length( )        B. compareTo( )
            C. equals( )       D. substring( )
             E. All of them   F. None of them
52.        Given the code
                String s1 = “yes”;
                String s2 = “yes”;
                String s3 = new String (s1) ;
            Which of the following would equate to true?
            A. s1 = = s2
            B. s1 = s2
             C. s3 = = s1
            D. s1.equals(s2)
             E. s3.equals(s1)
53.        Suppose that s1 and s2 are two strings. Which of the statements or expressions are correct?
            A. String s3 = s1 + s2;
            B. String s3 = s1 – s2;
            C. s1 <= s2
            D. s1.compareTo(s2);
             E. int m = s1.length( );
54.        Given the code
                String s = new String (“abc”) ;
            Which of the following calls are valid?
            A. s.trim( )
             B. s.replace(‘a’, ‘A’)
            C. s.substring(3)
            D. s.toUpperCase( )
            E. s.setCharAt(1,‘A’)
            F. s.append(“xyz”)
55.        The methods wait( ) and notify( ) are defi ned in
            A. java.lang.String
            B. java.lang.Runnable
            C. java.lang.Object
            D. java.lang.Thread
            E. java.lang.ThreadGroup
56.        Which of the following statements are true?
            A. A Java monitor must either extend Thread or implement Runnable.
            B. The sleep( ) method should be enclosed in try ... catch block.
            C. The yield( ) method should be enclosed in try ... catch block.
            D. A thread can be temporarily suspended from running by using the wait( ) method.
            E. A suspended thread using suspend( ) method can be revived using the resume( ) method.
57.        Given the following code:
                class Base { int x = 10; }
                class Derived extends Base
                { int x = 20; }
                Base b = new Base ( ) ;
                Derived d = new Derived( ) ;
                Base bd = new Derived( ) ;
            The statement
                System.out.println (b.x + “ ” + d.x + “ ” + bd.x) ;
            will produce the output
            A. 10 20 20
            B. 10 20 10
            C. 20 10 20
            D. 20 20 10
58.        Given the class defi nitions
                class Base
                {
                                void display( )
                                { System.out.println (“Base”) ; }
                }
                class Derived extends Base
                {
                                void display ( )
                                { System.out.println (“Derived”) ; }
                }
            and objects
                Base b = new Base( );
                Derived d = new Derived( );
                Base bd = new Derived( );
            then the print statements
                System.out.print(b.display( ) + “ ”);
                System.out.print(d.display( ) + “ ”);
                System.out.print(bd.display( ) + “ ”);
                System.out.println( );
            will display:
            A. Base Base Derived
            B. Base Derived Base
            C. Base Derived Derived
            D. Derived Derived Derived
59.        When we invoke repaint( ) for a Component, the AWT invokes the method:
            A. draw( )          B. show( )
            C. update( )       D. paint( )
60.        What does the following line of code do?
                TextField text = new TextFiled(10);
            A. Creates text object that can hold 10 rows of text.
            B. Creates text object that can hold 10 columns of text.
            C. Creates the object text and initializes it with the value 10.
            D. The code is illegal.
61.        Which of the following applet tags is legal to embed an applet class named Test into a Web        page?
            A. < applet
            class = Test width = 200 height = 100>
            < /applet>
            B. < applet>
            code = Test.class width = 200 height = 100>
            < /applet>
            C. < applet
            code = Test.class width = 200 height = 100
            < /applet>
            D. < applet
            param = Test.class width = 200 height = 100>
            < /applet>
            E. < applet
            code = Test.class width = 200 height = 100>
            < / applet>
62.        Which of the following methods can be used to draw the outline of a square?
            A. fi llRect( )                  B. drawLine( )
            C. drawRect( )               D. drawString( )
            E. drawPolygon( )
63.        Which of the following methods can be used to change the size of a component
            A. dimension( )              B. setSize( )
            C. area( )                       D. size( )
            E. resize( )
64.        Which of the following methods can be used to remove a component from the display?
            A. delete( )                    B. remove( )
             C. disappear( )             D. hide( )
            E. move( )
65.        The setBackground( ) method is part of the class
            A. Graphics                   B. Applet
             C. Component              D. Container
            E. Object
66.        When we implement the Runnable interface, we must defi ne the method
            A. start( )                      B. init( )
            C. run( )                        D. runnable( )
             E. resume( )                 F. main( )
67.        Which of the following strings can be used as mode strings for creating a RandomAccessFile     object?
            A. “ r ”                           B. “ w ”
             C. “ rw ”                        D. “ wr ”
             E. “ 0 ”
68.        What will be the output of the following program?
                class Main1
                {
                                public static void main(String args [ ])
                                {
                                                boolean b = true;
                                                System.out.println(“XXX”);
                                                return;
                                                System.out.println(“YYY”);
                                }
                }
            A. XXX
            B. YYY
            C. XXX followed by YYY
            D. Error. Won’t compile
69.        What will be output of the following program?
                class Main2
                {
                                public static void main(String args[ ])
                                {
                                                boolean b = true;
                                                System.out.println(“XXX”);
                                                if( !b ) return;
                                                System.out.println(“YYY”);
                                }
                }
            A. XXX
            B. YYY
            C. XXX followed by YYY
            D. Error. Won’t compile
70.        DataInput is
            A. an abstract class defi ned in java.io.
            B. a class we can use to read primitive data types.
            C. an interface that defi nes methods to open fi les.
            D. an interface that defi nes methods to read primitive data types.
71.        Which of the following statements are true?
            A. Unicode characters are all 16 bits.
            B. UTF characters are all 24 bits.
            C. Reader class has methods that can read integers and fl oats.
            D. File class may be used to rename a fi le.
            E. DataOutputStream objects are used to write primitive data to a fi le.
72.        Which are the valid ways to create DataInputStream streams?
            A. new DataInputStream( );
            B. new DataInputStream(“in.dat”, “r”);
            C. new DataInputStream(“in.dat”)
            D. new DataInputStream(new File(“in.dat”));
            E. new DataInputStream(new FileInputStream(“in.dat”);
73.        Which exception is thrown by the read( ) method of InputStream class?
            A. Exception                 B. FileNotFoundException
            C. ReadException         D. IOException
            E. None of the above
74.        In the code below, what data types the variable x can have?
                byte b1 = 5;
                byte b2 = 10;
                x = b1 * b2;
            A. byte                         B. int
             C. short                       D. long
             E. fl oat                       F. double
75.        If you want to assign a value of 99 to the variable year, then which of the following lines can be   used within an tag?
            A. number = getParameter(99)
            B. < number = 99 >
            C. < param = radius value = 99 >
            D. < param name = number value = 99 >
            E. < param number = 99 >
76.        What is java_g used for?
            A. Using the jdb tool
            B. Executing a class with optimization turned off
            C. To provide information about deprecated methods
            D. None of the above
77.        With javadoc, which of the following denotes a javadoc comment?
            A. //#                B. /*
            C. /**                D. //**
78.        Given fi le is a File object, which of the following are legal statements to create a new fi le
            A. fi le.create( );
            B. FileOutputStream fos = new FileOutputStream(fi le);
            C. FileWriter out = new FileWriter(fi le);
            D. FileInputStream fi s = new FileInputStream(fi le);
            E. RandomAccessFile raf = new RandomAccessFile(fi le);
79.        Which javadoc tage is used to denote a comment for a method parameter?
            A. @method                 B. @parameter
            C. @argument               D. @param
            E. @value
80.        Which of the following command lines options generates documentation for all classes and       methods?
            A. –protected                B. –public
             C. –private                   D. –verbose
             E. –encoding
81.        Given the declarations
                int x, m = 2000;
                short y;
                byte b1 = —40, b2;
                long n;
            which of the following assignment statements will evaluate correctly?
            A. x = m * b1;  
            B. y = m * b1;
            C. n = m * 3L;
            D. x = m * 3L;
82.        Given the declarations
                boolean b;
                short x1 = 100, x2 = 200, x3 = 300;
            Which of the following statements are evaluated to true?
            A. b = x1 * 2 = x2;
            B. b = x1 + x2 != 3 * x1;
            C. b = (x3 – 2*x2<0) || ((x3 = 400) <2**x2);
            D. b = (x3 – 21*x2>0) || (x3 = 400) 2*x2);
83.        In which of the following code fragments, the variable x is evaluated to 8.
            A. int x = 32;’                B. int x = 33;
                x = x > > 2;                   x = x > > 2;
            C. int x = 35;                 D. int x = 16;
                 x = x > > 2;                   x = x > > 1;
84.        Consider the following code snippet:
                .....
                .....
                try {
                                int x = 0;
                                int y = 50/x;
                                System.out.println(“Division by zero”);
                     }
                catch(ArithmeticException e) {
                System.out.println(“catch block”);
                }
                .....
                .....
            What will be the output?
            A. Error. Won’t compile
            B. Division by zero
            C. Catch block
            D. Division by zero
            Catch block
85.        Which of the following represent legal fl ow control statements?
            A. break;                       B. break( );       
            C. continue outer;          D. continue(inner);
            E. return;                       F. exit( );


ANSWARS OF MULTIPLE-CHOICE QUESTIONS
1. C
2. D & E
3. B & D
4. D
5. C
6. C
7. A B& C
8. C
9. B
10. C
11. B
12. B & C
13. D
14. C & E
15. D & E
16. C & B
17. E
18. A & C
19. A
20. B
21. A
22. B
23. D
24. C
25. C
26. B
27. C & D
28. A C & E
29. C
30. D
31. D
32. D
33. C
34. A D & E
35. A & C
36. B C & E
37. B C & D
38. B
39. D
40. B & C
41. C
42. C
43. C
44. B & C
45. B & C
46. B D & E
47. D
48. B C E & F
49. B D E & F
50. A D& F
51. E
52. A D & E
53. A D& E
54. A B C & D
55. C
56. B D & E
57. B
58. C
59. C
60. B
61. E
62. B C & E
63. B & E
64. D
65. C
66. C
67. A & C
68. D
69. C
70. D
71. A D & E
72. E
73. D
74. B D E & F
75. D
76. B
77. C
78. B C & E
79. D
80. C
81. A & C
82. A & C
83. A B C & D
84. C
85. A C & E