Java SE 11 Fundamentals and API Usage - 1Z0-819 Exam Topic 1 This comprehensive guide covers the first exam topic for Oracle Certified Professional Java SE 11 Developer (1Z0-819), focusing on Java Fundamentals and API usage. This section comprises approximately 15% of the exam content and is essential for building a strong Java foundation.
1. Primitive Data Types and Wrapper Classes Java has 8 primitive data types with specific characteristics:
Type
Size
Range
Default Value
Wrapper Class
byte
8 bits
-128 to 127
0
Byte
short
16 bits
-32,768 to 32,767
0
Short
int
32 bits
-2³¹ to 2³¹-1
0
Integer
long
64 bits
-2⁶³ to 2⁶³-1
0L
Long
float
32 bits
±1.4E-45 to ±3.4E38
0.0f
Float
double
64 bits
±4.9E-324 to ±1.7E308
0.0d
Double
char
16 bits
‘\u0000’ to ‘\uffff’
‘\u0000’
Character
boolean
1 bit
true/false
false
Boolean
Autoboxing and Unboxing Java automatically converts between primitives and their wrapper classes:
1 2 3 4 5 6 7 Integer a = 10 ; Double b = 3.14 ; int c = a; double d = b;
Integer Cache Behavior Java caches Integer values from -128 to 127 for performance:
1 2 3 4 5 6 7 Integer x = 127 ;Integer y = 127 ;System.out.println(x == y); Integer m = 128 ;Integer n = 128 ;System.out.println(m == n);
Best Practices
Use primitives for performance-sensitive code
Use wrapper classes with generics (e.g., List<Integer>
)
Prefer valueOf()
over constructors for wrapper objects
Handle null
carefully to avoid NullPointerExceptions
2. String Handling and Manipulation Strings are immutable objects with key methods:
String Creation 1 2 3 4 5 6 7 String s1 = "Java" ; String s2 = new String ("Java" ); String s3 = s1.intern(); System.out.println(s1 == s2); System.out.println(s1 == s3);
String Methods (Java 11+) 1 2 3 4 5 6 7 8 9 10 11 12 String text = " Java SE 11 " ;System.out.println(text.strip()); System.out.println(text.repeat(2 )); System.out.println(" " .isBlank()); System.out.println("Java\nSE\n11" .lines().count()); System.out.println(text.trim()); System.out.println(text.substring(2 , 6 )); System.out.println(String.join("-" , "A" , "B" , "C" ));
Text Blocks (Java 15+) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 String html = """ <html> <body> <p>Hello %s</p> </body> </html>""" .formatted("World" );String json = """ { "name": "John", "age": 30, "languages": ["Java", "Python"] }""" ;
String Building 1 2 3 4 5 6 StringBuilder sb = new StringBuilder ("Java" );sb.append(" SE" ).append(" 11" ); sb.insert(0 , "Oracle " ); sb.delete(0 , 7 ); System.out.println(sb.toString());
3. Proper Usage of Optional Class Optional
helps avoid NullPointerExceptions and makes null checks explicit:
Creation and Access 1 2 3 4 5 6 7 8 9 10 11 12 Optional<String> empty = Optional.empty(); Optional<String> name = Optional.of("Alice" ); Optional<String> maybeName = Optional.ofNullable(getName()); String value = maybeName.orElse("default" );String value2 = maybeName.orElseGet(() -> generateDefault());String value3 = maybeName.orElseThrow(IllegalStateException::new );maybeName.ifPresent(System.out::println);
Chaining Operations 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Optional<User> user = findUserById(123 ); String email = user .filter(u -> u.getAge() > 18 ) .flatMap(User::getEmail) .map(String::toUpperCase) .orElse("N/A" ); User u = findUserById(123 );String email2 = "N/A" ;if (u != null && u.getAge() > 18 ) { String e = u.getEmail(); if (e != null ) { email2 = e.toUpperCase(); } }
Best Practices
Avoid using Optional for:
Class fields
Method parameters
Collection elements
Never call get()
without checking isPresent()
Prefer orElseGet()
for expensive default operations
Use orElseThrow()
for required values
4. Date and Time API (java.time package) Modern date/time handling replaces outdated Date/Calendar classes:
Core Classes 1 2 3 4 5 6 7 8 9 10 11 LocalDate today = LocalDate.now();LocalDate birthday = LocalDate.of(1990 , Month.JANUARY, 1 );LocalTime now = LocalTime.now();LocalTime meetingTime = LocalTime.of(14 , 30 ); LocalDateTime current = LocalDateTime.now();ZonedDateTime zoned = ZonedDateTime.now(ZoneId.of("Asia/Taipei" ));
Periods and Durations 1 2 3 4 5 6 7 8 Period age = Period.between(birthday, today);System.out.printf("Age: %d years, %d months%n" , age.getYears(), age.getMonths()); Duration meetingLength = Duration.ofHours(1 ).plusMinutes(30 );LocalTime endTime = meetingTime.plus(meetingLength);
1 2 3 4 5 6 7 8 9 DateTimeFormatter formatter = DateTimeFormatter .ofPattern("dd/MM/yyyy HH:mm:ss" ) .withLocale(Locale.US); String formatted = current.format(formatter);LocalDateTime parsed = LocalDateTime.parse("20/06/2025 14:30:00" , formatter);
Time Zones 1 2 3 4 5 6 7 8 ZonedDateTime nyTime = ZonedDateTime.now(ZoneId.of("America/New_York" ));ZonedDateTime twTime = nyTime.withZoneSameInstant(ZoneId.of("Asia/Taipei" ));ZoneId.getAvailableZoneIds().stream() .filter(z -> z.contains("America" )) .forEach(System.out::println);
5. Control Flow Statements and Pattern Matching Modern Java features for more expressive control flow:
Enhanced Switch (Java 14+) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 int dayOfWeek = 3 ;String dayType = switch (dayOfWeek) { case 1 , 2 , 3 , 4 , 5 -> { System.out.println("Weekday" ); yield "Weekday" ; } case 6 , 7 -> "Weekend" ; default -> throw new IllegalArgumentException ("Invalid day: " + dayOfWeek); }; String dayName = switch (dayOfWeek) { case 1 -> "Monday" ; case 2 -> "Tuesday" ; default -> "Unknown" ; };
Pattern Matching (Java 16+) 1 2 3 4 5 6 7 8 9 10 11 12 13 Object obj = "Hello Java 11" ;if (obj instanceof String s && s.length() > 5 ) { System.out.println(s.toUpperCase()); } String formatted = switch (obj) { case Integer i -> String.format("int %d" , i); case String s -> String.format("String %s" , s); case null -> "null" ; default -> obj.toString(); };
Traditional Control Flow 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 List<String> languages = List.of("Java" , "Python" , "C++" ); for (String lang : languages) { System.out.println(lang); } try (InputStream is = new FileInputStream ("file.txt" ); BufferedReader br = new BufferedReader (new InputStreamReader (is))) { String line; while ((line = br.readLine()) != null ) { System.out.println(line); } } catch (IOException e) { e.printStackTrace(); }
Summary and Exam Tips 1. Identifying Correct Output of Code Snippets Expect questions that show code snippets and ask for the output. Focus on:
Key areas:
Autoboxing/unboxing behavior
1 2 3 4 Integer a = 1000 , b = 1000 ;System.out.println(a == b); Integer c = 100 , d = 100 ;System.out.println(c == d);
String manipulation results
1 2 3 String s = "Java" ;s.concat(" SE 11" ); System.out.println(s);
1 2 LocalDate date = LocalDate.of(2023 , 2 , 28 );System.out.println(date.plusMonths(1 ));
2. Spotting Potential NullPointerExceptions Identify code that could throw NPEs:
Common pitfalls:
Unboxing null wrapper objects
1 2 Optional<Integer> opt = Optional.empty(); int num = opt.orElse(null );
Method chaining on potentially null objects
1 String name = findUser().getName();
Accessing array elements before initialization
1 2 int [] numbers = null ;System.out.println(numbers[0 ]);
3. Recognizing Proper API Usage Identify correct vs incorrect API usage:
Key verification points:
1 2 3 4 5 6 7 8 Optional<String> name = Optional.ofNullable(getName()); name.ifPresent(System.out::println); if (name.isPresent()) { System.out.println(name.get()); }
Valid date/time operations
1 2 3 4 5 LocalDate date = LocalDate.parse("2023-01-01" );Date legacyDate = new Date ("2023-01-01" );
Appropriate string methods
1 2 3 4 5 " text " .strip();" text " .trim();
Analyze code for performance issues:
Critical areas:
1 2 3 4 5 Long sum = 0L ;for (long i = 0 ; i < Integer.MAX_VALUE; i++) { sum += i; }
String concatenation in loops
1 2 3 4 5 6 7 8 9 10 11 String result = "" ;for (int i = 0 ; i < 1000 ; i++) { result += i; } StringBuilder sb = new StringBuilder ();for (int i = 0 ; i < 1000 ; i++) { sb.append(i); }
1 2 3 4 5 String value = optional.orElse(createExpensiveDefault());String value = optional.orElseGet(() -> createExpensiveDefault());
Exam Strategy
Read questions carefully - note keywords like “correct”, “best”, “most efficient”
Eliminate obviously wrong answers first
For code output questions, trace execution step-by-step
Watch for trick questions with:
== vs equals() comparisons
Method chaining on null references
Mutable vs immutable objects
Time zone conversions
Practice with sample questions from:
Enthuware Java 11 Practice Tests
Oracle’s official sample questions
Whizlabs 1Z0-819 practice exams
2. String Handling and Manipulation Strings are immutable objects with key methods:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 String str = "Java 11" ;str.length(); str.substring(0 ,4 ); str.contains("11" ); str.repeat(2 ); String joined = String.join("-" , "A" , "B" , "C" ); String html = """ <html> <body> <p>Hello World</p> </body> </html>""" ;
3. Proper Usage of Optional Class Optional
helps avoid NullPointerExceptions:
1 2 3 4 5 6 7 8 9 10 11 12 13 Optional<String> optional = Optional.ofNullable(getName()); String name = optional.orElse("default" );String result = optional .filter(s -> s.length() > 3 ) .map(String::toUpperCase) .orElse("N/A" );
4. Date and Time API (java.time package) Modern date/time handling:
1 2 3 4 5 6 7 8 9 10 11 12 13 LocalDate today = LocalDate.now();LocalDate birthday = LocalDate.of(1990 , Month.JANUARY, 1 );Period age = Period.between(birthday, today);System.out.println(age.getYears()); LocalTime time = LocalTime.of(14 , 30 );LocalTime later = time.plusHours(2 ); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy" );String formatted = today.format(formatter);
5. Control Flow Statements and Pattern Matching Traditional control flow:
1 2 3 4 5 6 7 8 9 10 11 12 13 int day = 3 ;String dayType = switch (day) { case 1 , 2 , 3 , 4 , 5 -> "Weekday" ; case 6 , 7 -> "Weekend" ; default -> "Invalid" ; }; Object obj = "Hello" ;if (obj instanceof String s) { System.out.println(s.length()); }
Summary Key exam focus areas:
Understand autoboxing/unboxing behavior
Master String manipulation methods
Apply Optional correctly to avoid NPEs
Use java.time API for date/time operations
Utilize modern control flow features
For exam preparation, practice writing code that demonstrates these concepts and understand the performance implications of each approach.