Oracle Certified Professional Java SE 8 Programmer
1 Java Class Design
1-1 Implement encapsulation
1-2 Implement inheritance including visibility modifiers and composition
1-3 Implement polymorphism
1-4 Override hashCode, equals, and toString methods from Object class
1-5 Create and use singleton classes and immutable classes
1-6 Develop code that uses static keyword on initializers, variables, methods, and classes
2 Advanced Java Class Design
2-1 Develop code that uses abstract classes and methods
2-2 Develop code that uses the final keyword
2-3 Create inner classes including static inner class, local class, nested class, and anonymous inner class
2-4 Use enumerated types including methods, and constructors in an enum type
2-5 Develop code that declares, implements andor extends interfaces and use the atOverride annotation
2-6 Create and use Lambda expressions
3 Generics and Collections
3-1 Create and use a generic class
3-2 Create and use ArrayList, TreeSet, TreeMap, and ArrayDeque objects
3-3 Use java util Comparator and java lang Comparable interfaces
3-4 Collections Streams and Filters
3-5 Iterate using forEach methods of Streams and List
3-6 Describe Stream interface and Stream pipeline
3-7 Use method references with Streams
4 Lambda Built-in Functional Interfaces
4-1 Use the built-in interfaces included in the java util function package such as Predicate, Consumer, Function, and Supplier
4-2 Develop code that uses primitive versions of functional interfaces
4-3 Develop code that uses binary versions of functional interfaces
4-4 Develop code that uses the UnaryOperator interface
5 Java Stream API
5-1 Develop code to extract data from an object using map, peek, and flatMap methods
5-2 Search for data by using search methods of the Stream classes including findFirst, findAny, anyMatch, allMatch, noneMatch
5-3 Develop code that uses the Optional class
5-4 Develop code that uses Stream data methods and calculation methods
5-5 Sort a collection using Stream API
5-6 Save results to a collection using the collect method and grouppartition data using the Collectors class
5-7 Use flatMap() methods in the Stream API
6 Exceptions and Assertions
6-1 Use try-catch and throw statements
6-2 Use catch, multi-catch, and finally clauses
6-3 Use Autoclose resources with a try-with-resources statement
6-4 Create custom exceptions and Auto-closeable resources
6-5 Test invariants by using assertions
7 Use Java SE 8 DateTime API
7-1 Create and manage date-based and time-based events including a combination of date and time into a single object using LocalDate, LocalTime, LocalDateTime, Instant, Period, and Duration
7-2 Work with dates and times across time zones and manage changes resulting from daylight savings including Format date and times values
7-3 Define and create and manage date-based and time-based events using Instant, Period, Duration, and TemporalUnit
8 Java File IO (NIO 2)
8-1 Operate on file and directory paths using the Paths class
8-2 Check, delete, copy, and move files and directories using the Files class
8-3 Recursively access a directory tree using the DirectoryStream and FileVisitor interfaces
8-4 Find a file by using the PathMatcher interface, and use Java SE 8 IO improvements, including Files find(), Files walk(), and lines() methods
8-5 Observe the changes in a directory by using WatchService
9 Java Concurrency
9-1 Create worker threads using Runnable, Callable and use an ExecutorService to concurrently execute tasks
9-2 Identify potential threading problems among deadlock, starvation, livelock, and race conditions
9-3 Use synchronized keyword and java util concurrent atomic package to control the order of thread execution
9-4 Use java util concurrent collections and classes including CyclicBarrier and CopyOnWriteArrayList
9-5 Use parallel ForkJoin Framework
9-6 Use parallel Streams including reduction, decomposition, merging processes, pipelines, and performance
10 Building Database Applications with JDBC
10-1 Describe the interfaces that make up the core of the JDBC API including the Driver, Connection, Statement, and ResultSet interfaces and their relationship to provider implementations
10-2 Identify the components required to connect to a database using the DriverManager class including the JDBC URL
10-3 Submit queries and read results from the database including creating statements, returning result sets, iterating through the results, and properly closing result sets, statements, and connections
10-4 Use PreparedStatement to perform CRUD operations
10-5 Use CallableStatement to call stored procedures
10-6 Use Transactions including disabling auto-commit mode, committing and rolling back transactions
10-7 Use JDBC batch operations
10-8 Create and use RowSet objects using RowSetProvider and RowSetFactory
11 Localization
11-1 Read and set the locale by using the Locale object
11-2 Create and manage date- and time-based events by using Localization including formatting dates, numbers, and currency values
11-3 Work with dates, numbers, and currency values by using the NumberFormat and DateFormat classes and their derived classes such as DecimalFormat and SimpleDateFormat
11-4 Build a user interface for a localized application
11-5 Describe the advantages of localizing an application
Localization in Java

