By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
methods Functions that can be performed on an object
static public class Simple { public ______ void main(String args[]) }
void public class Simple { public static ____ main(String args[]) }
main public class Simple { public static void ____(String args[]) }
args[] public class Simple { public static void main(String _____) }
String public class Simple { public static void main(____ args[]) }
-cp // to compile javac ___ <classesPaths> -d <compilerOutputPath> <pathToSource>.java
classesPaths // to compile javac -cp <_______> -d <compilerOutputPath> <pathToSource>.java
-d // to compile java -cp <classesPaths> __ <compilerOutputPath> <pathToSource>.java
compilerOutputPath // to compile java ___ <classesPaths> -d <_________> <pathToSource>.java
pathToSource // to compile java -cp <classesPaths> -d <compilerOutputPath> <_________>.java
.java // to compile java ___ <classesPaths> -d <compilerOutputPath> <pathToSource>______
if // if statement ____ (a == b) { System.out.println('True'); } else { System.out.println('False'); }
else // if statement if (a == b) { System.out.println('True'); } ____ { System.out.println('False'); }
switch // switch statement _____ (color) { case 'Blue': shirt = 'Blue' + shirt; break; case 'Red': shirt = 'Red' + shirt; break; default: shirt = 'White' + shirt; }
case // switch statement switch (color) { _____ 'Blue': shirt = 'Blue' + shirt; break; _____ 'Red': shirt = 'Red' + shirt; break; default: shirt = 'White' + shirt; }
default // switch statement _____ (color) { case 'Blue': shirt = 'Blue' + shirt; break; case 'Red': shirt = 'Red' + shirt; break; _____: shirt = 'White' + shirt; System.out.println('' + shirt); }
while // while loop _____ (x < 20) { System.out.print('x: ' + x); x++; System.out.print('\n'); }
() // while loop while _x < 20_ { System.out.print('x: ' + x); x++; System.out.print('\n'); }
for // for loop ____ (int i = 0; i < 9; i++) { System.out.println('' + i); }
; // for loop for (int i = 0_ i < 9_ i++) { System.out.println('' + i); }
++ // for loop for (int i = 0; i < 9; i__) { System.out.println('' + i); }
name //iterate over array of int int[] numbers = {100,200,300}; for (String ____:names){ System.out.println('Name' + name); }
names //iterate over array of int int[] numbers = {100,200,300}; for (String name:____){ System.out.println('Name' + name); }
StringBuilder //creating StringBuilder _______ sb = new StringBuilder('hello');
new //creating StringBuilder StringBuilder sb = ___ StringBuilder('hello');
append //adding to a StringBuilder instance StringBuilder sb = new StringBuilder('hello'); sb.______(', how are you?');
insert //how to insert sb._____(::number::, ' Fine');
length //how to get a length of StringBuilder sb.______()
ClassName //build a constructor in a class public ________ () { }
mutators Methods that set the value of each field are called ______
this //build a class accessor public void setId (int id) { ____.Id = id; }
new //create an instance ClassName cn = ___ ClassName();
namespace A package is implemented as a folder and, like a folder, provides a _______ to a class
//com.example.domain +com |_+example |_+domain |_+Employee.java |_+Manager.java
reference For Java objects, the value of the right side of an assignment is a ________ to memory that stores a Java object
130000.0 //what does this return? public class ObjectPassTest { public static void main(String[] args) { ObjectPassTest test = new ObjectPassTest(); Employee x = new Employee(); x.setSalary(120_000.00); test.foo(x); System.out.println('' + x.getSalary()); } public void foo(Employee e){ e.setSalary(130_000.00); e = new Employee(); e.setSalary(140_000.00); } }
hashCode It is necessary to override the ______ method whenever this the equals method is overridden
... //make this varargs friendly public class Statistics { public float average(int___ nums) { int sum = 0; for (int x: nums) { sum += x; } return ((float) sum / nums.length } }
Manager //make code compile public static void main(String[] args){ Employee e = new Manager(); if (e instanceof Manager){ Manager m = ( _____ ) e; m.setDeptName('HR'); System.out.println(m.getDetails()); } }
initializer The static _______ block is a code block prefixed by the static keyword
//example static boolean[] switches = new boolean[5]; _____ { System.out.println(''); for (int i=0; i<5; i++) { switches[i] = true; } }
import A static _____ statement makes the static members of a class available under their simple name
//example _____ static java.lang.Math.random; import static java.lang.Math. - ;
public class StaticImport { public static void main(String[] args) { double d = random(); } }
singleton The ______ design pattern details a class implementation that can be instantiated only once
final //make a Singleton public class SingletonClass { private static ____ SingletonClass instance = new SingletonClass(); private SingletonClass() {} public static SingletonClass getInstance() { return instance; } }
arguments An abstract method can take ______ and return values
child When inheriting from an abstract class, you must do either of the following: (1) Declare the _______ class as abstract (2) Override all abstract methods inherited from the parent class.
methods When inheriting from an abstract class, you must do either of the following: (1) Declare the child class as abstract (2) Override all abstract ______ inherited from the parent class.
compile Enumerations provide a ______-time range check
enum //make an enumeration public _____ PowerState { OFF, ON, SUSPEND; }
extends If you use both extends and implements, ________ must come first
new //Make an Anonymous inner class Z04Analyzer.searchArr(strList01, ___ StringAnalyzer() { @Override public boolean analyze(String target, String searchStr) { return target.contains(searchStr); } } });
generics _________ provide flexible type safety to your code, reduce the need for casting with collections and move many common errors from run time to compile time
cache //example of a simple ______ class public class CacheString { private String message; public void add(String message){ this.message = message; } public String get(){ return this.message; } }
generic //example of a _______ class public class CacheAny<T> { private T t; public void add(T t) { this.t = t; } public T get() { return this.t; } }
types With generics, S and U are used if there are second or third ______
<String> //Write generic of the following CacheString myMessage = new CacheString(); CacheAny_____ myGenericMessage = new CacheAny_____();
() //Write generic of the following CacheString myMessage = new CacheString(); CacheAny<String> myGenericMessage = new CacheAny<String>__;
<> //Use generics to add compile time check List partList = new ArrayList(3);
List<Integer> partList = new ArrayList__(3);
Unbox //_____ Integer collection for (Integer partNumberObj:partList) { int partNumber = partNumberObj; System.out.println('Part number: ' + partNumber); }
null A HashMap implementation justlike Hashtable except that it accepts ____ keys and values
() //implement a TreeMap public class MapExample { public static void main(String[] args) { Map<String, String> partList = new TreeMap<>__; //.... } }
<> //implement a TreeMap public class MapExample { public static void main(String[] args) { Map<String, String> partList = new TreeMap__(); //.... } }
TreeMap //implement a TreeMap public class MapExample { public static void main(String[] args) { Map<String, String> partList = new ______<>(); //.... } }
deque A ______ is a 'doubled-ended queue'
ArrayDeque //example of a _______ public class Teststack { public static void main(String[] args) { Deque<String> stack = new ________<>(); stack.push('one'); } }
sorting The Comparator interface enables you to create and use numerous ______ options
Builder //example of the ______ pattern people.add( new Person.______() .givenName('Betty') .surName('Jones') .age(85) .gender(Gender.FEMALE) );
variable //use of lambdas as a ______ Predicate<Person> allPilots = p -> p.getAge() >= 23 && p.getAge() <= 65;
p1.stream().filter(allPilots).forEach(p -> rob.roboCall(p));
:: //make reference to a static method ContainingClass__staticMethodName
supplier In the context of a stream this provides an instance of a T (such as a factory)
predicate //example of _____ package java.util.function; public interface ______<T> { public boolean test(T t); }
consumer //example of a _____ ______<SalesTxn> buyer = t -> System.out.println('Id: ' + t.getTxnId() + ' Buyer: ' + t.getBuyer().getName()); System.out.println('== Buyers - Lambda'); tList.stream().forEach(buyer); System.out.println('== First Buyer - Method'); buyer.accept(first);
Function //example of a ______ package java.util._____; public interface ______<T, R> { public R apply(T t); }
Supplier //example of a _____ package java.util.function;
public interface _______<T> { public T get(); }
double //complete primitive type return package java.util.function; public interface ToDoubleFunction<T> { public ____ applyAsDouble(T t); }
R //process a primitive type package java.util.function; public interface DoubleFunction<R> { public __ apply(double value); }
boolean //complete a BiPredicate package java.util.function; public interface BiPredicate<T, U> { public ______ test(T t, U u); }
T //take class as input and return //object of the same class package java.util.function; public interface UnaryOperator<T> extends Function<T, T> { @Override public __ apply(T t); }
super //accept this & any parent types ? _____ T
extends //accept this & any child types ? ______ T
result A terminal operation in a store pipeline produces a _____ or side effect
intermediate //stream methods //below: examples of _____ //operations filter() --- map() --- peek()
terminal //stream methods //below: examples of ____ //operations forEach() --- count() --- sum() --- average() --- min() --- max() --- collect()
short-circuit //stream methods //each below is a Terminal ___ findFirst() --- findAny() --- anyMatch() --- allMatch() --- noneMatch()
map A ____ takes one Function as an argument. A Function takes one generic and returns something else //code ___(Function<? super T, ? extends R> mapper)
peek The ____ method performs the operation specified by the lambda expression and returns the elements to the stream. //code _(Consumer<? super T> action)
max //in stream return biggest //element of this stream //according to Comparator __(Comparator<? super T> comparator)
min //in stream return smallest //element of this stream //according to Comparator __(Comparator<? super T> comparator)
Comparator //return sort according 2 comp sorted(______<? super T> comparator)
comparing The _______ method allows you to specify any field to sort on based on a method reference or lambda //_(Function<?superT,?extendsU> keyExtractor)
collect The ______ method allows you to save the result of a stream to a new data structure //example stream().collect(Collectors.toList());
averagingDouble The ______ method of the Collectors class produces the arithmetic mean of a double-valued function applied to the input elements //code averagingDouble(ToDoubleFunction<? super T> mapper)
groupingBy The ______ method of the Collectors class operates on input elements of type T, grouping elements according to a classification function, and returning the results in a map //code _(Function<?superT,?extendsK>classifier)
joining The ___ method of the Collectors class concatenates the input elements into a String, in encounter order
partitioningBy The _____ method of the Collectors class partitions the input elements according to a Predicate //code _(Predicates<?superT>predicate)
of The Stream.__ method allows you to easily create a stream //example Stream.of('Monday','Tuesday').filter(s -> s.startsWith('T')).forEach(s -> System.out.println('Matching Days: ' + s));
catch //complete try { InputStream in = new FileInputStream('missing file.txt'); } __ (Exception e) { System.out.println('Something went wrong'); }
try //complete __ { InputStream in = new FileInputStream('missing file.txt'); } catch (Exception e) { System.out.println('Something went wrong'); }
finally //complete try { in = new FileInputStream('missing file.txt'); } catch (IOException e) { System.out.println(e.getMessage()); } __ { try { if(in != null) in.close(); } catch(IOException e) { System.out.println('Failed to close file'); } }
IOException //complete try { in = new FileInputStream('missing file.txt'); } catch (______ e) { System.out.println(e.getMessage()); } finally { try { if(in != null) in.close(); } catch(IOException e) { System.out.println('Failed to close file'); } }
try-with-resources //example of _______ try(InputStream in = new FileInputStream('missing file.txt')) { System.out.println('File open'); int data = in.read(); } catch ...
| //perform multi-catch try () { } catch (ClassNotFoundException _ IOException e) { System.out.println(); }
throws //complete public static int readByte() _____ IOException {...}
: //descriptive assertion assert booleanExpression _ expression;
assert //complete assertion _____ booleanExpression;
internal //ex. of __ invariant use int x = num; if (x > 0) { System.out.print('+'); } else if (x == 0) { System.out.print('0'); } else { assert (x > 0); }
control //ex. of ____ flow invariant switch(suit) { case Suit.CLUBS: // break; case Suit.DIAMONDS: // break; default: assert false: 'Unknown'; break; }
class A _____ invariant is one that an object must satisfy in order to be a valid member of a class
class //ex. of ____ invariant public class PersonClassInvariant { String name; String son; int age; private void checkAge() { assert age >= 18 && age < 150; } public void changeName(String fname) { checkAge(); name=fname; } }
ea //turn on assertions java -__ MyProgram
LocalDate Questions that you can answer with _______: (1) Is it in the future or past? (2) Is it in a leap year? (3) What day of the week is it? (4) What is the day a month from now? (5) What is the date next Tuesday?
LocalTime Questions that you can answer with _______: (1) When is my lunch time? (2) Is lunch time in the future or past? (3) What is the time 1 hour 15 minutes from now? (4) How many minutes until lunch time? (5) How many hours until bedtime? (6) How do I keep track of just the hours and minutes?
LocalDateTime Questions you can answer the following questions with _______: (1) When is the meeting with corporate? (2) When does my flight leave? (3) When does the course start? (4) If I move the meeting to Friday, what is the date? (5) If the course starts at 9 AM on Monday and ends at 5 PM on Friday, how many hours am I in class?
() The three basic byte read methods are: (1) int read__ (2) int read(byte[] buffer) (3) read(byte[] buffer, int offset, int length)
byte[] The three basic byte read methods are: (1) int read() (2) int read( ____ buffer) (3) read(byte[] buffer, int offset, int length)
offset The three basic byte read methods are: (1) int read() (2) int read( byte[] buffer) (3) read(byte[] buffer, int _____, int length)
close //terminate open stream void ______();
available //get bytes avail in stream int _______();
skip //discard n bytes long ____(long n);
write //3 byte write methods void _(int c) void _(byte[] buffer) void _(byte[], int offSet, int length)
close //auto closed in try-w-r void _____();
flush //force write to the stream void _____();
+= //count bytes read while ((read = fis.read(b)) != -1) { fos.write(b); count __ read; }
read //3 basic read methods int _() int _(char[] cbuf) int _(char[] chuff, int offset, int length)
write //basic write void _(int c) void _(char[] cbuf) void _(char[] cbuf, int offset, int length) void _(String string) void _(String string, int offset, int length)
new //chain streams FileReader //to BufferedFileReader try (BufferedReader bufInput = ___ BufferedReader(__ FileReader(args[0]));
in //chain a buffered reader //to an input stream that //takes the console input try (BufferedReader in = new BufferedReader(new InputStreamReader(System.__)) { ... }
subpath A portion of a path can be obtained by creating a subpath using the _____ method: //example Path subpath(int beginIndex, int endIndex);
detects Every Path method either: (1) ____ what to do when a symbolic link is encountered, or (2) Provides an option enabling you to configure the behavior when a symbolic link is encountered
provides Every Path method either: (1) detects what to do when a symbolic link is encountered, or (2) ____ an option enabling you to configure the behavior when a symbolic link is encountered
isReadable //verify read access to file //using Files Class _______(Path)
isWritable //verify write access to file //using Files Class _______(Path)
isExecutable //verify execute ability //using Files Class _______(Path)
isSameFile //verify method tests to //to see whether two paths //point to the same file ______(Path, Path)
createFile //create a file Files._____(Path dir);
createDirectory //create a directory Files._____(Path dir);
createDirectories //create directories that //don/t exist, from top //to bottom Files.__(Paths.get('/home/foo/bar/example'));
deleteIfExists //delete file/dir/link w/ //no exceptions Files.___(path)
delete //delete file/dir/link w/ //exceptions Files.__(path)
copy //replicate a file or dir Files.__(source, target, REPLACE_EXISTING, NOFOLLOW_LINKS);
move //change location of file/dir Files.__(src, trg, REP_EX);
list //get a list of all of the files Files.__(Paths.get('.'))
walk //walk a dir structure Files.__(Paths.get('.'))
lines //convert BufferedReader //into a stream bReader.____()
readAllLines //load a file into an //ArrayList Files.___(file);
Executors Implementing instances can be obtained with _____ //example ExecutorService es = ____.newCachedThreadPool();
Callable The ____ interface: (1) Defines a task submitted to an ExecutorService (2) Is similar in nature to Runnable, but can: Return a result using generics, throw a checked exception //example package java.util.concurrent; public interface __<V> { V call() throws Exception; }
Future The ___ interface is used to obtain the results from a Callable's V call() method //example __<V> ___ = es.submit(callable); try { V result = __.get(); } catch (ExecutionException|InterruptedException ex) { }
this Synchronized methods use the monitor for the ______ object //example synchronized(___) { }
deadlock //below will cause _____ synchronized(obj1) { synchronized(obj2) { ... } } synchronized(obj2) { synchronized(obj1) { ... } }
availableProcessor //detect number of //processors int count = Runtime.getRuntime().__();
threaded //single-_____ example //1 Gig int[] data = new int[10241024256]; for (int i = 0; i < data.length; i++) { data[i] = ThreadLocalRandom.current().nextInt(); } int max = Integer.MIN_VALUE; for (int value: data) { if (value > max) { max = value; } } System.out.println('Max value found:' + max);
RecursiveTask //__ example public class FindMaxTask extends ____<Integer> { private final int threshold; private final int[] myArray; private int start; private int end; public FindMaxTask(int[] myArray, int start, int end, int threshold) { // copy parameters to fields } protected Integer compute() { // shown later } }
parallelStream //Make parallel stream double result = eList.____()
stateless //mutate the ____ way List<Employee> newList02 = new ArrayList<>(); newList02 = eList.parallelStream() .filter(e -> e.getDept().equals('Eng')) .collect(Collectors.toList());
stateful //mutate the ______ way //doesn't parallelize List<Employee> newList01 = new ArrayList<>(); eList.parallelStream().filter(e -> e.getDept().equals('Eng')) .forEach(e -> newList01.add(e));
associative If the combining function is ______, reduction parallelized cleanly //examples sum, min, max, average
DriverManager You can access them by following the sequence: (1) Use the _______ class to obtain a reference to a Connection object by using the getConnection method (2) Use the Connection object to obtain a reference to a Statement object through the createStatement method (3) Use the Statement object to obtain an instance of a ResultSet through an executeQuery method
Statement You can access them by following the sequence: (1) Use the DriverManager class to obtain a reference to a Connection object by using the getConnection method (2) Use the Connection object to obtain a reference to a _____ object through the createStatement method (3) Use the Statement object to obtain an instance of a ResultSet through an executeQuery method
ResultSet You can access them by following the sequence: (1) Use the DriverManager class to obtain a reference to a Connection object by using the getConnection method (2) Use the Connection object to obtain a reference to a Statement object through the createStatement method (3) Use the Statement object to obtain an instance of a _____ through an executeQuery method
driver //URL for a JDBC driver jdbc:<___>:[subsubprotocol:][databaseName][;attribute=value] //example String url = 'jdbc:derby://localhost:1527/EmployeeDB';
subsubprotocol //URL for a JDBC driver jdbc:<driver>:[ _____:][databaseName][;attribute=value] //example String url = 'jdbc:derby://localhost:1527/EmployeeDB';
databaseName //URL for a JDBC driver jdbc:<driver>:[ subsubprotocol:][ _______ ][;attribute=value] //example String url = 'jdbc:derby://localhost:1527/EmployeeDB';
attribute //URL for a JDBC driver jdbc:<driver>:[subsubprotocol:][databaseName][;____=value] //example String url = 'jdbc:derby://localhost:1527/EmployeeDB';
wrapper To execute SQL queries with JDBC, you must create a SQL query ____ object, an instance of the Statement object //example Statement stmt = con.createStatement();
ResultSet //use the statement //instance to execute //SQL query ____ rs = stmt.executeQuery(query);
executeQuery //use a ResultSet object String query = 'SELECT - FROM Employee'; ResultSet rs = stmt.___(query);
ResultSet Resources held by the _____ may not be released until garbage is collection, therefore, it is a good practice to explicitly close _______ objects when they are no longer needed
resources //try-with-___ try (Connection con = DriverManager.getConnection(url, username, password); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(query)){...}
PreparedStatement ____ is useful when you want to execute a SQL statement multiple times //example PreparedStatement pStmt = con.preparedStatement(query);
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.