Check out Part 1 - Oracle Java Certification Exam Sample Questions - Part 1.The answer to each question has given at end of this post.
1. Which is a valid functional interface?
public interface Useful<E> {
E getStuff();
void putStuff(E e);
}
public interface Useful {
void doStuff();
default void doOtherStuff() {}
}
@FunctionalInterface
public interface Useful{
default void doStuff(){}
}
public interface Useful {
abstract void doStuff();
abstract void doCalc();
}
2. Given:
public abstract class Customer {
private String name;
public Customer(String name) {
this.name = name;
}
public String getName() {
return name;
}
public abstract void buy();
}
3. Given the code fragment:
import java.util.ArrayDeque;
import java.util.Queue;
public class App {
public static void main(String[] args) {
Queue < String > products = new ArrayDeque < String > ();
products.add("p1");
products.add("p2");
products.add("p3");
System.out.print(products.peek());
System.out.print(products.poll());
System.out.println("");
products.forEach(s - > System.out.print(s));
}
}
p1p1
p2p3
p1p2
p1p2p3
p1p2
p3
p1p1
p1p2p3
4. Given the code fragment:
try (Connection con = DriverManager.getConnection(url, uname, pwd)) {
Statement stmt = con.createStatement();
System.out.print(stmt.executeUpdate("INSERT INTO User VALUES (500,'Ramesh')"));
}
5. Given the code fragment:
public class TestFun {
public static void main(String[] args) {
List<Integer> nums = Arrays.asList(1,2,3,4,5);
// Line n1
}
}
nums.peek(n -> n%2 == 0)
.forEach( s -> System.out.print(" "+s));
nums.filter(n -> n%2 == 0)
.forEach( s -> System.out.print(" "+s));
nums.map(n -> n%2 == 0)
.forEach( s -> System.out.print(" "+s));
nums.stream()
.filter(n -> n%2 == 0)
.forEach( s -> System.out.print(" "+s));
Answers
1. B2. B and E
3. A
4. C
5. D
Continue Learning with Java Guides
Want to take your programming skills to the next level? Explore my practical Udemy courses on Java, Spring Boot, Microservices, Full-Stack Development, Docker, and Generative AI. You can also follow my structured learning roadmaps to become a professional developer.
By Ramesh Fadatare - Udemy Instructor Partner
Comments
Post a Comment
Leave Comment