Java Programming Fundamentals

Module: B3.3-R5: Web Technologies

Chapter: Introduction To Java And OOPs Concepts

🔹 Introduction

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.

1️⃣ Structure of a Java Program

A basic Java program consists of the following elements:

  • Package declaration (optional)
  • Import statements (optional)
  • Class definition
  • Main method – entry point of execution
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, Java!");
    }
}

main() method syntax:

  • public – accessible by JVM
  • static – no object needed to invoke
  • void – returns nothing
  • String[] args – command-line arguments
2️⃣ Java Syntax Rules
  • Java is case-sensitive: Mainmain
  • Class names start with uppercase letters
  • Method/variable names start with lowercase
  • Statements end with semicolons ;
  • Blocks are enclosed in curly braces { }
  • Whitespace is ignored except in string literals
3️⃣ Java Variables & Data Types

Variables store data in memory. In Java, all variables must be declared with a type.

✔ Primitive Data Types
TypeSizeExample
byte1 bytebyte age = 25;
short2 bytesshort s = 1000;
int4 bytesint num = 12345;
long8 byteslong population = 123456789L;
float4 bytesfloat rate = 12.5f;
double8 bytesdouble pi = 3.14159;
char2 byteschar grade = 'A';
boolean1 bitboolean flag = true;
✔ Non-Primitive Data Types
  • String
  • Arrays
  • Classes
  • Interfaces
  • Objects
4️⃣ Java Operators
✔ Arithmetic Operators

+ , - , * , / , %

✔ Relational Operators

== , != , > , < , >= , <=

✔ Logical Operators

&& , || , !

✔ Assignment Operators

=, +=, -=, *=, /=

✔ Increment & Decrement

++variable, variable++, --variable

5️⃣ Input & Output in Java
✔ Printing Output
System.out.println("Hello");   // Prints with newline
System.out.print("Hi");       // Prints without newline
✔ Taking Input using Scanner
import java.util.Scanner;

Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
String name = sc.nextLine();
double value = sc.nextDouble();
6️⃣ Control Statements
✔ Conditional Statements
  • if
  • if-else
  • nested if
  • switch-case
✔ Looping Statements
  • for loop
  • while loop
  • do-while loop
  • enhanced for loop
✔ Jump Statements
  • break
  • continue
  • return
7️⃣ Arrays in Java (Basic)

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};
📝 Conclusion

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.