Premium

Oracle Advacned Java Advanced Certification Questions and Answers (Dumps and Practice Questions)



Question : You have been given below code, please select the correct option for it.


package com.hadoopexam;

class Welcome {
int counter;
int counter1;

Welcome() {
this(10);
}

Welcome(int c) {
counter = c;
counter1 = c;

}

public String toString() {
return "counter vale is: " + counter+counter1;
}

public static void main(String[] args) {
System.out.println(new Welcome());
}
}


 : You have been given below code, please select the correct option for it.
1. It will give compile time error, saying method Welcome(int) is not defined.

2. It will give compile time error. As counter is defined.

3. It will give runtime error, by throwing NullPointerException.

4. The code will run perfectly and print "counter value is: 1010"

5. The code will run perfectly and print "counter value is: 20"


Correct Answer : 4
Explanation: As we can see first entry is String hence, + operator will behave as a concatenation operator.




Question : You have been given below code

package com.hadoopexam;

class Welcome {
private K key;
private V value;

public Welcome(K key, V value) {
this.key = key;
this.value = value;
}

public static Welcome createPair(T value) {
return new Welcome(value, value);
}

public K getKey() {
return key;
}

public V getValue() {
return value;
}

}
Which of the belwo option is invalid?

 : You have been given below code
1. Welcome score = new Welcome("Amit",100);

2. Welcome welcomePair = Welcome. createPair("HadoopExam.com");

3. Welcome anotherPair = new Welcome<>(97, 32);

4. Welcome myGrade = new Welcome<>("Amit", "B+");

5. None of the above


Correct Answer : 5
Explanation: All the declaration are valid.




Question : What is the behavior is expected from below code ?

package com.hadoopexam;
class Welcome {
int counter;

Welcome() {
this(10);
}

Welcome(int c) {
counter=c;
}

String toString() {
return "Value of counter is" + counter;
}

public static void main(String[] args) {
System.out.println(new Welcome());
}
}

 : What is the behavior is expected from below code ?
1. It will compile and run perfectly and product output as "Value of counter is 10"

2. It will compile and run perfectly and product output as "Value of counter is 0"

3. Code will not compile as no valid Welcome(int) method is defined.

4. Code will not compile because, you are trying to restrict the visibility of toString() method.

5. As we know, every class by default extends the Object class. Which has public toString() method. Hence, you cannot restrict the access modifiers
for the overridden method.

Correct Answer : 4
Explanation:


Related Questions


Question : Which action can be used to load a database driver by using JDBC.?


 : Which action can be used to load a database driver by using JDBC.?
1. Add the driver class to the META-INF/services folder of the JAR file

2. Include the JDBC driver class in a jdbc.properties file.

3. Use the java.lang.Class.forName method to load the driver class.

4. Use the DriverManager.getDriver method to load the driver class.



Question : You have been given below code, what is the expected behavior assume below path does not exist "/com/HadoopExam.java" ?

package com.hadoopexam;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

class Welcome {

public static void main(String[] args) throws IOException {
Path p1 = Paths.get("/com/HadoopExam.java");
System.out.println(p1.getNameCount() + ":" + p1.getName(1) + ":" + p1.getFileName());
}
}
 : You have been given below code, what is the expected behavior assume below path does not exist
1. It will give compile time error.

2. It will throw "NullPointerException"

3. It will throe "FileNotFoundException"

4. It will print "2:HadoopExam.java:HadoopExam.java"

5. It will print "2:com:HadoopExam.java"



Question : You have been given below code, what is the expected behavior?

package com.hadoopexam;

import java.util.concurrent.atomic.AtomicInteger;

class Welcome implements Runnable {
private static AtomicInteger count = new AtomicInteger(5);

public void run() {
int counterValue = count.incrementAndGet();
System.out.print(counterValue + " ");
}

public static void main(String[] args) {
Thread thread1 = new Thread(new Welcome());
Thread thread2 = new Thread(new Welcome());
Thread thread3 = new Thread(new Welcome());
Thread[] ta = { thread1, thread2, thread3 };
for (int x = 0; x < 3; x++) {
ta[x].start();
}
}
}

 : You have been given below code, what is the expected behavior?
1. It will print 5,5,5

2. It will print 5,6,7 but order can be anything

3. It will print 6,7,8

4. It will print 6,7,8 but its order can be anything

5. It will anything in any order



Question : You have been given below code,

package com.hadoopexam;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Welcome {

public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
System.out.print ("What is your course id? : ");
//n1
}
}
Which of the below code segment you will use, so that it can read the values entered from keyboard by user?
 : You have been given below code,
1. int courseId = Integer.parseInt (bufferedReader.readline());

2. int courseId = bufferedReader.read();

3. int courseId = bufferedReader.nextInt();

4. int courseId = Integer.parseInt (bufferedReader.next());



Question : You have been given below code, what is the behavior expected?

package com.hadoopexam;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

class Welcome {

public static void main(String[] args) throws IOException {
Path source = Paths.get ("resources\\test\\Message.properties");
Path destination = Paths.get("resources");
Files.copy(source, destination);
}
}
 : You have been given below code, what is the behavior expected?
1. It will create a new file name Message.properties in resources directory.

2. It will create a new file "resources\\resources\\test\\Message.properties"

3. It will throw run time exception, with " FileAlreadyExistsException"

4. It will not do anything , just run and come out.



Question : You have been given below code, what is the expected behavior?

package com.hadoopexam;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

class Welcome {

String course, name, city;

public Welcome(String name, String course, String city) {
this.course = course;
this.name = name;
this.city = city;
}

public String toString() {
return course + ":" + name + ":" + city;
}

public String getCourse() {
return course;
}

public void setCourse(String course) {
this.course = course;
}

public static void main(String[] args) throws IOException {
List stds = Arrays.asList(
new Welcome ("Amit", "Hadoop", "Chennai"),
new Welcome ("Kumar", "Spark", "New Delhi"),
new Welcome ("Jatin", "AWS", "Kolkata"));
stds.stream().collect(Collectors.groupingBy(Welcome::getCourse)).forEach((src, res) -> System.out.print(src+":"));
}
}

 : You have been given below code, what is the expected behavior?
1. It will print "Hadoop:Spark:AWS:"

2. It will print "Jatin:Kumar:Amit:"

3. It will print "New Delhi:Chennai:Kolkata:"

4. It will not print "Jatin:New Delhi:Chennai:"