Premium

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



Question : Given the code fragment:

What is the result?
  : Given the code fragment:
1. Execution terminates in the first catch statement, and caught a RuntimeException is printed to the console
2. Execution terminates In the second catch statement, and caught an Exception is printed to the console.
3. Access Mostly Uused Products by 50000+ Subscribers
4. Execution completes normally, and "Ready to use" is printed to the console.
5. The code fails to compile because a throws keyword is required.




Correct Answer : Get Lastest Questions and Answer
Explanation: After running the program below error will be printed. Reason : there is a infinite while loop while(true), which keeps adding a String object in List and never exit. Which causes this error.

Exception in thread "main" java.lang.outofMemoryError: Java heap space
at java.util.Arrays.copyof(Arrays.java:3210)
at java.util.Arrays.copyof(Arrays.java:3181)
at java.util.ArrayList.grow(ArrayList.java:261)
at java.util.ArrayList.ensureExplicitCapacity(ArrayList.java:235)
at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:227)
at java.util.ArrayList.add(ArrayList.java:458)
at Q45.main(Q45.java:11)
Java Result: 1




Question : When you run the given program, what would be printed.


 : When you run the given program, what would be printed.
1. int sum is 30
float sum is 30.0
2. int sum is 30
double sum is 30.0
3. Access Mostly Uused Products by 50000+ Subscribers
double sum is 30.0
4. Integer sum is 30
flaot sum is 30.0

Correct answer: 2



Question : Which statement initializes a stringBuilder to a capacity of ?

 : When you run the given program, what would be printed.
1. StringBuilder sb = new String ("128");
2. StringBuilder sb = StringBuilder.setCapacity (128);
3. Access Mostly Uused Products by 50000+ Subscribers
4. StringBuilder sb = new StringBuilder (128);




Correct Answer : Get Lastest Questions and Answer :
Explanation: StringBuilder(int capacity)
Constructs a string builder with no characters in it and an initial capacity specified by the capacity argument.
Note: An instance of a StringBuilder is a mutable sequence of characters.
The principal operations on a StringBuilder are the append and insert methods, which are
overloaded so as to accept data of any type. Each effectively converts a given datum to a
string and then appends or inserts the characters of that string to the string builder. The
append method always adds these characters at the end of the builder; the insert method adds
the characters at a specified point.







Question : You have been given code as shown, what happen when you compile/run

  : You have been given code as shown, what happen when you compile/run
1. It will print 10:20
2. It will print 0:20
3. Access Mostly Uused Products by 50000+ Subscribers
4. Compilation fails at line n1
5. Compilation fails at line n2

Correct Answer : Get Lastest Questions and Answer :






Related Questions


Question : Given the code fragment:
String h1 = "Bob";
String h2 = new String ("Bob");
What is the best way to test that the values of h1 and h2 are the same?

  : Given the code fragment:
1. if (h1 = = h2)
2. if (h1.equals(h2))
3. Access Mostly Uused Products by 50000+ Subscribers
4. if (h1.same(h2))



Question : You have been given belwo interface declaration

interface Runnable {
public voide run();
}

Which of the following will create instance of Runnable type?

   : You have been given belwo interface declaration
1. Runnable run = 0 -> {
System.out.println("Run");
}
2. Runnable run = 0 -> System.out.println("Run");
3. Access Mostly Uused Products by 50000+ Subscribers
4. Runnable run => System.out.println("Run");
5. None of above





Question : You have been given below Java Code

public class Painting {
private String type;

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public static void main(String[] args) {
Painting obj1 = new Painting();
Painting obj2 = new Painting();
obj1.setType(null);
obj2.setType("Fresco");
System.out.print(obj1.getType() + " : " + obj2.getType());
}
}

When you run it, what would be printed ?


   : 	You have been given below Java Code
1. : Fresco
2. null : Fresco
3. Access Mostly Uused Products by 50000+ Subscribers
4. A NullPointerException is thrown at runtime





Question : You have been given below code

boolean log3 = (5.0 != 6.0) && (4 != 5);
boolean log4 = (4 != 4) || (4 == 4);
System.out.println("\n log3:" + log3 + "\n log4 : " + log4);

When you execute this code, what would be printed ?
   : 	You have been given below code
1. log3:false
log4:true
2. log3:true
log4:true
3. Access Mostly Uused Products by 50000+ Subscribers
log4:false
4. log3:false
log4:false






Question : You have been given following code

public class Test {
static boolean bVar;

public static void main(String[] args) {
boolean bVar1 = true;
int count = 8;
do {
System.out.println("Hello Java! " + count);
if (count >= 7) {
bVar1 = false;
}
} while (bVar != bVar1 && count > 4);
count -= 2;
}
}

When you run it, what would be printed ?

  : You have been given following code
1. Hello Java! 8 Hello Java! 6 Hello Java! 4
2. Hello Java! 8 Hello Java! 6
3. Access Mostly Uused Products by 50000+ Subscribers
4. Compilation fails




Question : You have been given following code

public class TestLoop {
public static void main(String[] args) {
int array[] = { 0, 1, 2, 3, 4 };
int key = 3;
for (int pos = 0; pos < array.length; ++pos) {
if (array[pos] == key) {
break;
}
}
System.out.print("Found " + key + "at " + pos);
}
}

What is the result?

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