Java Programming - Detailed Content
1. Java Basics
a. Syntax, Data Types, Operators
Java Syntax: Java is case-sensitive, uses classes, methods, and follows a structured format.
Data Types:
o Primitive: int, float, double, boolean, char, byte, short, long
o Non-primitive: Arrays, Strings, Classes, Interfaces
Operators:
o Arithmetic: +, -, *, /, %
o Relational: >, <, ==, !=, >=, <=
o Logical: &&, ||, !
o Assignment: =, +=, -=, *=, /=
🔹 Example Code:
public class Basics {
public static void main(String[] args) {
int a = 10, b = 20;
[Link]("Sum: " + (a + b));
[Link]("Is a > b? " + (a > b));
b. Control Structures
If-Else: For decision making
Switch: For multiple conditions
Loops: for, while, do-while
🔹 Example Code:
public class ControlFlow {
public static void main(String[] args) {
int number = 5;
if (number > 0) {
[Link]("Positive number");
} else {
[Link]("Negative number");
}
3. Exception Handling
a. Try-Catch Blocks
Handle runtime errors without crashing the program.
🔹 Example Code:
public class ExceptionExample {
public static void main(String[] args) {
try {
int data = 50 / 0; // ArithmeticException
} catch (ArithmeticException e) {
[Link]("Cannot divide by zero!");
b. Custom Exceptions
Creating user-defined exceptions.
🔹 Example Code:
class InvalidAgeException extends Exception {
public InvalidAgeException(String message) {
super(message);
public class CustomExceptionTest {
static void validate(int age) throws InvalidAgeException {
if (age < 18)
throw new InvalidAgeException("Not eligible for voting");
public static void main(String[] args) {
try {
validate(16);
} catch (InvalidAgeException e) {
[Link]([Link]());
}
[Link]("Hello, Java File Handling!");
[Link]();
6. Java APIs & Libraries
Collections Framework: ArrayList, HashMap
Java Utility APIs: Scanner, Math, StringBuilder
External Libraries: Apache Commons, Gson, Jackson
🔹 Example Code (ArrayList usage):
import [Link];
public class APIExample {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<>();
[Link]("Java");
[Link]("Python");
for (String lang : list) {
[Link](lang);
7. Hands-on Projects
Library Management System
Bank Account Management System
Simple E-commerce Cart Simulation
8. Technical Interview Preparation
Practice coding questions: Arrays, Strings, Recursion, OOP Design Patterns.
Mock tests for companies like TCS, Infosys, Wipro.
🔹 Example Code (Reversing a String):
public class ReverseString {
public static void main(String[] args) {
String input = "Java";
String reversed = new StringBuilder(input).reverse().toString();