Module: B3.3-R5: Web Technologies
Chapter: Introduction To Java And OOPs Concepts
Java Programming Fundamentals cover the core concepts needed to begin writing Java applications. This includes understanding the structure of a Java program, syntax rules, variables, data types, operators, input/output, control structures, and the program execution flow. Mastering these basics is essential before moving to OOP concepts such as classes, inheritance, and polymorphism.
A basic Java program consists of the following elements:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}
main() method syntax:
public – accessible by JVMstatic – no object needed to invokevoid – returns nothingString[] args – command-line argumentsMain ≠ main;{ }Variables store data in memory. In Java, all variables must be declared with a type.
| Type | Size | Example |
|---|---|---|
| byte | 1 byte | byte age = 25; |
| short | 2 bytes | short s = 1000; |
| int | 4 bytes | int num = 12345; |
| long | 8 bytes | long population = 123456789L; |
| float | 4 bytes | float rate = 12.5f; |
| double | 8 bytes | double pi = 3.14159; |
| char | 2 bytes | char grade = 'A'; |
| boolean | 1 bit | boolean flag = true; |
+ , - , * , / , %
== , != , > , < , >= , <=
&& , || , !
=, +=, -=, *=, /=
++variable, variable++, --variable
System.out.println("Hello"); // Prints with newline
System.out.print("Hi"); // Prints without newline
import java.util.Scanner; Scanner sc = new Scanner(System.in); int num = sc.nextInt(); String name = sc.nextLine(); double value = sc.nextDouble();
Arrays store multiple values of the same type in a single variable.
int[] arr = new int[5]; arr[0] = 10; arr[1] = 20;
Or directly:
int[] marks = {90, 85, 88, 76, 95};
Java fundamentals create the base required for learning advanced concepts like OOP, file handling, multithreading, exception handling, collections, and GUI frameworks. Understanding syntax, variables, operators, control flow, and input/output ensures a strong foundation for building Java applications of any complexity.