Java – Collections Framework
The Java Collections Framework provides reusable data structures like ArrayList, HashMap, and HashSet.Example: ArrayList list = new ArrayList();list.add("Apple");list.add("Banana");System.out.println(list);
The Java Collections Framework provides reusable data structures like ArrayList, HashMap, and HashSet.Example: ArrayList list = new ArrayList();list.add("Apple");list.add("Banana");System.out.println(list);
Generics enable type-safe programming by specifying data types for classes and methods.Example: ArrayList numbers = new ArrayList();numbers.add(10);System.out.println(numbers);
The Streams API introduced in Java 8 enables functional-style operations on collections.Example: List names = Arrays.asList("Alice", "Bob", "Charlie");names.stream().filter(name -> name.startsWith("A")) .forEach(System.out::println);
Introduced in Java 8, Lambda Expressions enable functional programming with concise syntax.Example: List numbers = Arrays.asList(1, 2, 3, 4, 5);numbers.forEach(n -> System.out.println(n));
Java supports various types of operators:Example: int a = 10, b = 5;System.out.println(a + b); // Addition
Comments are used to annotate code for clarity. Single-line comments use “//”, and multi-line comments use “/*…*/”.Example: // This is a single-line comment /* This is a multi-line comment */
Java can take user input using the Scanner class.Example: Scanner scanner = new Scanner(System.in);System.out.print("Enter your name: ");String name = scanner.nextLine();System.out.println("Hello, " + name);
Java supports various types of variables, including int, double, String, and boolean. These are used to store different types of data.Example: int num = 10;double price = 19.99;String name = "Java";
Java has both primitive data types (like int, double) and reference data types (like objects and arrays).Example: int age = 25;double height = 5.9;String name = "John";
Type casting is converting one data type to another.Example: int x = 10;double y = (double) x;System.out.println(y);