Java Technologies
| Question: | 
| Which of the following is the correct syntax for suggesting that the JVM perform garbage collection? | 
| a. | System.setGarbageCollection(); | |
| b. | System.out.gc(); | |
| c. | System.gc(); | |
| d. | System.free(); | 
| Question: | 
| Choose all valid forms of the argument list for the   FileOutputStream constructor shown below: | 
| a.  | FileOutputStream( FileDescriptor fd ) | |
| b.  | FileOutputStream( String n, boolean a ) | |
| c.  | FileOutputStream( boolean a ) | |
| d.  | FileOutputStream() | |
| e.  | FileOutputStream( File f ) | 
|  Question: | 
| What will happen when this code is compiled and run? (The employee table has only 1 column) import java.sql.*; public class X { X() { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c = DriverManager.getConnection("jdbc:odbc:MedSol","",""); Statement s = c.createStatement(); ResultSet r = s.executeQuery("SELECT * from Employee"); c.close(); while(r.next()) { System.out.println(r.getString(1)); } } catch(Exception e) { e.printStackTrace(); } } public static void main(String str[]) { new X(); } } | 
| a. | All the values of column one are printed | |
| b. | Nothing is printed | |
| c. | The code will fail to compile | |
| d. | The code will throw an exception as records are being   printed after the connection is closed | 
| Question: | 
| Which of the following statements are correct with regard   to Polymorphism? | 
| a. | Polymorphism is a method in which a class can exist in   multiple forms | |
| b. | Polymorphism is a method in which a class can exist in   only two forms | |
| c. | Polymorphism is a method in which different instances of   an object displays different behavior | |
| d. | Polymorphism is a method in which different instances of   an object displays same behavior | 
|  Question: | 
| Can ServerSocket be used with UDP? | 
| a. | Yes | |
| b. | No | 
| Question: | 
| Which sequence will be printed when the following program   is run? import java.util.*; public class Test { public static void main(String str[]) { List l = new ArrayList(); l.add(''1''); l.add(''2''); l.add(1,''3''); System.out.println(l); } } | 
| a. | [1, 3, 2] | |
| b. | [1, 3, 1] | |
| c. | [1, 1, 3] | |
| d. | [1, 1, 2] | |
| e. | This code will generate an error | 
|  Question: | 
| What is Abstraction? | 
| a. | An act of representing essential features without   including details or working methodology | |
| b. | An act of representing essential features along with the   details or working methodology | |
| c. | An act of acquiring properties of some other object | |
| d. | An ability to be present in more than one form | 
| Question: | 
| What should be the replacement of "//ABC" in the   following code? class Krit { String str= new String("OOPS !!! JAVA"); public void KritMethod(final int iArgs) { int iOne; class Bicycle { public void sayHello() { //ABC } } } public void Method2() { int iTwo; } } | 
| a. | System.out.print(str); | |
| b. | System.out.print(iOne); | |
| c. | System.out.print(iTwo); | |
| d. | System.out.print(iArgs); | 
|  Question: | 
| What will be the output of this program? public class Test { public static void main (String args[]) { int a, b; a = 2; b = 0; System.out.println (g (a, new int[] {b})); } public static int g (int a, int b[]) { b[0] = 2 * a; return b[0]; } } | 
| a. | 0 | |
| b. | 1 | |
| c. | An exception will occur | |
| d. | 4 | 
| What would happen on trying to compile and run the   following code? public class Test { public static void main (String args[]) { int iRand; iRand = Math.random(); System.out.println(iRand); } } | 
| a. | A compilation error about random being an unrecognized   method will occur | |
| b. | A random number between 0 and 1 | |
| c. | A random number between 1 and 10 | |
| d. | A compilation error referring to a cast problem | 
|  Question: | 
| Which of these interfaces is the most applicable when   creating a class that associates a set of keys with a set of values? | 
| a. | Collection | |
| b. | Set | |
| c. | Map | |
| d. | SortedSet  | 
| Question: | 
| One method in your application needs to be synchronized.   Which of the following options are correct for synchronization? | 
| a. | public synchronized void Process(void){} | |
| b. | public void Process(){ synchronized(this){ } } | |
| c. | public void synchronized Process(){} | |
| d. | public synchronized void Process(){}  | 
|  Question: | 
| What would be the result of compiling and running the   following code class? public class Test { public static void main (String args[]) { Test t = new Test (); t.start (); } public void start () { int i = 2; int j = 3; int x = i & j; System.out.println (x); } } | 
| a. | The code will not compile | |
| b. | The code will compile but will give runtime error | |
| c. | The code will compile and print 2 | |
| d. | The code will compile and print 1 | 
| Question: | 
| Which of the following are not Java keyword? | 
| a. | strictfp | |
| b. | for | |
| c. | wait | |
| d. | while | |
| e. | try | 
| What would happen on trying to compile and run the   following code? public class Quest { int i=0; public static void main(String argv[]) { } Quest() { top: while(i <2) { System.out.println(i); i++; continue top; } } } | 
| a. | The code will compile but no output at runtime | |
| b. | The code will compile and output of 0 | |
| c. | The code will compile and output of 0 followed by 1 | |
| d. | The code will not compile as a target label cannot appear   before the corresponding continue or break statement | 
|  Question: | 
| What will be the output of the following program? public class Test { public static void main (String args[ ]) { B o = new A (); System.out.println (o.content ()); } public String content () throws Exception { throw new Exception (''This is an exception on this.content ()''); } private static class B { public String content () { return ''B''; } } private static class A extends B { public String content () { return ''A''; } } } | 
| a. | The code will compile but will fail to run | |
| b. | The code will compile and on running, it will print ''A'' | |
| c. | The code will fail to compile | |
| d. | The code will compile and on running, it will print ''B'' | 
|  Question: | 
| Which of the following will ensure that garbage collection   runs? | 
| a. | System.free() | |
| b. | Runtime.gc() | |
| c. | Object.gc() | |
| d. | System.gc() | |
| e. | None of the above | 
| Question: | 
| You have a class called TwoTyre. Its main method is as   follows: public static void main(String bicycle[]) { System.out.println(bicycle[0]); } On the command line you typed: java TwoTyre one two what would be the result? | 
| a. | one | |
| b. | two | |
| c. | TwoTyre | |
| d. | None of the above | 
|  Question: | 
| What is the return type of the method ceil(double) from   the Math class? | 
| a. | int | |
| b. | float | |
| c. | double | |
| d. | Integer | |
| e. | Double | 
| Question: | 
| What is the java.net.IDN class in 1.6? | 
| a. | Methods to resolve integrated domain names (IDNs), such   domain names are special embedded names | |
| b. | Methods to swap bytes between network byte order and host   byte order | |
| c. | Methods to convert internationalized domain names (IDNs)   between a normal Unicode representation and an ASCII Compatible Encoding   (ACE) representation | |
| d. | This class does not exist | |
| e. | None of the above | 
| Question: | 
| How does the set collection deal with duplicate elements? | 
| a. | Duplicate values will cause an error at compile time | |
| b. | A set may contain elements that return duplicate values   from a call to the equals method | |
| c. | An exception is thrown if you attempt to add an element   with a duplicate value | |
| d. | The add method returns false if you attempt to add an   element with a duplicate value | 
|  Question: | 
| What is the superclass of java.net.DatagramSocket? | 
| a. | java.net.Socket | |
| b. | java.net.UDPSocket | |
| c. | java.net.SocketInterface | |
| d. | java.lang.Object | |
| e. | None of the above | 
| Question: | 
| What would happen on trying to compile and run the   following code? class House { public final void MaintainMethod() { System.out.println("MaintainMethod"); } } public class Building extends House { public static void main(String argv[]) { House h = new House(); h.MaintainMethod(); } } | 
| a. | A runtime error will occur because class House is not   defined as final | |
| b. | Successful compilation and output of   "MaintainMethod" at run time | |
| c. | A compilation error indicating that a class with any final   methods must be declared final itself | |
| d. | A compilation error indicating that you cannot inherit   from a class with final methods | 
|  Question: | 
| Which of the following is a short circuit operator? | 
| a. | && | |
| b. | || | |
| c. | | | |
| d. | & | 
|  Question: | 
| What will be the output when this code is compiled and   run? public class Test { static int a; int b; public Test () { int a, b, c; a = b = c = 20; System.out.println (a); } public static void main (String args[]) { new Test (); } } | 
| a. | The code will fail to compile | |
| b. | True is printed | |
| c. | Nothing is printed | |
| d. | 20 is printed | 
|  Question: | 
| What   is printed to the standard output if myMethod() is executed? class MyPoint { void myMethod() { int x, y; x = 5; y = 3; System.out.print( " ( " + x + ", " + y + " ) " ); switchCoords( x, y ); System.out.print( " ( " + x + ", " + y + " ) " ); } void switchCoords( int x, int y ) { int temp; temp = x; x = y; y = temp; System.out.print( " ( " + x + ", " + y + " ) " ); } } | 
| a. | (5, 3) (5, 3) (5, 3) | |
| b. | (5, 3) (3, 5) (3, 5) | |
| c. | (5, 3) (3, 5) (5, 3) | |
| d. | No output will be printed | 
| Question: | 
| Which of the following are the methods of the Thread   class? | 
| a. | stay() | |
| b. | go() | |
| c. | yield() | |
| d. | sleep(long millis) | 
| Question: | 
| All class methods in the java.lang package are thread   safe. (in 1.5) | 
| a. | True | |
| b. | False | 
|  Question: | 
| Assuming that val has been defined as an int for the code   below, which values of val will result in "Test C" being printed? if( val > 4 ) { System.out.println("Test A"); }else if( val > 9 ) { System.out.println("Test B"); }else System.out.println("Test C"); | 
| a. | val < 0 | |
| b. | val between 0 and 4 | |
| c. | val between 4 and 9 | |
| d. | val > 9 | |
| e. | val = 0 | |
| f. | No values for val will result in "Test C" being   printed | 
|  Question: | 
| A method can be defined as native to: | 
| a. | Overcome the limitation of the private scope of a method | |
| b. | Get to access hardware that Java does not know about | |
| c. | Write optimized code for performance in a language such as   C/C++ | |
| d. | Define a new data type such as an unsigned integer | 
| Question: | 
| Which class contains a method to create a directory? | 
| a. | File | |
| b. | DataOutput | |
| c. | Directory | |
| d. | FileDescriptor | |
| e. | FileOutputStream | 
| Question: | 
| What will be the output when this code is compiled and   run? public class Test { public Test () { Bar b = new Bar (); Bar b1 = new Bar (); update (b); update (b1); b1 = b; update (b); update (b1); } private void update (Bar bar) { bar.x = 20; System.out.println (bar.x); } public static void main (String args[]) { new Test (); } private class Bar { int x = 10; } } | 
| a. | The code will fail to compile | |
| b. | 10 10 10 10 | |
| c. | 20 20 20 20 | |
| d. | 10 20 10 20 | 
| Question: | 
| Choose the correct statements: | 
| a. | An inner class may extend another class | |
| b. | There are no circumstances where an inner class may be   defined as private | |
| c. | A programmer may only provide one constructor for an   anonymous class | |
| d. | An inner class may be defined as static | 
| Question: | 
| What would happen on trying to compile and run the   following code? private class Crack { } public class Manic { transient int numb; public static void main(String sparrow[]) { } } | 
| a. | A Compilation error because an integer cannot be transient | |
| b. | A Compilation error because transient is not a data type | |
| c. | A Compilation error because of an erroneous main method | |
| d. | A Compilation error because class Crack cannot be private | 
|  Question: | 
| Which of the following cannot apply to constructors? | 
| a. | Name same as class name | |
| b. | Void return type | |
| c. | Can have parameters | |
| d. | Overloading | 
| Question: | 
| How many objects are created by the following code? Object a, b, c, d, e; e = new Object (); b = a = e; e = new Object (); | 
| a. | 2 | |
| b. | 5 | |
| c. | 4 | |
| d. | This code is invalid | 
|  Question: | 
| Which of the following statements are true about local   inner class within a method? | 
| a. | It can be marked as static | |
| b. | It can only access final members of its enclosing class | |
| c. | It has access to all members of its enclosing class | |
| d. | None of the above | 
| Question: | 
| What would happen on trying to compile and run the   following code? public class MainCls { public static void main(String argv) { System.out.println("My Text"); } } | 
| a. | A compile error will be generated because 'main' is a   reserved word and cannot be used for a class | |
| b. | "My Text" will be displayed | |
| c. | The code will compile. A runtime error will occur because   'main' is not properly defined | |
| d. | The code will compile. A runtime error will occur because   constructor is not defined | 
|  Question: | 
| Which of the following statements is not correct with   regard to threads in Java? | 
| a. | A call to the wait method causes the calling thread to   pause its execution | |
| b. | The wait and notify methods are defined in the Thread   class | |
| c. | The synchronized keyword can be applied to either a method   or a block of code | |
| d. | Any code that has calls to the wait or notify methods must   be synchronized | 
 

 

