Description/Overview: A lookup 'sheet' of common use Java methods, boilerplate code, and more. For more advanced data structures guidance/solutions and clean coding advice, see the Supplemental Resources section.
- Syntax and Data Types
- Mathematical and Logical Operators
- Control Flow/Decision Structures
- Arrays
- Strings
- Methods
- Object-Oriented Programming (OOP) Principles
- Exception Handling
- Java Collections Framework (JCF)
- Generics
- File Input/Output (I/O)
- Multithreading
- Lambda Expressions and Functional Interfaces
- Stream API
- Time API
- Networking
- Reflection
- Annotations
- Java Database Connectivity (JDBC)
- Supplemental Resources
4. Arrays
5. Strings
6. Methods
- Method declaration:
public int addVals(int a, int b) { return a + b; }
- Method overload (if added to a class with the above method):
public int addVals(int a, int b, int c) { return a + b + c; }
10. Generics
- Generic class:
public class ClassName<T> { }
- Generic method:
public <T> void methodName(T parameter) { }
- Bounded type parameter (with generic method):
public <T extends Number> void methodName(T parameter) { }
- Wildcard:
public void methodName(List<?> list) { }
12. Multithreading
14. Stream API
15. Time API
Retrieving present values...
- Present date:
LocalDate date = LocalDate.now();
- Present time:
LocalTime time = LocalTime.now();
- Present date and time:
LocalDateTime dateTime = LocalDateTime.now();
- Present day (of week):
DayOfWeek dayOfWeek = date.getDayOfWeek();
Retrieving more specific values...
- A specific date:
LocalDate date = LocalDate.of(2024, 10, 6);
- Period between dates:
Period period = Period.between(date1, date2);
- Duration between times:
Duration duration = Duration.between(time1, time2);
Performing mathematical operations...
- Adding days to a date:
LocalDate future = date.plusDays(5);
- Adding years to a date:
LocalDate future = date.plusYears(4);
- Subtracting months from a date:
LocalDate past = date.minusMonths(2);
Parsing, formatting, and conditional logic...
- Parsing a date (from String data):
LocalDate date = LocalDate.parse("2020-02-09");
- Formatting a date (from String data):
String formatted = date.format(DateTimeFormatter.ISO_DATE);
- Evaluate if a year is a leap year:
boolean isLeapYear = date.isLeapYear();
16. Networking
17. Reflection
18. Annotations
Java Clean Coding Guide
Java Data Structure Leetcode Interview Questions