Java Programming with Database Connectivity

Test your knowledge of Java programming concepts including JDBC, collections, object-oriented programming, operators, control flow, exceptions, arrays, and generics.

19 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

import java.util.Scanner; public class ScannerTest { public static void main(String[] args) { Scanner scanner = new Scanner("hello 1 2.00 false"); scanner.useDelimiter(" "); String str = scanner.next(); int anInt = scanner.nextInt(); float aFloat = scanner.nextFloat(); boolean booleanValue = scanner.nextBoolean(); System.out.println(str + ":" + anInt + ":" + aFloat + ":" + booleanValue); } }

  1. The program will output 'hello:1:2.0:false'
  2. The program will throw Input Mismatch exception at the run-time
  3. The program will output nothing.
  4. The program will ouput ':1:2.0:false'
Question 2 Multiple Choice (Single Answer)

public class Gen<G>{ G g; Gen(G g) { this.g =g; } public static void main(String[] args) { Gen<String> arr[] = new Gen[5]; //line 1 arr[0] = new Gen("Java"); //line 2 arr[1] = new Gen(1); //line 3 arr[2] = (Gen<String>)new Gen(1); //line 4 arr[3] = (Gen<String>)new Gen<Integer>(1); //line 5 for(Gen o:arr) { System.out.println(o); } } }

  1. Compile time Error at line 1
  2. Compile time Error at line 3
  3. Compile time Error at line 4
  4. Compile time Error at line 5
  5. Run Time Error
Question 3 Multiple Choice (Single Answer)

What will be printed out if you attempt to compile and run the following code? int i=9; switch (i) { default: System.out.println("default"); case 0: System.out.println("zero"); break; case 1: System.out.println("one"); case 2: System.out.println("two"); }

  1. default
  2. default, zero
  3. error default clause not defined
  4. no output displayed
Question 4 Multiple Choice (Single Answer)

Which of the following statements are true?

  1. Methods cannot be overriden to be more private
  2. static methods cannot be overloaded
  3. private methods cannot be overloaded
  4. An overloaded method cannot throw exceptions not checked in the base class
Question 5 Multiple Choice (Single Answer)

What will be printed out if this code is run with the following command line? java myprog good morning public class myprog{ public static void main(String argv[]) { System.out.println(argv[2]); } }

  1. myprog
  2. good
  3. morning
  4. Exception raised: "java.lang.ArrayIndexOutOfBoundsException: 2"
Question 6 Multiple Choice (Single Answer)

Which of the following is not keyword or reserved word in Java?

  1. if
  2. then
  3. goto
  4. while
  5. case
Question 7 Multiple Choice (Single Answer)

What will happen if you try to compile and run the following code? public class Q { public static void main(String argv[]){ int anar[]=new int[5]; System.out.println(anar[0]); } }

  1. Error: anar is referenced before it is initialized
  2. null
  3. 0
  4. 5
Question 8 Multiple Choice (Single Answer)

What will be the result of attempting to compile and run the following code? abstract class MineBase { abstract void amethod(); static int i; } public class Mine extends MineBase { public static void main(String argv[]){ int[] ar=new int[5]; for(i=0;i < ar.length;i++) System.out.println(ar[i]); } }

  1. a sequence of 5 0's will be printed
  2. Error: ar is used before it is initialized
  3. Error Mine must be declared abstract
  4. IndexOutOfBoundes Error
Question 9 Multiple Choice (Single Answer)

Which of the following lines of code will compile without error? a) int i=0; if(i) { System.out.println("Hello"); } b) boolean b=true; boolean b2=true; if(b==b2) { System.out.println("So true"); } c) int i=1; int j=2; if(i==1 &| j==2) System.out.println("OK");

  1. a)
  2. b)
  3. c)
  4. none
Question 10 Multiple Choice (Single Answer)

What will be output if you try to compile and run the following code, but there is no file called Hello.txt in the current directory? import java.io.*; public class Mine { public static void main(String argv[]){ Mine m=new Mine(); System.out.println(m.amethod()); } public int amethod() { try { FileInputStream dis=new FileInputStream("Hello.txt"); }catch (FileNotFoundException fne) { System.out.println("No such file found"); return -1; }catch(IOException ioe) { } finally{ System.out.println("Doing finally"); } return 0; } }

  1. No such file found
  2. No such file found ,-1
  3. No such file found, Doing finally, -1
  4. 0
Question 11 Multiple Choice (Single Answer)

What will happen if you attempt to compile and run the following code? class Base {} class Sub extends Base {} class Sub2 extends Base {} public class CEx{ public static void main(String argv[]){ Base b=new Base(); Sub s=(Sub) b; } }

  1. Compile and run without error
  2. Compile time Exception
  3. Runtime Exception
  4. none
Question 12 Multiple Choice (Single Answer)

What is the result of the following operation? System.out.println(4 | 3);

  1. 6
  2. 0
  3. 1
  4. 7
Question 13 Multiple Choice (Single Answer)

Given the following code how could you invoke the Base constructor that will print out the string "base constructor"; class Base{ Base(int i){ System.out.println("base constructor"); } Base(){ } } public class Sup extends Base{ public static void main(String argv[]){ Sup s= new Sup(); //One } Sup() { //Two } public void derived() { //Three } }

  1. On the line After //One put Base(10);
  2. On the line After //One put super(10);
  3. On the line After //Two put super(10);
  4. On the line After //Three put super(10);
Question 14 Multiple Choice (Single Answer)

You need to create a class that will store unique object elements. You do not need to sort these elements but they must be unique. What interface might be most suitable to meet this need?

  1. Set
  2. List
  3. Map
  4. Vector
Question 15 Multiple Choice (Single Answer)

There is a table called Employee having columns are empno, ename , job , deptno,grade and salary. Which of the following is a correct query to change all emp salary with salary<10000 to 1.5 times and grade to ‘Promo’

  1. Update Employee set salary = salary * 1.5 and grade=’Promo’ where salary < 10000;
  2. Update Employee set salary = salary * 1.5, grade=’Promo’ where salary < 10000;
  3. Update table Employee set salary = salary * 1.5, grade=’Promo’ where salary < 10000;
  4. Update table Employee set salary = salary * 1.5 and grade=’Promo’ where salary < 10000;
Question 16 Multiple Choice (Single Answer)

Which of the following is Data Definition Language?

  1. INSERT
  2. DELETE
  3. UPDATE
  4. CREATE
Question 17 Multiple Choice (Single Answer)

Which type of Statement can execute parameterized queries?

  1. PreparedStatement
  2. ParameterizedStatement
  3. ParameterizedStatement and CallableStatement
  4. All kinds of Statements (i.e. which implement a sub interface of Statement)
Question 18 Multiple Choice (Single Answer)

Which type of Statement can execute queries stored on db server?

  1. CallableStatement
  2. ParameterizedStatement
  3. ParameterizedStatement and CallableStatement
  4. All kinds of Statements (i.e. which implement a sub interface of Statement)
Question 19 Multiple Choice (Single Answer)

Which packages contain the JDBC classes?

  1. java.jdbc and javax.jdbc
  2. java.jdbc and java.jdbc.sql
  3. java.sql and javax.sql
  4. java.rdb and javax.rdb