QUESTION 1 ---------------------------------------------------------------------What is the output for the below code ? import java.util.LinkedList; import java.util.Queue; public class Test { public static void main(String... args) { Queue q = new LinkedList(); LinkedList();
q.add("newyork");
q.add("ca");
q.add("t
A) newyork ca texas 11 B) ca newyork texas 11 C) 11 texas ca newyork D) Compile error : Integer can't add ---------------------------------------------------------------------QUESTION 2 ---------------------------------------------------------------------Predict the output for following program : public class ThreadEx extends Thread{ public static void main(String argv[]){ ThreadEx t = new ThreadEx(); ThreadEx(); t.runMe(); t.start(); } public void run(){ System.out.print("Thread Running"); } public vo A) Thread Running Thread Running B) Thread Running C) Thread RunningThread Running D) Compilation Error E) Runtime Error ---------------------------------------------------------------------QUESTION 3
---------------------------------------------------------------------What will be the output for following program public class Test { public static void main(String[] args) { Byte b = 120; int c = (int)(b + 10 + 20D + 20L + 40.50F); System.out.println(c); } } A) 210 B) 210.5 C) 120 D) compilation fails E) Runtime Error ---------------------------------------------------------------------QUESTION 4 ---------------------------------------------------------------------What will be the result of compiling and running following program import java.io.*; public class IOTesting { public static void main(String[] args) throws IOException { File file = new File("file.txt"); FileOutputStream stream = new FileOutputStream A) create file "file.txt" and write "R" into it. B) create file "file.txt" and write "6517" into it. C) create file "file.txt" and no content will be written into it. D) It will throw IOException. E) It will throw FileNotFoundException. ---------------------------------------------------------------------QUESTION 5 ---------------------------------------------------------------------Which of the following statement(s) is/are invalid? A. DataInputStream dis = new DataInputStream("file.txt"); B. DataInputStream dis = new DataInputStream(new FileInputStream("file.info")); C. InputStream dis = new DataInputStream(new FileInputSt A) A, B, C, D B) B, C, D
C) B, E D) Only B E) A, C, E ---------------------------------------------------------------------QUESTION 6 ---------------------------------------------------------------------What will be the output of following program import java.util.ArrayList; public class IOTesting { public static void main(String[] args) { ArrayList list = new ArrayList<>(); ArrayList listStr = list;
ArrayList
A) throw ClassCastException B) Welcome Java C) throw ArrayIndexOutOfBoundsException D) print java.lang.StringBuffer@ ---------------------------------------------------------------------QUESTION 7 ---------------------------------------------------------------------Which result set generally does not show changes to the underlying database that are made while it is open. The membership, order, and column values of rows are typically fixed when the result set is created? A) TYPE_FORWARD_ONLY B) TYPE_SCROLL_INSENSITIVE C) TYPE_SCROLL_SENSITIVE D) ALL MENTIONED ABOVE ---------------------------------------------------------------------QUESTION 8 ---------------------------------------------------------------------Which are valid declarations for 2D array? A. int [][]test = new int[][]; B. int [][]test = new int[2][]; C. int [][]test = new int[2][3]; D. int []test[] = new int[][3]; E. int test[][] = new [2][3]int; F. int test[][] = new [2]int [];
G. A) A,B,C,D B) B, C, G C) B,D,G D) A,E,F E) C, D, E ---------------------------------------------------------------------QUESTION 9 ---------------------------------------------------------------------What is the output of the below code? import java.io.*; import java.io.Serializable; class A{} public class Test implements Serializable { private static A a = new A(); public static void main(String... args){ Test b = new Test(); try{ A) Compilation Fail B) java.io.NotSerializableException: Because class A is not Serializable C) No Exception at Runtime D) None of the above E) Runtime Error ---------------------------------------------------------------------QUESTION 10 ---------------------------------------------------------------------Which of the following statements are invalid statements. A. An Array in Java is an object. B. Number ofelements in the array can be known by using length() method. C. If a method tries to access an array element beyond its range, some unchecked except A) A, B B) B, C C) C, D D) B, D E) A, D ----------------------------------------------------------------------
QUESTION 11 ---------------------------------------------------------------------What will the output of following code? public class StringTest { public static void main(String[] args) { String test = "true"; if(test) System.out.println("test"); else System.out.println(test); } } A) test B) Compilation fails C) true D) An IllegalArgumentException exception will be thrown at runtime ---------------------------------------------------------------------QUESTION 12 ---------------------------------------------------------------------import java.util.*; public class Demo { public static void main(String[] args) { HashMap map = new HashMap(); //line 4 map.put(18,1); map.put(15.5, 15.5); map.put(20, 20); map.put(45D, 50L); Set set = map.keySet(); //insert code here / A) Collections.sort(set); B) Arrays.sort(set); C) set = new TreeSet(set); D) set = new SortedSet(set); E) compilation fails ---------------------------------------------------------------------QUESTION 13 ---------------------------------------------------------------------Given that the current directory is empty, and that the user has read and write
permissions, and the following: 11. import java.io.*; 12. public class DOS { 13. public static void main(String[] args) { 14. File dir = new File("dir"); 15. dir.mkdir(); 16. A) A B) B C) C D) D E) E ---------------------------------------------------------------------QUESTION 14 ---------------------------------------------------------------------Which declarations will initialize boolean variables? A. boolean a = 0; B. boolean b = 1; C. boolean e = (0==0); D. boolean c = null; E. boolean d = (12>5?true:false); A) A, B B) C,E C) C, D, E D) D, E E) none of the above ---------------------------------------------------------------------QUESTION 15 ---------------------------------------------------------------------What will be the output of following code? import java.util.*; public class SomeTest { public static void main(String[] args) { Set set = new HashSet(); Float i1 = 111.11F; Float i2 = 222.22F; set.add(i1);
set.add(i1); set.add(i A) 2 1 1 B) 2 1 0 C) 3 2 2 D) 3 2 1 E) compilation fails ---------------------------------------------------------------------QUESTION 16 ---------------------------------------------------------------------Re arrange the Steps to create a JDBC Application A) Connect to a Database B) Load a driver C) Extract from ResultSet D) Register a driver E) Create and execute SQL statements A) D->B->A->E->C B) B->D->A->E->C C) A->B->D->E->C D) A->D->B->E->C ---------------------------------------------------------------------QUESTION 17 ---------------------------------------------------------------------Given: public class MyThread implements Runnable { public static void main (String[] args) throws Exception { Thread t = new Thread(new MyThread()); t.start(); System.out.print("Started"); t.join(); System.out.print("Done"); } public void run A) A B) B C) C D) D
E) E ---------------------------------------------------------------------QUESTION 18 ---------------------------------------------------------------------The code snippet to add a column in department table is : Statement stmt = con.createStatement(); Stmt.execute(?); Pass the query. A) “Alter table department add varchar2(15)” B) “Alter table department add dep_name” C) “Alter table department add dep_name varhcar2(15)” D) none ---------------------------------------------------------------------QUESTION 19 ---------------------------------------------------------------------What is the output of the below code: final class Complex { private double re, im; public Complex(double re, double im) { this.re = re; this.im = im; } Complex(Complex c) { System.out.println("Copy constructor c A) Copy constructor called (10.0 + 15.0i) B) Copy constructor called (10 + 15i) C) (10 + 15) D) compile time error E) run time error ---------------------------------------------------------------------QUESTION 20 ---------------------------------------------------------------------Which of the following are true about abstract classes in Java
A. Abstract class can have abstract as well as non-abstract methods . B. If we inherit an abstract class and do not implement all the abstract methods, then the sub class must be marked as ab A) A,B,C B) A,B,E C) B,C,D,F D) A,B,C,E E) D, F ---------------------------------------------------------------------QUESTION 21 ---------------------------------------------------------------------What is the output of following program? interface I { public int var = 5; } public class Rest { public static void main(String[] args) { System.out.println(I.var++); } } A) 5 B) 6 C) 0 D) Compilation fails E) run time error ---------------------------------------------------------------------QUESTION 22 ---------------------------------------------------------------------public class DemoTest { public static void main(String[] args) { // TODO Auto-generated method stub int i = 2; int var = 1 + (i++) + (--i) + 1; //line 5 System.out.println(var++); } } A) 6
B) 7 C) 5 D) compilation error at line 5 E) runtime exception ---------------------------------------------------------------------QUESTION 23 ---------------------------------------------------------------------Predict the output for following program. import java.io.*; class Good implements Serializable{ public Good() { System.out.println("Good"); } } public class SerTest { public static void main(String[] args) throws Exception { Good b = new Good(); A) Good Good B) Good C) compile time error D) runtime error ---------------------------------------------------------------------QUESTION 24 ---------------------------------------------------------------------What will be the result of compiling and run the following code: public class FileTest { public static void main(String... args) throws Exception { File file = new File("datafile"); System.out.println(file.exists()); file.createNewFile(); System. A) true true B) true false C) false true D) false
false ---------------------------------------------------------------------QUESTION 25 ---------------------------------------------------------------------Predict the output of following code import java.util.LinkedList; import java.util.Queue; public class LinkTest { public static void main(String... args) { Queue q = new LinkedList<>(); q.add("Kashi"); q.add("Madurai"); q.add("Ujjain"); A) Kashi 3 Madurai 3 Ujjain 3 11 3 B) Kashi 3 Madurai 2 Ujjain 1 11 0 C) Kashi 4 Madurai 4 Ujjain 4 11 4 D) 3 2 1 0 E) It will throw ClassCastException ---------------------------------------------------------------------QUESTION 26 ---------------------------------------------------------------------What will be output of following code? public class ThreadTest extends Thread { ThreadTest(){ super("ThreadOne"); } public static void main(String[] args){
System.out.println(new ThreadTest().currentThread().getName()); } } A) ThreadOne B) main C) ThreadTest D) Thread E) compilation error ---------------------------------------------------------------------QUESTION 27 ---------------------------------------------------------------------What will be output of following code snippet? boolean stmt1 = "champ" == "champ"; boolean stmt2 = new String("champ").equals(new String("champ")); boolean stmt3 = "champ".toString()=="champ"; System.out.println(stmt1 && stmt2 && stmt3); A) true B) false C) true true true D) false false false E) compilation error ---------------------------------------------------------------------QUESTION 28 ---------------------------------------------------------------------interface Chewable {} interface Eatable extends Chewable{} class Food implements Chewable { } class Meat extends Food {} class Gum implements Chewable{} public class Tester { public static void main(String[] args) { Food food = new Food(); Meat meat A) truetruetruetrue B) truetruefalsetrue C) falsefalsetruetrue D) falsetruefalsetrue
E) compilation error ---------------------------------------------------------------------QUESTION 29 ---------------------------------------------------------------------Consider following two classes (Address and Account), what will happen if you attempt to serialize an instance of Account? import java.io.Serializable; class Address {} class Employee implements Serializable { Address address; } A) Serialization will succeed without any problem B) compilation error C) runtime exception ---------------------------------------------------------------------QUESTION 30 ---------------------------------------------------------------------Which of the following values can be replaced in the place of 1 and 2 Statement statement = con.createStatement(1, 2); A. ResultSet. TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY B. ResultSet. TYPE_SCROLL_INSENSITIVE , ResultSet. CONCUR_UPDATABLE C. Resu A) B,C,D B) A,B,C,D C) C,D D) B,D ---------------------------------------------------------------------QUESTION 31 ---------------------------------------------------------------------How can you retrieve information from a ResultSet? A) By invoking the method get(..., String type) on the ResultSet, where type is the database type B) By invoking the method get(..., Type type) on the ResultSet, where Type is an object which represents A) A B) B C) C
D) D ---------------------------------------------------------------------QUESTION 32 ---------------------------------------------------------------------Select the common methods, which are defined for both type String and type StringBuffer ? A. toString() B. length() C. append(String) D. trim() E. charAt() F. equals(Object) A) A,F B) A,B,F C) A,B,E,F D) A,C,F E) A,B,E ---------------------------------------------------------------------QUESTION 33 ---------------------------------------------------------------------Choose incorrect statements? A. ResultSet.CONCUR_UPDATABLE used with the result set is used to update the rows directly in the database. B. When a connection is created, it is in auto-commit mode. C. Type-2 and Type-4 drivers are pure java drivers. D. e A) A,C B) B,C C) A,D D) A,B,D E) C ---------------------------------------------------------------------QUESTION 34 ---------------------------------------------------------------------What will be the output of following code? String data = "B1HA2RA3T"; String [] tokens = data.split("\\d");
for(int i=tokens.length-1; i>=0; i--) System.out.print(tokens[i]+" "); A) T RA HA B B) B HA RA T C) BHARAT D) T AR AH B E) compilation fails ---------------------------------------------------------------------QUESTION 35 ---------------------------------------------------------------------Which of the Thread instantiations are valid in following code? public class SomeThread extends Thread implements Runnable { public static void main(String[] args) { new Thread(); //A new SomeThread(); // B new Thread(new SomeThread()); // C new A) A,B,C B) B,C,D C) A, B, C, D D) A,B,D E) compilation fails ---------------------------------------------------------------------QUESTION 36 ---------------------------------------------------------------------Given the following code segment enclosed within a try/catch block, what valid Exception type can be catched causing no compilation error? (choose three) try{ File file = new File("file"); file.createNewFile(); }catch( A) A,B,C B) C) A,C,D D) B,C,D E) B,D,E F) A,C,E
---------------------------------------------------------------------QUESTION 37 ---------------------------------------------------------------------What will happen if we execute following code? public class DemoThread extends Thread { public void run() { System.out.println("running"); } public static void main(String[] args) { DemoThread thread = new DemoThread(); thread.start(); thread.r A) print "running" twice B) print "running" thrice C) It will throw IllegalThreadStateException D) It will throw InterruptedException E) compilation error ---------------------------------------------------------------------QUESTION 38 ---------------------------------------------------------------------In following program, at what line file "info.txt" will be created? import java.io.*; public class FileTester { public static void main(String[] args) { try { File file = new File("info.txt");// line 5 file.createNewFile(); // line 6 FileWr A) line 5 B) line 6 C) line 7 D) line 8 E) line 11 ---------------------------------------------------------------------QUESTION 39 ---------------------------------------------------------------------What would be output of following program? Consider today's date is 21st April 2016 .
import java.text.SimpleDateFormat; import java.util.Date; public class DateTester { public static void main(String[] args) { SimpleDateFormat format = new SimpleDateF A) 4::21::2016 B) 04::21::2016 C) Apr::21::2016 D) April::21::2016 E) Compilation error due to invalid format given for date ---------------------------------------------------------------------QUESTION 40 ---------------------------------------------------------------------Given the code fragment: float x = 155.00f % 2.00f; int y = 155 % 2; byte z = 155 % 2; System.out.print(x + ", "+ y + ", " + z); What is the result? A) 1.0f,1,1 B) 77.5f, 77, 77 C) 1.0, 1, 1 D) compilation error E) An exception will be thrown at runtime ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------