Anda di halaman 1dari 8

1. What is hash-collision in Hashtable and How it is handled in Java? A. Two different keys with the same hash value.

Two different entries will be kept in a single hash bucket to avoid the collision. 2. What are the different driver types available in JDBC? B. A JDBC-ODBC bridge A native-API partly Java technology-enabled driver A net-protocol fully Java technology-enabled driver A native-protocol fully Java technology-enabled driver 3 . StringBuffer sb1 = new StringBuffer("Amit"); StringBuffer sb2= new StringBuffer("Amit"); String ss1 = "Amit"; System.out.println(sb1==sb2); System.out.println(sb1.equals(sb2)); System.out.println(sb1.equals(ss1)); System.out.println("Poddar".substring(3)); a) false false false dar 4. What is the output of following if the return value is "the value 0 if the argument string is equal to this string; a value less than 0 if this string is lexicographically less than the string argument; and a value greater than 0 if this string is lexicographically greater than the string argument" (Assuming written inside main) String s5 = "AMIT"; String s6 = "amit"; System.out.println(s5.compareTo(s6)); System.out.println(s6.compareTo(s5)); System.out.println(s6.compareTo(s6)); a >-32 32 0 5) What is the output (Assuming written inside main) String s1 = new String("amit"); String s2 = s1.replace('m','i'); s1.concat("Poddar"); System.out.println(s1); System.out.println((s1+s2).charAt(5)); d) amit i 6) What is the output (Assuming written inside main) String s1 = new String("amit"); System.out.println(s1.replace('m','r')); System.out.println(s1); String s3="arit"; String s4="arit"; String s2 = s1.replace('m','r'); System.out.println(s2==s3); System.out.println(s3==s4); a) arit amit false true 7) Which one does not extend java.lang.Number 2)Boolean 3)Character 8) Which one does not have a valueOf(String) method 3)Character

9) What is the output of following (Assuming written inside main) String s1 = "Amit"; String s2 = "Amit"; String s3 = new String("abcd"); String s4 = new String("abcd"); System.out.println(s1.equals(s2)); System.out.println((s1==s2)); System.out.println(s3.equals(s4)); System.out.println((s3==s4)); a) true true true false 10. Which checkbox will be selected in the following code ( Assume with main and added to a Frame) Frame myFrame = new Frame("Test"); CheckboxGroup cbg = new CheckboxGroup(); Checkbox cb1 = new Checkbox("First",true,cbg); Checkbox cb2 = new Checkbox("Scond",true,cbg); Checkbox cb3 = new Checkbox("THird",false,cbg); cbg.setSelectedCheckbox(cb3); myFrame.add(cb1); myFrame.add(cb2); myFrame.add(cb3); d) cb3 11) Which checkbox will be selected in the following code ( Assume with main and added to a Frame) Frame myFrame = new Frame("Test"); CheckboxGroup cbg = new CheckboxGroup(); Checkbox cb1 = new Checkbox("First",true,cbg); Checkbox cb2 = new Checkbox("Scond",true,cbg); Checkbox cb3 = new Checkbox("THird",true,cbg); myFrame.add(cb1); myFrame.add(cb2); myFrame.add(cb3); d) cb3 12) What will be the output of line 5 1 Choice c1 = new Choice(); 2 c1.add("First"); 3 c1.addItem("Second"); 4 c1.add("Third"); 5 System.out.println(c1.getItemCount()); c) 3 13) What will be the order of four items added Choice c1 = new Choice(); c1.add("First"); c1.addItem("Second"); c1.add("Third"); c1.insert("Lastadded",2); System.out.println(c1.getItemCount()); c) Lastadded,First,Second,Third 14) Answer based on following code 1 Choice c1 = new Choice(); 2 c1.add("First"); 3 c1.addItem("Second"); 4 c1.add("Third"); 5 c1.insert("Lastadded",1000); 6 System.out.println(c1.getItemCount()); d) No error and line 6 will print

15) Which one of the following does not extends java.awt.Component.. ans c a) CheckBox b) Canvas C) CHECKBOCGROUP d) Label 16) What is default layout manager for panels and applets? a) Flowlayout 17. For awt components which of the following statements are true?A,B,C a) If a component is not explicitly assigned a font, it usese the same font that it container uses. b) If a component is not explicitly assigned a foreground color, it usese the same foreground color that it container uses. c) If a component is not explicitly assigned a backround color , it usese the same background color that it container uses. d) If a component is not explicitly assigned a layout manager , it usese the same layout manager that it container uses. 18) java.awt.Component class method getLocation() returns Point (containg x and y cordinate).What does this x and y specify B a) Specify the postion of components lower-left component in the coordinate space of the component's parent. B) SPECIFY THE POSTION OF COMPONENTS UPPER-LEFT COMPONENT IN THE COORDINATE SPACE OF THE COMPONENT'S PARENT. c) Specify the postion of components upper-left component in the coordinate space of the screen. 19. What will be the output of follwing { double d1 = -0.5d; System.out.println("Ceil for d1 " + Math.ceil(d1)); System.out.println("Floor for d1 " +Math.floor(d1)); } d) Ceil for d1 -0.0 Floor for d1 -1.0; 20. What is the output of following { float f4 = -5.5f; float f5 = 5.5f; float f6 = -5.49f; float f7 = 5.49f; System.out.println("Round f4 is " + Math.round(f4)); System.out.println("Round f5 is " + Math.round(f5)); System.out.println("Round f6 is " + Math.round(f6)); System.out.println("Round f7 is " + Math.round(f7)); } b) Round f4 is -5 Round f5 is 6 Round f6 is -5 Round f7 is 5 21. Given Integer.MIN_VALUE = -2147483648 Integer.MAX_VALUE = 2147483647 What is the output of following { float f4 = Integer.MIN_VALUE; float f5 = Integer.MAX_VALUE; float f7 = -2147483655f; System.out.println("Round f4 is " + Math.round(f4)); System.out.println("Round f5 is " + Math.round(f5)); System.out.println("Round f7 is " + Math.round(f7)); } a) Round f4 is -2147483648 Round f5 is 2147483647 Round f7 is -2147483648

