New Microsoft Word Document (2)
New Microsoft Word Document (2)
2. Setting Up Java
• Install JDK: Download from Oracle or OpenJDK.
• IDEs: Eclipse, IntelliJ IDEA, NetBeans.
6. Methods
• Defining a Method:
• public static int addNumbers(int a, int b) {
• return a + b;
• }
• Calling a Method:
• int result = addNumbers(5, 3);
• System.out.println(result); // Output: 8
7. OOP Concepts
• Classes and Objects:
• class Car {
• String model;
• int year;
•
• public void drive() {
• System.out.println("Driving the " + model);
• }
• }
•
• public class Main {
• public static void main(String[] args) {
• Car myCar = new Car();
• myCar.model = "Toyota";
• myCar.year = 2020;
• myCar.drive();
• }
• }
• Inheritance:
• class Animal {
• void makeSound() {
• System.out.println("Some sound");
• }
• }
•
• class Dog extends Animal {
• void makeSound() {
• System.out.println("Bark");
• }
• }
8. Exception Handling
• Try-Catch:
• try {
• int result = 10 / 0;
• } catch (ArithmeticException e) {
• System.out.println("Error: " + e.getMessage());
• }
9. Collections
• ArrayList:
• ArrayList<String> list = new ArrayList<>();
• list.add("Java");
• list.add("Python");
Key Points:
• Java is case-sensitive.
• The main method is the entry point for every Java application.
• System.out.println() is used to print messages to the console.
Once you copy this into your preferred text editor or word processor, you can save it as a PDF!
Let me know if you need further help with that.