Browse all practice questions for the Java FPT Software (Fsoft) Academy Practice Test. Search by topic, open any question and review its full explanation, then test yourself in the practice quiz.

Java FPT Software (Fsoft) Academy Practice Test course image
More practice questions

These questions are part of the practice quiz. Start practicing

  • What will happen when you compile and run the following Java code? abstract class Base { abstract void amethod(); static int i; } public class Derived extends Base { public static void main(String[] argv) { int[] ar = new int[5]; for (i = 0; i < ar.length; i++) System.out.print(ar[i]); } }
  • Generics basics and an example of a bounded wildcard.
  • Which class is used to read characters and strings in Java from the console?
  • What is the result of compiling code that declares a raw List and calls sort() without a comparator?
  • Which statement about the enum-based singleton pattern is true?
  • When repeatedly calling readLine() on a BufferedReader until no more data remains, what is returned at end of stream?
  • Which statement about CopyOnWriteArrayList is true?
  • Which type of dependency injection in Spring provides dependencies via the class constructor?
  • Which approach is commonly used to propagate checked exceptions from a stream operation without altering method signatures?
  • Evaluate the following do-while loop behavior: do{ if(count % 3 == 0) continue; sum += count; } while(count++ < 11); System.out.println(sum); If sum starts at 0 and count starts at 0, what is printed?
  • If you store the result of d.substring(1,7) into a new variable t while d is 'bookkeeper', what is t?
  • What do wait(), notify(), and notifyAll() do in Java concurrency?
  • Which tool is used to compile Java code?
  • Which statement best differentiates method overloading from method overriding?
  • Which statement best describes what happens when you compile and run the following code? class Triangle { public int base; public int height; private final double ANGLE; public void setAngle(double a) { ANGLE = a; } public static void main(String[] args) { Triangle t = new Triangle(); t.setAngle(90); } }
  • Which expression creates a String at compile time due to constant folding?
  • Which statement demonstrates a concise way to create a comparator that sorts by name using Java 8 features?
  • In Java, if a method receives an int parameter and prints the parameter value after applying the pre-increment operator (++), what value is printed first?
  • Which statement prints to the standard output in Java?
  • In Java, when a subclass is instantiated, in what order are the constructors invoked?
  • Which singleton pattern approach provides thread-safety with lazy initialization using the Initialization-on-demand Holder idiom?
  • If a list l contains at least two elements, what does l.subList(1, 1) return?
  • Which annotation meta-annotation controls whether an annotation is retained at runtime?
  • Which statement initializes a list with two string elements "Name 1" and "Name 2"?
  • What will be printed by the two showMe() calls on the Data class, the first with an integer argument 10 and the second with the string argument 'Z'?
  • What will be printed when iterating a two-dimensional array {{1,2,3},{4,5}} with a nested loop that prints elements and breaks the inner loop when an element equals 2, followed by a continue for the outer loop?
  • Which is correct format of writing JSON name/value pair?
  • Which statement will throw a NullPointerException when executed?
  • Which statement will cause the Travel.go() method to compile? public class Travel { ArrayList<Hotel> go() { // insert code here } }
  • What does Java serialization do?
  • In a ragged two-dimensional array declared as int[][] a = new int[2][]; a[0] = new int[3]; a[1] = new int[2]; What is a[1].length?
  • If a String d initially holds 'bookkeeper', you call substring(1,7) but do not assign the result, then set d to 'w' + d, and then call append on d; what happens?
  • In the given Java snippet, the line creating an ObjectOutputStream uses ObjectOutputstream (lowercase s). What is the result?
  • Given a class A with a method baz and a subclass B that overrides baz, what is the result when you execute A a = new B(); a.baz()?
  • Which practice most improves Java performance by reducing boxing and unnecessary synchronization?
  • What is the main purpose of the double-checked locking pattern with volatile in lazy initialization?
  • Which statement about interfaces and inheritance in Java is correct?
  • Which import statement is required to use ArrayList in Java?
  • Consider a snippet that creates a StringBuilder sb with '12345678', sets its length to 5, then attempts to set length to 10, and then prints sb.length() with an invalid argument; will it compile?
  • What is the behavior of a static field in a class?
  • Given i = 0 and j = 11, after a loop that decrements j and increments i in the condition, what is printed?
  • Which pattern is commonly used for thread-safe lazy initialization using a static inner class?
  • Which statement is true about eager initialization of a singleton?
  • After executing sb = new StringBuilder('12345678'); sb.setLength(5); sb.setLength(10); what is sb.length()?
  • Which line can be added to the following class to ensure the final boolean field is properly initialized so the code compiles? public class InitTest { static int si = 10; int i; final boolean bool; // 1 }
  • Which class is used to read characters from a text file?
  • Which annotation is used to indicate that a method overrides a method in a superclass?
  • If s1 is assigned 'abc', s2 is assigned 'def', s3 is set to s2, then s2 is changed to 'ghi'; what is printed when concatenating s1, s2, and s3?
  • If you reassign a parameter that holds an object reference inside a method, does the original reference in the caller change?
  • Can null value be added to a List?
  • Which tool is used to execute Java code?
  • If the code compiles and reaches the try block, what will be printed?
  • Which pairing is a typical combination in the Java Collections Framework?
  • What does File.length() return?
  • Which of the following demonstrates polymorphism?
  • Explain fail fast versus fail safe iterators with examples.
  • Which statement correctly describes the differences among String, StringBuilder, and StringBuffer?
  • Which feature of java.util.concurrent Locks allows configuring thread acquisition order?
  • In Java, how are primitive arguments passed to methods?
  • What does List<? extends Number> mean for type safety?
  • What happens to the monitor when a thread calls wait() on an object?
  • Which operator or keyword is used to determine the type of an object at runtime in Java?
  • Which statement best describes type erasure in Java generics?
  • What was the earlier name of the Java programming language?
  • Which of the following is considered a common SQL anti-pattern in Java applications?
  • What will happen when adding null to a List<Integer> and then summing with auto-unboxing?
  • What is the value of a[3] for the array int[] a = {1, 2, 3, 4};
  • How can Java achieve multiple inheritance?
  • In Java, what are the results of the following comparison: a = new String('x'); b = new String('x'); System.out.println(a == b); System.out.println(a.equals(b));
  • Which statement about inheritance in Java is true?
  • JSON stands for which of the following?
  • Which statement about lambda expressions is true?
  • After execution of the code fragment where int x, a = 6, b = 7; x = a++ + b++; what are the values of x, a, and b?
  • What is the default value of each element in a newly created int[] array?
  • Which of the following is a valid JSON representation for an object with name 'Alice' ?
  • Which of the following command sequences will compile a Java class named MyFirstClass and run it with the arguments hello and hello?
  • What will happen when you compile and run code that prints a five-element int array where no values are assigned?
  • In Java, what is the difference between the equality operator and the equals method?
  • What is printed by the following Java code snippet? int[] ar = new int[5]; for (int i = 0; i < ar.length; i++) System.out.print(ar[i]);
  • Which of the following is a valid way to declare a String with content 'Hello'?
  • Which statement about interfaces best describes their role?
  • Which statement about ObjectOutputStream's writeObject method is true?
  • Which command prints Hello! when run with the arguments open and someone?
  • In a scenario with nested loops, if the inner loop runs three times for each outer iteration, how many total inner iterations occur across all outer iterations?
  • Which statement about Runnable and Callable is correct?
  • In a two-dimensional array example where the inner loop breaks on the value 2, what is the printed sequence?
  • What is the result of evaluating the following expression? String s = "ab"; String t = "a" + "b"; System.out.println(s == t);
  • Which JDBC interface is used to call stored procedures?
  • Which characteristic defines a functional interface in Java?
  • What is the result of the following primes code, considering the line 'List p = = new ArrayList();' is in the program?
  • Which of the following is not a primitive data type in Java?
  • Which memory area in the JVM stores Java objects?
  • Which File method tests the existence of a file or directory?
  • Which expression correctly provides a default value using Optional when x might be null?
  • What is the result of the expression new String("Hello").equals("Hello")?
  • Which line creates an Employee instance?
  • How many times will the value 2 be printed in a nested loop where the outer loop iterates over three elements and the inner loop runs with a counter from 0 to 2 for each element?
  • If a method assigns its String parameter to a new value, does the original variable in the caller reflect that change?
  • What is the purpose of a database connection pool?
  • What is the key difference between map() and flatMap() in Java Streams?
  • To use FileReader and BufferedReader, which import is necessary?
  • In the following Java code, which lines are printed? for (int i = 0; i < 2; i++) { for (int j = 0; j < 3; j++) { if (i == j) { continue; } System.out.println("i = " + i + " j " + j); } }
  • Given the following code, what is the result when compiling and running? A subclass attempts to override a method with a different primitive return type, and the code uses the subclass instance to call the method.
  • Which statement accurately describes PreparedStatement in JDBC?
  • In Java, which statement best describes the difference between shallow copies and deep copies?
  • Which of the following keywords cannot be used when declaring a class?
  • In Java Streams, which operation is terminal and triggers evaluation?
  • What value is printed by the program that initializes var to 20 and uses a do-while with inner loops, finally printing var?
  • Which technique can help prevent deadlocks by using a timeout when acquiring locks?
  • Which statement best describes Dependency Injection and how a DI container works in Spring (basic)?
  • Which package contains the File class?
  • Which statement about try-with-resources with multiple resources is true?
  • Consider a class that declares int[] ia = new int[1]; Object[] oA = new Object[1]; boolean bool; and prints ia[0] + ' ' + oA[0] + bool. What is the printed result?
  • From a Java perspective, which statement best contrasts REST and SOAP web services?
  • Which method is used to call the constructors of the superclass from the subclass?
  • Given a = 5 and b = 9; x = a++ + b++; what are x, a, b after the expression?
  • Which class is used to write objects to a file?
  • Which statement best describes inheritance in Java?
  • If a static int field is declared but not initialized, what is its default value?
  • Which keyword is used to create an instance of a class?
  • Is String considered a wrapper class in Java?
  • In a class SomeClass with methods of varying access modifiers, which set of method calls from another class in the same package are valid?
  • In a Java program where i is initialized to 10 and a static variable j is initialized to 20, a method doubles its parameter and doubles j. After calling the method with i, what values are printed for i and j?
  • What does System.out.println(5 + 3); print?
  • What is the value of d after calling substring(1,7) on the string 'bookkeeper' if the returned value is not assigned to any variable?
  • What is the default access modifier for an interface method?
  • Which exception is typically caught for I/O operations in Java?
  • What is the difference between HashMap and ConcurrentHashMap?
  • String[] seasons = {"winter", "spring", "summer", "fall"}; What is seasons.length?
  • Which method reads a line of text from a BufferedReader?
  • Given a List<String> al that has two elements added, what is al.size()?
  • Which statement makes a class serializable?
  • What is autoboxing and unboxing in Java, and what are potential performance implications?
  • If b starts as 8 and c starts as 3, what is the value of b after performing b = (byte) (b ^ c)?
  • Who is considered the father of the Java programming language?
  • Which statement best characterize a deep copy?
  • Which declaration would allow the code that uses a 2D List named table to compile when inserting at the designated declaration point?
  • Which statement is true about primitive types and wrapper classes in the context of autoboxing?
  • Which Java class is a widely used example of immutability?
  • What is printed when running a program with no command-line arguments that computes k = m1(args.length); k += 3 + ++k; System.out.println(k);?
  • Consider the following code snippet: StringBuffer s = new StringBuffer("Hello"); if ((s.length() > 5) && s.append("there").equals("Fa1se")); // do nothing System.out.println("value is " + s); What is the output?
  • What is the output of this code fragment? int x = 3; int y = 10; System.out.println(y % x);
  • In a do-while loop, which statement best describes how many times the loop body is executed?
  • In a loop that contains a break inside the inner loop, which loop is terminated by the break?
  • Which Optional expression correctly transforms a present value using a map to lower case?
  • Which declaration initializes an array in a single statement with five elements?
  • Which statement best describes encapsulation with a simple example?
  • Which statement is true about comparing arrays with Arrays.equals(a, b) versus using a.equals(b)?
  • Given the snippet: String s = "Hello"; if (s.length() > 5) { s += "There"; } System.out.println("value is " + s); What is printed?
  • What is the value of j after executing the following? int i = 0; int j = i++ + ++i; System.out.println(j);
  • Given the method skeleton with invalid syntax in Java, such as int radix 2; and misused else blocks, what is the result of compiling this method?
  • JSON stands for JavaScript Object Notation.
  • What will the following program print? The variable c starts at 0 and a flag is true; within a loop the counter increments until certain conditions deactivate the flag. What is printed?
  • Which statement describes try-with-resources in Java?
  • If a subclass overrides a method and an object is referenced by its superclass type, which implementation is executed at runtime?
  • Which statement about volatile variables is false?
  • In the example where a static integer a is initialized to 40, what is printed by the program?
  • What are the default values for elements of int[] and boolean[] when a new array is created in Java?
  • Which statement about abstract methods is true?
  • In Java, attempting to override a method in a subclass by changing its primitive return type results in what?
  • If the serialVersionUID of a class changes and you attempt to deserialize an older serialized form, what happens?
  • In Java, what is the purpose of the super keyword in a subclass constructor?
  • In the Computer class, the field k is declared as a Keyboard and initialized with new Keyboard(). This demonstrates what concept?
  • Which singleton pattern is most resistant to reflection attacks and serialization issues?
  • Given a superclass with a constructor Dog(String name) and a subclass Beagle that defines only one constructor, which Beagle constructor would be legal?
  • If a program defines s as 'hello' (String) and sb as StringBuilder('hello'), then sb.reverse() is called and s.reverse() is attempted; what happens?
  • Which statement about List, Set, and Map is correct?
  • Which statement about comparing arrays with the operator '==' is true?
  • What is printed when the following method is invoked with an argument 4?
  • Which technique is commonly used to implement pagination in JDBC queries?
  • Consider the code snippet: int arr[2]; System.out.println(arr[0]); System.out.println(arr[1]); What happens when compiling and running this code in Java?
  • If an array has length n, what is the index of its last element?
  • Which statement correctly describes method overloading?
  • Which statement about protected access in Java is true?
  • When do Java static initialization blocks execute?
  • Which checked exception must be handled or declared when performing file I/O operations in Java?
  • Can you extend an interface in Java?
  • What happens if you try to instantiate an abstract class?
  • Which statement about garbage collection in Java is correct?
  • What results from running the following code where b is 10 and c is 15, and b is assigned as (byte) (b ^ c)?
  • Which statement about the default constructor in Java is true?
  • Which statement correctly describes typical error handling for file I/O in Java?
  • When overriding a method, which statement is true about its visibility?
  • Given this code: int x = 0, y = 4, z = 5; if (x > 2) { if (y < 5) { System.out.println("message one"); } else { System.out.println("message two"); } } else if (z > 5) { System.out.println("message three"); } else { System.out.println("message four"); } What is printed?
  • After the method returns, what value is printed for the original int variable in the caller when printing it in main?
  • Can an abstract class be declared final?
  • Which statement about static fields is true?
  • Which statement correctly describes checked versus unchecked exceptions in Java?
  • What is true about static fields in Java?
  • Which statement best describes volatile variables in Java in terms of visibility and ordering?
  • In a nested loop that builds 11 rows (i from 0 to 10) each row containing 11 elements (j from 0 to 10), how many elements are in each inner row?
  • Assuming the declarations int i = 10, j = 12, k = 1; k += i++ - --j; what is the value printed for k?
  • Which option is commonly used to read a string from standard input in Java?
  • Which Map implementation maintains keys in natural order or by a comparator?
  • Which statement about reading and writing files with NIO is true?
  • Which technique is commonly used to perform a deep copy by converting an object graph to a byte stream and back?
  • Which class declaration is valid in a Java file named Example.java?
  • Which statement accurately reflects the equals/hashCode contract?
  • Which feature was introduced in Java 9 as part of the module system?
  • What is the difference between default methods in interfaces and abstract classes in Java?
  • Given int[] a = {1, 2, 3}; int[] b = {1, 2, 3}; System.out.println(a == b);
  • When used as a stack or queue, which statement is most accurate?
  • Which statement best describes how Java passes arguments to methods?
  • Given two strings created as follows: String s1 = "abc" + "def"; String s2 = new String(s1); Which statement is true?
  • Given int[] arr = new int[3]; System.out.println(arr.length); What is printed?
  • Given the following switch structure, what is printed when i equals 5? switch (i) { default: case 1: System.out.println(1); case 0: System.out.println(0); case 2: System.out.println(2); break; case 3: System.out.println(3); }
  • What is the output of the following snippet: int a=1; int b=a++; int c=++a; System.out.println(a + " " + b + " " + c);
  • Which statement about the modulo operator is true in Java?
  • Given two int arrays arr1 and arr2 initialized as {1, 2, 3} and {1, 2, 3} respectively, what is the result of Arrays.equals(arr1, arr2) in Java?
  • Which class is used to write primitive data types to a stream in Java?
  • Which statement about Java wrapper types like Integer is true?
  • Which description best captures the Java Collections Framework?
  • What is a key advantage of Lock over synchronized blocks in Java?
  • Which of the following is a valid way to declare an array in Java?
  • Which constructor initializes x when given an integer argument?
  • Given a superclass MySuper with a constructor that prints values and a subclass MySub that calls super(2) and then prints, what is the output when creating a new MySub()?
  • For the following program snippet, what happens when run with the command line arguments java Test closed?
  • Which of the following is a valid JSON object literal with name Bob and age 30?
  • Which statement is true about serialization of transient and static fields in Java?
  • Which statement accurately describes immutability in Java?
  • Which statement best describes the compilation result of the code snippet that initializes an integer with syntax int k 2; while(--k) { System.out.println(k); } ?
  • When two int variables are passed to a method that attempts to swap their values by parameter, which statement is true?
  • If a class has a static int count initialized to 0, and its constructor increments count, what is the printed value after creating three objects and printing count?
  • Assume a Java program declares int size = 10; int[] arr = new int[size]; and prints each element in sequence with no separators. Without any assignment to arr, what is printed?
  • Which statement about Java Streams is true?
  • Which memory area in the JVM stores loaded class metadata?
  • What is a primary benefit of using a thread pool in Java?
  • How does ArrayList resize when its capacity is reached?
  • Which approach is commonly used to expose different API versions in RESTful URLs?
  • Which statement about Path and Files APIs is true?
  • Which keyword is used to inherit a class?
  • What is the primary purpose of serialVersionUID in Java serialization?
  • Which statement best describes the goal of the G1 garbage collector?
  • Which statement is the canonical Java main method signature for the program entry point?
  • Which RESTful practice is specifically aimed at enabling efficient client-side caching?
  • Which constructor initializes y when given a string argument?
  • What does List.subList(int fromIndex, int toIndex) return?
  • Which declaration initializes an array in a single statement with exactly five elements?
  • Which statement best describes the difference between character streams and byte streams in Java?
Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy