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

Java Basics - Class Notes

The document provides an overview of Java, a high-level, object-oriented programming language, highlighting its key features such as platform independence and automatic memory management. It covers essential topics including Java setup, basic syntax, control flow statements, object-oriented programming concepts, exception handling, and the Java Collections Framework. Additionally, it introduces Java 8 features like lambda expressions and the Streams API.

Uploaded by

ciket64575
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)
29 views6 pages

Java Basics - Class Notes

The document provides an overview of Java, a high-level, object-oriented programming language, highlighting its key features such as platform independence and automatic memory management. It covers essential topics including Java setup, basic syntax, control flow statements, object-oriented programming concepts, exception handling, and the Java Collections Framework. Additionally, it introduces Java 8 features like lambda expressions and the Streams API.

Uploaded by

ciket64575
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
You are on page 1/ 6

Java Basics - Class Notes

1. Introduction to Java

• What is Java?
o Java is a high-level, object-oriented programming language developed by Sun
Microsystems (now owned by Oracle).
o It is platform-independent, meaning Java programs can run on any device or
operating system that has a Java Virtual Machine (JVM).
• Key Features of Java:
o Object-Oriented: Focuses on objects, classes, inheritance, and polymorphism.
o Platform Independent: "Write Once, Run Anywhere" (WORA) due to JVM.
o Multithreading: Allows multiple tasks to run concurrently.
o Automatic Memory Management: Uses garbage collection to manage memory.
o Rich API: Extensive set of libraries for networking, GUI, utilities, etc.

2. Setting Up Java

• Install JDK (Java Development Kit):


o Download from Oracle’s website or use an open-source version like OpenJDK.
o Ensure JAVA_HOME is set up and the bin directory is in your system’s PATH.
• IDE for Java:
o Popular IDEs include Eclipse, IntelliJ IDEA, and NetBeans for writing and
debugging Java code.

3. Basic Java Syntax

• Hello World Program:

java
Copy
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}

o public class HelloWorld: Defines a class named HelloWorld.


o public static void main(String[] args): The main method where the program
begins execution.
o System.out.println(): Outputs text to the console.

4. Variables and Data Types

• Primitive Data Types:


o int: Integer values (e.g., 10, -5)
o double: Decimal values (e.g., 3.14, -2.5)
o char: Single characters (e.g., 'a', '1')
o boolean: True or false values.
o long, short, byte, float (other numeric types).
• Declaring Variables:

java
Copy
int age = 25;
double price = 10.99;
boolean isJavaFun = true;

5. Control Flow Statements

• If-Else Statement:

java
Copy
if (age >= 18) {
System.out.println("Adult");
} else {
System.out.println("Minor");
}

• Switch Statement:

java
Copy
int day = 3;
switch(day) {
case 1: System.out.println("Monday"); break;
case 2: System.out.println("Tuesday"); break;
case 3: System.out.println("Wednesday"); break;
default: System.out.println("Invalid day");
}

• Loops:
o For Loop:

java
Copy
for (int i = 0; i < 5; i++) {
System.out.println(i);
}

o While Loop:

java
Copy
int i = 0;
while (i < 5) {
System.out.println(i);
i++;
}

6. Functions (Methods)

• Defining a Method:

java
Copy
public static int addNumbers(int a, int b) {
return a + b;
}

• Calling a Method:

java
Copy
int result = addNumbers(5, 3);
System.out.println(result); // Output: 8

7. Object-Oriented Programming (OOP) Concepts

• Classes and Objects:


o Class: Blueprint for creating objects. Contains fields (variables) and methods
(functions).
o Object: Instance of a class.

java
Copy
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:
o Allows a class to inherit fields and methods from another class.

java
Copy
class Animal {
void makeSound() {
System.out.println("Some sound");
}
}

class Dog extends Animal {


void makeSound() {
System.out.println("Bark");
}
}

public class Main {


public static void main(String[] args) {
Dog dog = new Dog();
dog.makeSound(); // Output: Bark
}
}

• Polymorphism:
o The ability for different classes to be treated as instances of the same class
through inheritance. Methods can have the same name but behave differently.
• Encapsulation:
o Bundles the data (variables) and methods into a single unit (class) and restricts
access to the inner workings of the class through access modifiers (public,
private).
• Abstraction:
o Hides the complex implementation details and shows only the necessary features
of the object.

8. Exception Handling

• Try-Catch Block:
o Used to handle exceptions (errors during program execution).

java
Copy
try {
int result = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Error: " + e.getMessage());
}

9. Collections Framework

• List, Set, Map:


o ArrayList: A dynamic array that allows duplicate elements.
o HashSet: A collection that does not allow duplicates.
o HashMap: A collection of key-value pairs.

Example of ArrayList:
java
Copy
ArrayList<String> list = new ArrayList<>();
list.add("Java");
list.add("Python");

10. Java API and Libraries

• Common Libraries:
o java.util: Collections, date/time utilities, etc.
o java.io: File I/O operations.
o java.net: Networking utilities.

11. Java 8 Features

• Lambda Expressions:
o Allows writing anonymous methods in a more concise way.

java
Copy
(a, b) -> a + b;

• Streams API:
o Facilitates functional-style operations on collections of elements.

java
Copy
List<Integer> numbers = Arrays.asList(1, 2, 3, 4);
numbers.stream().filter(n -> n % 2 == 0).forEach(System.out::println);

Key Points to Remember:

• Java is case-sensitive, meaning Main and main are different.


• The main method is the entry point for every Java application.
• Always use System.out.println() to print messages to the console.

This is a high-level overview. If you want more detailed examples or explanations on any
specific topic, just let me know!

You said:

make it in pdf format


ChatGPT said:

ChatGPT
I can't directly generate a PDF for you, but I can guide you through how to do it yourself!

Here's what you can do:

1. Copy the text from the notes I provided.


2. Open a word processor (like Microsoft Word, Google Docs, or any other text editor).
3. Paste the text into the document.
4. After formatting it the way you want (you can add headings, bullet points, etc.), go to
File > Save As or Download and select the PDF format.

This will give you a PDF version of your Java class notes!

Let me know if you'd like more help with the process!

You might also like