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
All questions

These questions are part of the practice quiz. Start practicing

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

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy