1. Variables


int x = 10; // integer variable
double y = 20.5; // double variable
boolean isAdmin = true; // boolean variable
String name = "John Doe"; // string variable

2. Data Types


byte, short, int, long, float, double, boolean, char, String

3. Operators


+, -, \*, /, %, ==, !=, >, <, >=, <=, &&, ||, !

4. Control Structures


if (condition) { code }
if (condition) { code } else { code }
switch (expression) { case value: code; break; }
for (init; condition; increment) { code }
while (condition) { code }
do { code } while (condition);

5. Loops


for (int i = 0; i < 10; i++) { code }
while (i < 10) { code; i++; }
do { code; i++; } while (i < 10);

6. Arrays


int[] scores = {90, 80, 70, 60};
String[] names = {"John", "Jane", "Bob"};

7. Methods


public static void main(String[] args) { code }
public int add(int x, int y) { return x + y; }

8. Classes


public class Person { private String name; public Person(String name) { this.name = name; } }

9. Objects


Person person = new Person("John Doe");

10. Inheritance


public class Animal { public void sound() { System.out.println("The animal makes a sound."); } }
public class Dog extends Animal { public void sound() { System.out.println("The dog barks."); } }

11. Polymorphism


public class Animal { public void sound() { System.out.println("The animal makes a sound."); } }
public class Dog extends Animal { public void sound() { System.out.println("The dog barks."); } }
Animal animal = new Dog();
animal.sound(); // Output: The dog barks.

12. Encapsulation


public class Person { private String name; public Person(String name) { this.name = name; } public String getName() { return name; } }

13. Abstraction


public abstract class Animal { public abstract void sound(); }
public class Dog extends Animal { public void sound() { System.out.println("The dog barks."); } }

14. Interface


public interface Printable { public void print(); }
public class Document implements Printable { public void print() { System.out.println("Printing document..."); } }

15. Exception Handling


try { code } catch (Exception e) { code }

16. File Input/Output


File file = new File("example.txt");
Scanner scanner = new Scanner(file);
PrintWriter writer = new PrintWriter(file);

17. Networking


Socket socket = new Socket("example.com", 80);
ServerSocket serverSocket = new ServerSocket(80);

18. Multithreading


Thread thread = new Thread(new Runnable() { public void run() { code } });
thread.start();

19. Collections


List<String> list = new ArrayList<>();
Set<String> set = new HashSet<>();
Map<String, String> map = new HashMap<>();

20. Generics


public class Container<T> { private T value; public Container(T value) { this.value = value; } }

21. Lambda Expressions


List<String> names = Arrays.asList("John", "Jane", "Bob");
names.forEach(name -> System.out.println(name));

22. Streams


List<String> filtered = names.stream().filter(name -> name.startsWith("J")).collect(Collectors.toList());

23. Optional


Optional<String> optionalName = Optional.ofNullable(name);
optionalName.ifPresent(n -> System.out.println(n));

24. Enum


public enum Day { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }

25. Switch Expressions


String dayType = switch (day) { case SUNDAY, SATURDAY -> "Weekend"; default -> "Weekday"; };

26. Var Keyword


var number = 10; // inferred as int
var name = "John"; // inferred as String

27. Static Keyword


public static int count = 0; // static variable
public static void display() { System.out.println("Static method"); } // static method

28. Final Keyword


final int MAX_VALUE = 100; // constant
final class Constants { } // final class

29. This Keyword


public class Person { private String name; public Person(String name) { this.name = name; } }

30. Super Keyword


public class Dog extends Animal { public Dog() { super(); } }

31. Static Block


static { System.out.println("Static block executed"); }

32. Instance Block


{ System.out.println("Instance block executed"); }

33. Inner Classes


public class Outer { class Inner { } }

34. Anonymous Classes


Runnable runnable = new Runnable() { public void run() { System.out.println("Anonymous class"); } };

35. Static Nested Classes


public static class StaticNested { }

36. Method Overloading


public int add(int a, int b) { return a + b; }
public double add(double a, double b) { return a + b; }

37. Method Overriding


public class Animal { public void sound() { System.out.println("Animal sound"); } }
public class Cat extends Animal { public void sound() { System.out.println("Meow"); } }

38. Constructor Overloading


public class Person { public Person() { } public Person(String name) { } }

39. Default Methods in Interfaces


public interface MyInterface { default void display() { System.out.println("Default method"); } }

40. Static Methods in Interfaces


public interface MyInterface { static void staticMethod() { System.out.println("Static method"); } }

41. Java Annotations


@Override
public void method() { }

42. Custom Annotations


@interface MyAnnotation { String value(); }

43. Reflection


Class<?> clazz = Class.forName("Person");
Method[] methods = clazz.getDeclaredMethods();

44. Java 8 Features


Stream<String> stream = Stream.of("a", "b", "c");

45. Java 9 Features


List<String> list = List.of("a", "b", "c");

46. Java 10 Features


var list = List.of("a", "b", "c"); // Local variable type inference

47. Java 11 Features


String multiline = """
This is a
multiline string
""";

48. Java 12 Features


switch (day) {
case MONDAY, FRIDAY -> System.out.println("Working day");
case SATURDAY, SUNDAY -> System.out.println("Weekend");
}

49. Java 13 Features


String text = """
This is a text block
that spans multiple lines
""";

50. Java 14 Features


public record Person(String name, int age) { }

51. Java 15 Features


sealed interface Shape permits Circle, Square { }

52. Java 16 Features


public class Main {
public static void main(String... args) { }
}

53. Java 17 Features


var list = List.of("Java", "Python", "C++");

