Unit 1: Introduction to Java
Basics of Java
- Java is a high-level, object-oriented programming language.
- Java programs consist of classes and methods.
Hello, World!
- The classic “Hello, World!” program in Java:
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }
Unit 2: Data Types and Operators
Primitive Data Types
- int: Represents integers (e.g., -42, 0, 100).
- double: Represents floating-point numbers (e.g., 3.14, 2.718).
- char: Represents a single character (e.g., ‘A’, ‘$’).
- boolean: Represents true or false.
Variables and Assignment
- Declare and assign a variable:
int age = 25; double pi = 3.1415; char grade = 'A'; boolean isStudent = true;
Arithmetic Operators
- Basic arithmetic operators:
- Addition:
+ - Subtraction:
- - Multiplication:
* - Division:
/ - Modulo:
%
- Addition:
Comparison Operators
- Comparison operators return boolean values:
- Equal to:
== - Not equal to:
!= - Greater than:
> - Less than:
< - Greater than or equal to:
>= - Less than or equal to:
<=
- Equal to:
Logical Operators
- Logical operators for combining conditions:
- AND:
&& - OR:
|| - NOT:
!
- AND:
Conditional Statements
ifstatement:if (condition) { // Code to execute if the condition is true }elsestatement:if (condition) { // Code to execute if the condition is true } else { // Code to execute if the condition is false }