0% found this document useful (0 votes)
5 views6 pages

Java Quick Revision Notes

This document provides a quick revision guide for Java programming, covering key concepts such as the main method, variables, data types, conditionals, loops, methods, classes, inheritance, polymorphism, encapsulation, exception handling, collections, generics, streams, lambda expressions, file I/O, multithreading, and packages. It emphasizes best practices like following OOP principles and using appropriate data structures. The notes serve as a concise reference for Java developers to refresh their knowledge on essential topics.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

Java Quick Revision Notes

This document provides a quick revision guide for Java programming, covering key concepts such as the main method, variables, data types, conditionals, loops, methods, classes, inheritance, polymorphism, encapsulation, exception handling, collections, generics, streams, lambda expressions, file I/O, multithreading, and packages. It emphasizes best practices like following OOP principles and using appropriate data structures. The notes serve as a concise reference for Java developers to refresh their knowledge on essential topics.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

​⚡ Java Quick Revision Notes​

​1. Hello World​


​public class Main {​
​public static void main(String[] args) {​
​[Link]("Hello, World!");​
​}​
​}​

​👉 Entry point is always​​


main​​method.​

​2. Variables & Data Types​


i​nt x = 10;​
​double pi = 3.14;​
​boolean isActive = true;​
​char grade = 'A';​
​String name = "Aman";​

​👉 Primitive vs. Non-Primitive (String, Arrays, Objects).​

​3. Conditionals​
​if (x > 10) {​
​[Link]("Big");​
​} else if (x == 10) {​
​[Link]("Equal");​
​} else {​
​[Link]("Small");​
​}​

​4. Loops​
​for (int i = 0; i < 5; i++) [Link](i);​

​while (x > 0) { x--; }​

​for (String s : new String[]{"a","b"}) {​


​[Link](s);​
​}​

​5. Methods​
​public static int add(int a, int b) {​
​return a + b;​
​}​

​👉 Methods belong to a class.​

​6. Classes & Objects​


​class Person {​
​String name;​
​int age;​

​void greet() {​
​[Link]("Hello, " + name);​
​}​
​}​

​ erson p = new Person();​


P
​[Link] = "Aman";​
​[Link]();​

​7. Constructors​
​class Person {​
​String name;​
​Person(String name) {​
​[Link] = name;​
​}​
}​ ​
​Person p = new Person("Aman");​

​👉 Special method to initialize objects.​

​8. Inheritance​
​class Animal {​
​void sound() { [Link]("Some sound"); }​
​}​

​class Dog extends Animal {​


​void sound() { [Link]("Bark"); }​
​}​

​👉​​
extends​​= inheritance,​​
super​​= parent call.​

​9. Polymorphism​
​ nimal a = new Dog();​
A
​[Link](); // "Bark"​

​👉 Parent reference can point to child object.​

​10. Abstract Classes & Interfaces​


​abstract class Shape {​
​abstract void draw();​
​}​

​interface Drawable {​
​void draw();​
​}​

​class Circle implements Drawable {​


​public void draw() { [Link]("Circle"); }​
​}​

​👉​​
abstract​​= partially defined,​​
interface​​= contract.​

​11. Encapsulation​
​class Bank {​
​private int balance = 1000;​
​public int getBalance() { return balance; }​
​public void deposit(int amount) { balance += amount; }​
​}​

​👉 Use​​
private​​+ getters/setters.​

​12. Exception Handling​


​try {​
​int result = 10 / 0;​
​} catch (ArithmeticException e) {​
​[Link]("Error: " + [Link]());​
​} finally {​
​[Link]("Always runs");​
​}​

​👉 Use​​
throw​​for custom exceptions.​

​13. Collections​
​import [Link].*;​

​ ist<String> list = new ArrayList<>();​


L
​[Link]("Aman");​

​ ap<String, Integer> map = new HashMap<>();​


M
​[Link]("age", 21);​
​[Link]([Link]("age"));​

​👉​​
List​ Set​
​,​​ Map​​are common interfaces.​
​,​​

​14. Generics​
​class Box<T> {​
​private T value;​
​public void set(T value) { [Link] = value; }​
​public T get() { return value; }​
​}​

​ ox<String> b = new Box<>();​


B
​[Link]("Hello");​

​15. Streams (Java 8+)​


​ ist<Integer> nums = [Link](1,2,3,4);​
L
​[Link]()​
​.filter(n -> n % 2 == 0)​
​.map(n -> n * n)​
​.forEach([Link]::println);​

​👉 Functional-style operations on collections.​

​16. Lambda Expressions​


​ unnable r = () -> [Link]("Running...");​
R
​new Thread(r).start();​

​17. File I/O​


​import [Link].*;​
​ tring data = [Link]([Link]("[Link]"));​
S
​[Link]([Link]("[Link]"), "Hello Java");​

​18. Multithreading​
​class MyThread extends Thread {​
​public void run() { [Link]("Thread running"); }​
​}​

​new MyThread().start();​

​👉 Or use​​
Runnable​
​.​

​19. Packages​
​ ackage myapp;​
p
​import [Link];​

​👉 Organize code into namespaces.​

​20. Important Best Practices​


​●​ ​Follow​​OOP principles​​: Encapsulation, Inheritance,​​Polymorphism, Abstraction.​

interfaces​​when multiple implementations possible.​


​●​ ​Use​​

List​
​●​ ​Prefer​​ ​/​​
Map​​over arrays for flexibility.​

​●​ ​Handle exceptions properly (​​


try-catch-finally​
​).​

​●​ ​Use streams & lambdas for concise code.​

You might also like