Java Basics
• Unit I – Java Basics and Programming
Fundamentals
• Presented by: Govind Singh Panwar
Objectives
• Learn Java syntax and structure
• Understand data types and variable
declarations
• Use operators and expressions in Java
Java Syntax Overview
• Case-sensitive language
• Code blocks use curly braces {}
• Every statement ends with a semicolon ;
• Class and method structure
Basic Program Structure
public class HelloWorld {
public static void main(String[] args) {
[Link]("Hello, world!");
}
}
• Entry point: main() method
• Print output using [Link]()
Data Types in Java
• Primitive: int, float, double, char, boolean,
byte, short, long
• Non-primitive: Strings, Arrays, Classes,
Interfaces
• Example: int age = 25;
Variables in Java
• Declaring and initializing variables
• Naming conventions
• Scope: local, instance, static
Type Conversion
• Implicit type casting (widening)
• Explicit type casting (narrowing)
• int i = 10;
• double d = i; // widening
• int x = (int) d; // narrowing
Operators in Java
• Arithmetic: +, -, *, /, %
• Relational: ==, !=, <, >, <=, >=
• Logical: &&, ||, !
• Assignment: =, +=, -=, *=
Expressions
• Expressions combine variables, operators, and
values
• int a = 10, b = 20;
• int sum = a + b;
• Evaluation order matters (precedence and
associativity)
Summary
• Java has strict syntax and strong typing
• Understanding data types, variables, and
operators is foundational
• Next: Control Structures in Java
Quick Questions
• What are primitive and non-primitive data
types?
• What is the difference between widening and
narrowing conversions?
• Write a sample Java expression using
arithmetic operators