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

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

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy