0% found this document useful (0 votes)
15 views3 pages

Java Basics - Simple Notes

Java is a platform-independent, object-oriented programming language that is easy to use. Key concepts include setting up Java with the JDK, basic syntax, variables, control flow, methods, object-oriented programming, error handling, collections, and features from Java 8 like lambda expressions and streams. The main method serves as the entry point for Java programs, and System.out.println() is used for output.

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 DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Java Basics - Simple Notes

Java is a platform-independent, object-oriented programming language that is easy to use. Key concepts include setting up Java with the JDK, basic syntax, variables, control flow, methods, object-oriented programming, error handling, collections, and features from Java 8 like lambda expressions and streams. The main method serves as the entry point for Java programs, and System.out.println() is used for output.

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 DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Sure!

Here's a simplified version of the Java class notes:

Java Basics - Simple Notes


1. What is Java?
 Java is a programming language that is easy to use and works on any computer
(platform-independent).
 Java is object-oriented, meaning it focuses on objects and actions (methods).

2. Setting Up Java
 Install Java: Download the JDK (Java Development Kit).
 Use an IDE (like Eclipse or IntelliJ) to write your code.

3. Basic Syntax
 Hello World Example:
 public class HelloWorld {
 public static void main(String[] args) {
 System.out.println("Hello, World!");
 }
 }
 This prints "Hello, World!" on the screen.

4. Variables and Data Types


 Data types in Java:
o int: Whole numbers (e.g., 25)
o double: Decimal numbers (e.g., 3.14)
o char: Single character (e.g., 'a')
o boolean: True or false (e.g., true)
 Example of variables:
 int age = 25;
 double price = 10.99;
 boolean isJavaFun = true;
5. Control Flow (Conditions and Loops)
 If-Else:
Checks if something is true or false.
 if (age >= 18) {
 System.out.println("Adult");
 } else {
 System.out.println("Minor");
 }
 For Loop:
Repeats actions multiple times.
 for (int i = 0; i < 5; i++) {
 System.out.println(i);
 }

6. Methods (Functions)
 Method Definition: A method does something and can return a result.
 public static int addNumbers(int a, int b) {
 return a + b;
 }
 Calling the method:
 int result = addNumbers(5, 3);
 System.out.println(result); // Output: 8

7. Object-Oriented Programming (OOP)


 Class and Object:
A class is a blueprint for creating objects (things that have properties and actions).
 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:
One class can inherit properties and actions from another class.

8. Error Handling (Exceptions)


 If something goes wrong, use try-catch to handle the error.
 try {
 int result = 10 / 0;
 } catch (ArithmeticException e) {
 System.out.println("Error: " + e.getMessage());
 }

9. Collections
 ArrayList stores a list of items.
 ArrayList<String> list = new ArrayList<>();
 list.add("Java");
 list.add("Python");

10. Java 8 Features


 Lambda Expressions:
A shortcut for writing small methods.
 (a, b) -> a + b;
 Streams:
Helps you work with collections of data in a simpler way.
 List<Integer> numbers = Arrays.asList(1, 2, 3, 4);
 numbers.stream().filter(n -> n % 2 == 0).forEach(System.out::println);

Key Points:

 Java is case-sensitive.
 The main method is where the program starts.
 System.out.println() is used to print things to the screen.

This version is simpler and easier to understand. Copy this into a text editor and save it as a PDF,
and you'll have your Java notes! Let me know if you need more help!

You might also like