Tutorial by Examples

Binary Literals: The integral types (byte, short, int, and long) can also be expressed using the binary number system. To specify a binary literal, add the prefix 0b or 0B to the number. Strings in switch Statements: You can use a String object in the expression of a switch statement The try-wit...
// An 8-bit 'byte' value: byte aByte = (byte)0b00100001; // A 16-bit 'short' value: short aShort = (short)0b1010000101000101; // Some 32-bit 'int' values: int anInt1 = 0b10100001010001011010000101000101; int anInt2 = 0b101; int anInt3 = 0B101; // The B can be upper or lower case. // A ...
The example reads the first line from a file. It uses an instance of BufferedReader to read data from the file. BufferedReader is a resource that must be closed after the program is finished with it: static String readFirstLineFromFile(String path) throws IOException { try (BufferedReader br = n...
The following example shows other ways you can use the underscore in numeric literals: long creditCardNumber = 1234_5678_9012_3456L; long socialSecurityNumber = 999_99_9999L; float pi = 3.14_15F; long hexBytes = 0xFF_EC_DE_5E; long hexWords = 0xCAFE_BABE; long maxLong = 0x7fff_ffff_ffff_ffffL;...
You can use Map<String, List<String>> myMap = new HashMap<>(); instead of Map<String, List<String>> myMap = new HashMap<String, List<String>>(); However, you can't use List<String> list = new ArrayList<>(); list.add("A"); ...
public String getTypeOfDayWithSwitchStatement(String dayOfWeekArg) { String typeOfDay; switch (dayOfWeekArg) { case "Monday": typeOfDay = "Start of work week"; break; case "Tuesday": case "Wednes...

Page 1 of 1