Localization in Java

Localization in Java refers to the process of adapting an application to meet the language, cultural, and other requirements of a specific region or locale. This webpage will explore key concepts related to localization, providing detailed explanations and examples to enhance your understanding.

Key Concepts

1. Locale

A Locale object represents a specific geographical, political, or cultural region. It is used to specify the user's language, country, and any special variant preferences.

Example

import java.util.Locale;

public class LocaleExample {
    public static void main(String[] args) {
        Locale locale = new Locale("fr", "FR");
        System.out.println("Locale: " + locale);
    }
}
    

2. ResourceBundle

A ResourceBundle is a class that allows you to manage locale-specific resources, such as text strings, images, and other data. It loads the appropriate resource bundle based on the specified locale.

Example

import java.util.Locale;
import java.util.ResourceBundle;

public class ResourceBundleExample {
    public static void main(String[] args) {
        Locale locale = new Locale("fr", "FR");
        ResourceBundle bundle = ResourceBundle.getBundle("Messages", locale);
        System.out.println(bundle.getString("greeting"));
    }
}
    

3. Properties Files

Properties files are used to store key-value pairs of localized strings. These files are named according to the locale they represent, such as Messages_fr_FR.properties for French (France).

Example

# Messages_fr_FR.properties
greeting=Bonjour
    

4. Formatting Numbers

The NumberFormat class is used to format numbers according to the conventions of a specific locale. This includes formatting for currency, percentages, and other numeric values.

Example

import java.text.NumberFormat;
import java.util.Locale;

public class NumberFormatExample {
    public static void main(String[] args) {
        Locale locale = new Locale("fr", "FR");
        NumberFormat numberFormat = NumberFormat.getCurrencyInstance(locale);
        System.out.println(numberFormat.format(1234.56));
    }
}
    

5. Formatting Dates

The DateFormat class is used to format dates according to the conventions of a specific locale. This includes formatting for dates, times, and date-time combinations.

Example

import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;

public class DateFormatExample {
    public static void main(String[] args) {
        Locale locale = new Locale("fr", "FR");
        DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.FULL, locale);
        System.out.println(dateFormat.format(new Date()));
    }
}
    

6. Formatting Messages

The MessageFormat class is used to format messages that include placeholders for dynamic data. This allows you to create localized messages with variable content.

Example

import java.text.MessageFormat;
import java.util.Locale;
import java.util.ResourceBundle;

public class MessageFormatExample {
    public static void main(String[] args) {
        Locale locale = new Locale("fr", "FR");
        ResourceBundle bundle = ResourceBundle.getBundle("Messages", locale);
        String pattern = bundle.getString("welcome");
        MessageFormat messageFormat = new MessageFormat(pattern, locale);
        System.out.println(messageFormat.format(new Object[]{"John"}));
    }
}
    

7. Locale-Sensitive Sorting

The Collator class is used to perform locale-sensitive string comparisons and sorting. This ensures that strings are sorted according to the conventions of the specified locale.

Example

import java.text.Collator;
import java.util.Arrays;
import java.util.Locale;

public class CollatorExample {
    public static void main(String[] args) {
        Locale locale = new Locale("fr", "FR");
        Collator collator = Collator.getInstance(locale);
        String[] words = {"été", "automne", "hiver", "printemps"};
        Arrays.sort(words, collator);
        System.out.println(Arrays.toString(words));
    }
}
    

8. Locale-Sensitive Case Conversion

The String class provides methods for locale-sensitive case conversion, such as toLowerCase(Locale) and toUpperCase(Locale). This ensures that case conversion is performed according to the conventions of the specified locale.

Example

import java.util.Locale;

