Premium

Oracle Java Programming Certification Questions and Answers (Dumps and Practice Questions)



Question : You have given code as shown and commands to compile and run are below.

javac HadoopExamApp.java
java HadoopExam 1 2 3

What would be printed.


 : You have given code as shown and commands to compile and run are below.
1. int HadoopExam 1
2. Object HadoopExam 1
3. Access Mostly Uused Products by 50000+ Subscribers
4. It failed in Compilation step/Command
5. It will compile successfully, but at runtime, it will through RuntimeException




Correct Answer : Get Lastest Questions and Answer :








Question : You have been given below code. What value it is going to print (Assume it is in a class)
  : You have been given below code. What value it is going to print (Assume it is in a class)
1. HadoopExam 0
HadoopExam 1
2. Null HadoopExam 0
Null HadoopExam 1
3. Access Mostly Uused Products by 50000+ Subscribers
Null
4. A NullPointerException is thrown at runtime.


Correct Answer : Get Lastest Questions and Answer :
Explanation:



Question : : You have been given below code fragement

StringBuilder sb = new StringBuilder ( ) ;
sb.append ("world");

Which code fragment prints Hello World?

  : :  You have been given below code fragement
1. sb.insert(0,"Hello "); System.out.println(sb);
2. sb.append(0,"Hello "); System.out.println(sb);
1. sb.add(0,"Hello "); System.out.println(sb);
2. sb.set(0,"Hello "); System.out.println(sb);




Correct Answer : Get Lastest Questions and Answer : Exp: The java.lang.StringBuilder.insert(int offset, char c) method inserts the string representation of the char argument into this sequence.
The second argument is inserted into the contents of this sequence at the position indicated by offset. The length of this sequence increases by one.
The offset argument must be greater than or equal to 0, and less than or equal to the length of this sequence.






Related Questions


Question : You have been given two separate classes as below.

public class MyException extends RuntimeException { }

public class Test {
public static void main(String[] args) {
try {
method1();
} catch (MyException ne) {
System.out.print("A");
}
}

public static void method1() { // line n1
try {
throw Math.random() > 0.5 ? new MyException()
: new RuntimeException();
} catch (RuntimeException re) {
System.out.print("B");
}
}
}

What is the result?

 : You have been given two separate classes as below.
1. A
2. B
3. Access Mostly Uused Products by 50000+ Subscribers
4. AB
5. A compile time error occurs at line n1





Question : You have been given Java Application as below code

public class App {
String myStr = "7007";

public void doStuff(String str) {
int myNum = 0;
try {
String myStr = str;
myNum = Integer.parseInt(myStr);
} catch (NumberFormatException ne) {
System.err.println("Error");
}
System.out.println("myStr: " + myStr + ", myNum: " + myNum);
}

public static void main(String[] args) {
App obj = new App();
obj.doStuff("9009");
}
}

What happen/print, when you execute this code ?

  : You have been given Java Application as below code
1. myStr: 9009, myNum: 9009
2. myStr: 7007, myNum: 7007
3. Access Mostly Uused Products by 50000+ Subscribers
4. Compilation fails





Question : Which two are benefits of polymorphism?
A. Faster code at runtime
B. More efficient code at runtime
C. More dynamic code at runtime
D. More flexible and reusable code
E. Code that is protected from extension by other classes

 : Which two are benefits of polymorphism?
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. C,D
5. A,E




Question : You have been given below code

public class Test {

public static void main(String[] args) {
int numsl[] = new int[3];
int nums2[] = { 1, 2, 3, 4, 5 };
numsl = nums2;
for (int x : numsl) {
System.out.print(x + " : ");
}
}
}

What would be the result?

  : You have been given below code
1. 1:2:3:4:5:
2. 1:2:3:
3. Access Mostly Uused Products by 50000+ Subscribers
4. An ArrayoutofBoundsException is thrown at runtime.




Question : You have been given below code, what would be printed when you run it?

public class Product {
int id;
String name;

public Product(int id, String name) {
this.id = id;
this.name = name;
}

public static void main(String[] args) {

// And given the code fragment:
Product p1 = new Product(101, "Pen");
Product p2 = new Product(101, "Pen");
Product p3 = p1;

boolean ansl = p1 == p2;
boolean ans2 = p1.name.equals(p2.name);
System.out.print(ansl + ":" + ans2);

}
}

 : You have been given below code, what would be printed when you run it?
1. true:true
2. true:false
3. Access Mostly Uused Products by 50000+ Subscribers
4. false:false




Question : Given the following classes:

public class Director extends Manager {
public int stockOptions;
}

public class Manager extends Employee {
public int budget;
}

public class Employee {
public int salary;


public static void main(String[] args) {
Employee employee = new Employee();
Manager manager = new Manager();
Director director = new Director();
// line n1
}
}

Which two options fail to compile when placed at line n1 of the main method?

A. employee.salary = 50_000;
B. director.salary = 80_000;
C. employee.budget = 200_000;
D. manager.budget = 1_000_000;
E. manager.stockOption = 500;
F. director.stockOptions = 1_000;


  : Given the following classes:
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. C,D
5. C,E