22) If 1 Boolean b1 = new Boolean("TRUE"); 2 Boolean b2 = new Boolean("true"); 3 Boolean b3 = new Boolean("JUNK"); 4 System.out.println("" + b1 + b2 + b3); c) Truetruefalse 23) In the above question if line 4 is changed to System.out.println(b1+b2+b3); The output is a) Compile time error Q24. What is the output { Float f1 = new Float("4.4e99f"); Float f2 = new Float("-4.4e99f"); Double d1 = new Double("4.4e99"); System.out.println(f1); System.out.println(f2); System.out.println(d1); } b) Infinity -Infinity 4.4E99 25. Which of the following wrapper classes can not take a "String" in constructor D 1) Boolean 2) Integer 3) Long 4) CHARACTER 5) Byte 6) Short 26. What is the output of following Double d2 = new Double("-5.5"); Double d3 = new Double("-5.5"); System.out.println(d2==d3); System.out.println(d2.equals(d3)); d) false true 27) Which one of the following always honors the components's preferred size. a) FlowLayout 28) Look at the following code import java.awt.*; public class visual extends java.applet.Applet{ static Button b = new Button("TEST"); public void init(){ add(b); } public static void main(String args[]){ Frame f = new Frame("Visual"); f.setSize(300,300); f.add(b); f.setVisible(true); } } What will happen if above code is run as a standalone application..C a) Displays an empty frame b) Displays a frame with a button covering the entire frame C) DISPLAYS A FRAME WITH A BUTTON LARGE ENOUGH TO ACCOMODATE ITS LABEL. 29 If the code in Q33 is compiled and run via appletviewer what will happenA A) DISPLAYS AN EMPTY APPLET b) Displays a applet with a button covering the entire frame c) Displays a applet with a button large enough to accomodate its label.

30. What is the output public static void main(String args[]){ Frame f = new Frame("Visual"); f.setSize(300,300); f.setVisible(true); Point p = f.getLocation(); System.out.println("x is " + p.x); System.out.println("y is " + p.y); } b) x is 0 y is 0 31) Which one of the following always ignores the components's preferred sizeB a) FlowLayout B) GRIDLAYOUT c) BorderLayout 32) Consider a directory structure like this (NT or 95) C:\JAVA\12345.msg --FILE \dir1\IO.class -- IO.class is under dir1 Consider the following code import java.io.*; public class IO { public static void main(String args[]) { File f = new File("..\\12345.msg"); try{ System.out.println(f.getCanonicalPath()); System.out.println(f.getAbsolutePath()); }catch(IOException e){ System.out.println(e); } } } What will be the output of running "java IO" from C:\java\dir1 c) C:\java\dir1\..\12345.msg C:\java\dir1\..\12345.msg 33) Suppose we copy IO.class from C:\java\dir1 to c:\java What will be the output of running "java IO" from C:\java. b) C:\12345.msg C:\java\..\12345.msg 34) Which one of the following methods of java.io.File throws IOException and whyB a) getCanonicalPath and getAbsolutePath both require filesystem queries. B) ONLY GETCANNONICALPATH AS IT REQUIRE FILESYSTEM QUERIES. c) Only getAbsolutePath as it require filesystem queries. 35) What will be the output if Consider a directory structure like this (NT or 95) C:\JAVA\12345.msg --FILE \dir1\IO.class -- IO.class is under dir1 import java.io.*; public class IO { public static void main(String args[]) { File f = new File("12345.msg"); String arr[] = f.list(); System.out.println(arr.length); } } b) java.lang.NullPointerException at run time 36) What will be the output Consider a directory structure like this (NT or 95) C:\JAVA\12345.msg --FILE import java.io.*; public class IO {