public class CaseConversionExample {
    public static void main(String[] args) {
        Locale locale = new Locale("tr", "TR");
        String text = "istanbul";
        System.out.println(text.toUpperCase(locale));
    }
}
    

9. Locale-Sensitive Text Search

The BreakIterator class is used to perform locale-sensitive text search and segmentation. This allows you to find word boundaries, sentence boundaries, and other text segments according to the conventions of the specified locale.

Example

import java.text.BreakIterator;
import java.util.Locale;

public class BreakIteratorExample {
    public static void main(String[] args) {
        Locale locale = new Locale("en", "US");
        BreakIterator iterator = BreakIterator.getWordInstance(locale);
        String text = "Hello, world!";
        iterator.setText(text);
        int start = iterator.first();
        for (int end = iterator.next(); end != BreakIterator.DONE; start = end, end = iterator.next()) {
            System.out.println(text.substring(start, end));
        }
    }
}
    

10. Locale-Sensitive Number Parsing

The NumberFormat class is also used to parse numbers according to the conventions of a specific locale. This ensures that numbers are parsed correctly based on the locale's formatting rules.

Example

import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Locale;

public class NumberParsingExample {
    public static void main(String[] args) {
        Locale locale = new Locale("fr", "FR");
        NumberFormat numberFormat = NumberFormat.getNumberInstance(locale);
        try {
            Number number = numberFormat.parse("1-234,56");
            System.out.println(number.doubleValue());
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}
    

11. Locale-Sensitive Date Parsing

The DateFormat class is used to parse dates according to the conventions of a specific locale. This ensures that dates are parsed correctly based on the locale's formatting rules.

Example

import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.Locale;

public class DateParsingExample {
    public static void main(String[] args) {
        Locale locale = new Locale("fr", "FR");
        DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale);
        try {
            Date date = dateFormat.parse("12/10/2023");
            System.out.println(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}
    

Examples and Analogies

Locale: Language and Region

Think of a Locale as a language and region setting on a smartphone. It determines how the phone displays text, numbers, dates, and other information based on the user's preferences.

ResourceBundle: Language Pack

Consider a ResourceBundle as a language pack that contains all the text and resources needed for a specific language. The phone loads the appropriate language pack based on the user's locale.

Properties Files: Dictionary

Visualize properties files as dictionaries that contain translations for different languages. Each dictionary (properties file) is named according to the language it represents.

Formatting Numbers: Currency Converter

Think of formatting numbers as a currency converter that displays amounts in the correct format for a specific country. The converter adjusts the format based on the user's locale.

Formatting Dates: Calendar App

Consider formatting dates as a calendar app that displays dates in the correct format for a specific country. The app adjusts the format based on the user's locale.

Formatting Messages: Dynamic Text

Visualize formatting messages as dynamic text that includes placeholders for variable content. The text adjusts based on the user's locale and the dynamic data provided.

Locale-Sensitive Sorting: Alphabetical Order

Think of locale-sensitive sorting as arranging words in alphabetical order according to the rules of a specific language. The order changes based on the user's locale.

Locale-Sensitive Case Conversion: Text Case

Consider locale-sensitive case conversion as changing the case of text according to the rules of a specific language. The case conversion adjusts based on the user's locale.

Locale-Sensitive Text Search: Word Finder

Visualize locale-sensitive text search as a word finder that identifies word boundaries according to the rules of a specific language. The word finder adjusts based on the user's locale.

Locale-Sensitive Number Parsing: Number Reader

Think of locale-sensitive number parsing as a number reader that interprets numbers according to the rules of a specific language. The number reader adjusts based on the user's locale.

Locale-Sensitive Date Parsing: Date Reader

Consider locale-sensitive date parsing as a date reader that interprets dates according to the rules of a specific language. The date reader adjusts based on the user's locale.

Conclusion

Localization in Java allows you to create applications that are adaptable to different languages, regions, and cultures. By understanding and effectively using Locale, ResourceBundle, properties files, number and date formatting, message formatting, locale-sensitive sorting, case conversion, text search, number parsing, and date parsing, you can create robust and user-friendly applications. This knowledge is essential for passing the Oracle Certified Professional Java SE 8 Programmer certification.