54. Java 18 Features


String text = """
This is a text block
with a new feature
""";

55. Java 19 Features


record Point(int x, int y) { }

56. Java 20 Features


Pattern pattern = Pattern.compile("a*b");

57. Java Collections Framework


List<String> list = new ArrayList<>();
Set<String> set = new HashSet<>();
Map<String, String> map = new HashMap<>();

58. ArrayList


ArrayList<String> list = new ArrayList<>();
list.add("Java");
list.add("Python");

59. HashMap


HashMap<String, Integer> map = new HashMap<>();
map.put("Java", 1);
map.put("Python", 2);

60. HashSet


HashSet<String> set = new HashSet<>();
set.add("Java");
set.add("Python");

61. LinkedList


LinkedList<String> linkedList = new LinkedList<>();
linkedList.add("Java");
linkedList.add("Python");

62. Stack


Stack<Integer> stack = new Stack<>();
stack.push(1);
stack.push(2);

63. Queue


Queue<String> queue = new LinkedList<>();
queue.add("Java");
queue.add("Python");

64. PriorityQueue


PriorityQueue<Integer> pq = new PriorityQueue<>();
pq.add(5);
pq.add(1);

65. TreeSet


TreeSet<String> treeSet = new TreeSet<>();
treeSet.add("Java");
treeSet.add("Python");

66. TreeMap


TreeMap<String, Integer> treeMap = new TreeMap<>();
treeMap.put("Java", 1);
treeMap.put("Python", 2);

67. Collections Utility Class


Collections.sort(list);
Collections.reverse(list);

68. Streams API


List<String> filtered = list.stream().filter(s -> s.startsWith("J")).collect(Collectors.toList());

69. Optional Class


Optional<String> optional = Optional.ofNullable(name);
optional.ifPresent(System.out::println);

70. Java Date and Time API


import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
LocalDate date = LocalDate.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
String formattedDate = date.format(formatter);

71. LocalDate


LocalDate today = LocalDate.now();
LocalDate tomorrow = today.plusDays(1);

72. LocalTime


LocalTime time = LocalTime.now();
LocalTime later = time.plusHours(1);

73. LocalDateTime


LocalDateTime dateTime = LocalDateTime.now();

74. ZonedDateTime


ZonedDateTime zonedDateTime = ZonedDateTime.now();

75. Period


Period period = Period.between(LocalDate.now(), LocalDate.of(2023, 12, 31));

76. Duration


Duration duration = Duration.between(LocalTime.now(), LocalTime.now().plusHours(1));

77. Java Streams


List<String> names = Arrays.asList("John", "Jane", "Jack");
names.stream().filter(name -> name.startsWith("J")).forEach(System.out::println);

78. Collectors


List<String> collected = names.stream().collect(Collectors.toList());

79. Map Function


List<String> upperCaseNames = names.stream().map(String::toUpperCase).collect(Collectors.toList());

80. Filter Function


List<String> filteredNames = names.stream().filter(name -> name.length() > 3).collect(Collectors.toList());

81. Reduce Function


Optional<String> concatenated = names.stream().reduce((a, b) -> a + b);

82. FlatMap


List<List<String>> listOfLists = Arrays.asList(Arrays.asList("A", "B"), Arrays.asList("C", "D"));
List<String> flatList = listOfLists.stream().flatMap(Collection::stream).collect(Collectors.toList());

83. Java 8 Optional


Optional<String> optionalName = Optional.ofNullable(name);
optionalName.ifPresent(n -> System.out.println(n));

84. Optional with Default Value


String defaultName = optionalName.orElse("Default Name");

85. Optional with Function


String upperName = optionalName.map(String::toUpperCase).orElse("Default Name");

86. Java 8 Default Methods


public interface MyInterface { default void defaultMethod() { System.out.println("Default method"); } }

87. Java 8 Static Methods


public interface MyInterface { static void staticMethod() { System.out.println("Static method"); } }

88. Java 8 Streams


List<String> names = Arrays.asList("John", "Jane", "Jack");
names.stream().filter(name -> name.startsWith("J")).forEach(System.out:: println);

89. Java 8 Collectors


Map<String, Long> nameCount = names.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));

90. Java 8 Map


Map<String, Integer> nameLength = names.stream().collect(Collectors.toMap(Function.identity(), String::length));

91. Java 8 Filter


List<String> filteredNames = names.stream().filter(name -> name.length() > 3).collect(Collectors.toList());

92. Java 8 Reduce


Optional<String> concatenated = names.stream().reduce((a, b) -> a + b);

93. Java 8 FlatMap


List<List<String>> listOfLists = Arrays.asList(Arrays.asList("A", "B"), Arrays.asList("C", "D"));
List<String> flatList = listOfLists.stream().flatMap(Collection::stream).collect(Collectors.toList());

94. Java 8 Optional


Optional<String> optionalName = Optional.ofNullable(name);
optionalName.ifPresent(n -> System.out.println(n));

95. Java 8 Optional with Default Value


String defaultName = optionalName.orElse("Default Name");

96. Java 8 Optional with Function


String upperName = optionalName.map(String::toUpperCase).orElse("Default Name");

97. Java 8 Default Methods


public interface MyInterface { default void defaultMethod() { System.out.println("Default method"); } }

98. Java 8 Static Methods


public interface MyInterface { static void staticMethod() { System.out.println("Static method"); } }

99. Java 8 Streams


List<String> names = Arrays.asList("John", "Jane", "Jack");
names.stream().filter(name -> name.startsWith("J")).forEach(System.out::println);

100. Java 8 Collectors


Map<String, Long> nameCount = names.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));