public static void main(String args[]) { File f1 = new File("\\12345.msg"); System.out.println(f1.getPath()); System.out.println(f1.getParent()); System.out.println(f1.isAbsolute()); System.out.println(f1.getName()); System.out.println(f1.exists()); System.out.println(f1.isFile()); } } d) \12345.msg \ true 12345.msg false false 37) If in question no 41 the line File f1 = new File("\\12345.msg"); is replaced with File f1 = new File("12345.msg"); What will be the output c) 12345.msg null false 12345.msg true true 38. What will happen when you attempt to compile and run this code? abstract class Base{ abstract public void myfunc(); public void another(){ System.out.println("Another method"); } } public class Abs extends Base{ public static void main(String argv[]){ Abs a = new Abs(); a.amethod(); } public void myfunc(){ System.out.println("My Func"); } public void amethod(){ myfunc(); }} 1) THE CODE WILL COMPILE AND RUN, PRINTING OUT THE WORDS "MY FUNC" 2) The compiler will complain that the Base class has non abstract methods 3) The code will compile but complain at run time that the Base class has non abstract methods 4) The compiler will complain that the method myfunc in the base class has no body, nobody at all to loop it 39. What will happen when you attempt to compile and run this code? public class MyMain{ public static void main(String argv){ System.out.println("Hello cruel world"); }} 1) The compiler will complain that main is a reserved word and cannot be used for a class 2) The code will compile and when run will print out "Hello cruel world" 3) The code will compile but will complain at run time that no constructor is defined 4) THE CODE WILL COMPILE BUT WILL COMPLAIN AT RUN TIME THAT MAIN IS NOT CORRECTLY DEFINED

40. Which of the following are Java modifiers?..A.B.D 1) public 2) private 3) friendly 4) transient 5) vagrant 41.What will happen when you attempt to compile and run this code? class Base{ abstract public void myfunc(); public void another(){ System.out.println("Another method"); }} public class Abs extends Base{ public static void main(String argv[]){ Abs a = new Abs(); a.amethod(); } public void myfunc(){ System.out.println("My func"); } public void amethod(){ myfunc(); }}.. B 1) The code will compile and run, printing out the words "My Func" 2) THE COMPILER WILL COMPLAIN THAT THE BASE CLASS IS NOT DECLARED AS ABSTRACT. 3) The code will compile but complain at run time that the Base class has non abstract methods 4) The compiler will complain that the method myfunc in the base class has no body, nobody at all to looove it 42) Why might you define a method as native?A 1) TO GET TO ACCESS HARDWARE THAT JAVA DOES NOT KNOW ABOUT 2) To define a new data type such as an unsigned integer 3) To write optimised code for performance in a language such as C/C++ 4) To overcome the limitation of the private scope of a method 43.What will happen when you attempt to compile and run this code? class Base{ public final void amethod(){ System.out.println("amethod"); }} public class Fin extends Base{ public static void main(String argv[]){ Base b = new Base(); b.amethod(); }}..D 1) Compile time error indicating that a class with any final methods must be declared final itself 2) Compile time error indicating that you cannot inherit from a class with final methods 3) Run time error indicating that Base is not defined as final

4) SUCCESS IN COMPILATION AND OUTPUT OF "AMETHOD" AT RUN TIME.


44.What will happen when you attempt to compile and run this code? public class Mod{ public static void main(String argv[]){ } public static native void amethod(); } 1) Error at compilation: native method cannot be static 2) Error at compilation native method must return value 3) Compilation but error at run time unless you have made code containing native a method available 4) COMPILATION AND EXECUTION WITHOUT ERROR

45. What will happen when you attempt to compile and run this code? private class Base{} public class Vis{ transient int iVal; public static void main(String elephant[]){ }} 1) COMPILE TIME ERROR: BASE CANNOT BE PRIVATE 2) Compile time error indicating that an integer cannot be transient 3) Compile time error transient not a data type 4) Compile time error malformed main method 46. What happens when you attempt to compile and run these two files in the same directory? //File P1.java package MyPackage; class P1{ void afancymethod(){ System.out.println("What a fancy method"); }} //File P2.java public class P2 extends P1{ public static void main(String argv[]){ P2 p2 = new P2(); p2.afancymethod(); }} 1) Both compile and P2 outputs "What a fancy method" when run 2) Neither will compile 3) Both compile but P2 has an error at run time 4) P1 COMPILES CLEANLY BUT P2 HAS AN ERROR AT COMPILE TIME 47.You want to find out the value of the last element of an array. You write the following code. What will happen when you compile and run it.? public class MyAr{ public static void main(String argv[]){ int[] i = new int[5]; System.out.println(i[5]); }} 2) An error at run time 48. You want to loop through an array and stop when you come to the last element. Being a good java programmer and forgetting everything you ever knew about C/C++ you know that arrays contain information about their size. Which of the following can you use? 1) myarray.length(); 2) MYARRAY.LENGTH; 3) myarray.size 4) myarray.size(); 49. What best describes the appearance of an application with the following code? import java.awt.*; public class FlowAp extends Frame{ public static void main(String argv[]){ FlowAp fa=new FlowAp(); fa.setSize(400,300); fa.setVisible(true);} FlowAp(){ add(new Button("One")); add(new Button("Two")); add(new Button("Three")); add(new Button("Four")); }//End of constructor}//End of Application 3) A Frame with one large button marked Four in the Centre 50. How do you indicate where a component will be positioned using Flowlayout? 4) Do nothing, the FlowLayout will position the component

Anda mungkin juga menyukai