Java Programming Session Overview

Sep 12, 2024

Java Programming Session Notes

Agenda

  • Introduction to Java
  • Basics of Object-Oriented Programming (OOP)
  • Installing Eclipse and Java
  • Setting up the environment

What is Java?

  • Java is an Object-Oriented Programming (OOP) Language.
  • OOP languages can be categorized into three types:
    • Structured Programming Languages: C, Python.
    • Object-Based Programming Languages: VB, VB Script, Python.
    • Object-Oriented Programming Languages: C++, Java, C, Python.

Object-Oriented Programming (OOP) Concepts

  • OOP languages support specific concepts:
    1. Class
    2. Object
    3. Polymorphism
    4. Inheritance
    5. Abstraction
    6. Encapsulation
  • Java supports all these OOP concepts, making it a purely object-oriented programming language.

Features of Java

  1. Platform Independence:
    • Java can run on any operating system without modification.
    • Write once, run anywhere.
  2. Case Sensitivity:
    • Java differentiates between uppercase and lowercase letters.

Important Components of Java

  • JDK (Java Development Kit): Required for developing Java applications. It includes the compiler and tools.
  • JRE (Java Runtime Environment): Required to run Java applications. It includes the JVM (Java Virtual Machine).
  • JVM (Java Virtual Machine): Converts Java code into bytecode, allowing it to be executed on various platforms.

Installation of Java and Eclipse

  1. Downloading JDK:
    • Visit Oracle's website to download JDK.
    • Sign up to create an Oracle account.
    • Download the appropriate installer for your OS (Windows/Mac).
    • Follow the prompts to install the software.
  2. Setting Java Path:
    • Locate the installation directory (typically in C:\Program Files\Java\jdkX.X.X\bin).
    • Add this path in the system environment variables.
  3. Installing Eclipse IDE:
    • Visit Eclipse's official website.
    • Download the latest version of the Eclipse IDE.
    • Follow the installation instructions.

Creating a Java Project in Eclipse

Steps to create a project:

  1. Open Eclipse and create a new Java project.
  2. Create a new package within the src directory.
  3. Create a new class inside the package:
    • The class must include a main method to execute the code.

Example of a Basic Java Program

public class FirstJavaProgram {
    public static void main(String[] args) {
        System.out.println("Welcome to Java");
        // More code can be added here
    }
}
  • Print statements:
    • Use System.out.print() or System.out.println() for output.
    • Strings must be enclosed in double quotes.

Naming Conventions and Comments

  • Class Naming Conventions:
    • Class names should start with uppercase letters.
    • Cannot start with numbers or contain special characters (except underscores).
  • Comments:
    • Single-line comments: // comment
    • Multi-line comments: /* comment */

Conclusion

  • Practice setting up the environment and creating a simple Java program.
  • Familiarize yourself with the syntax and structure of Java programming.
  • Prepare for more advanced concepts in future sessions.