NBKRIST JavaHub – Java Fundamentals

Java Fundamentals – Super Easy Guide

This page gives a smooth, beginner-friendly introduction to Core Java. Each concept is explained in simple words with short examples and outputs.

1. Program Structure in Java

Every Java program starts with a class and a main() method. The JVM begins execution from main().

Java follows a clean structure: Class → Methods → Statements.

class Hello { public static void main(String[] args) { System.out.println("Welcome to Java!"); } }
Welcome to Java!

2. Writing Simple Java Programs

Java uses System.out.println() to print output. Every statement ends with a semicolon.

Simple programs help understand the flow of execution.

class Simple { public static void main(String[] args) { System.out.println("Java is easy!"); } }
Java is easy!

3. Elements / Tokens in Java

Tokens are the smallest units in a Java program. They include keywords, identifiers, literals, operators, and symbols.

Java programs are built entirely using these basic elements.

int x = 10; // identifier + operator + literal final int MAX = 100; // keyword + identifier

4. Java Statements

A Java statement tells the computer what to do. Types: expression, declaration, loop, and decision statements.

Each statement ends with a semicolon except blocks.

int a = 5; // declaration if(a > 2) { // decision statement System.out.println("Yes"); }
Yes

5. Command Line Arguments

Arguments passed while running the program are stored in args[].

They help send values without changing the code.

class Demo { public static void main(String[] args) { System.out.println("Argument: " + args[0]); } }
Argument: NBKRIST

6. User Input in Java

Java uses Scanner class for reading input.

It supports reading integers, strings, floats, etc.

import java.util.*; class InputDemo { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int age = sc.nextInt(); System.out.println(age); } }
(User enters: 21) → 21

7. Escape Sequences

Escape sequences allow special formatting inside quotes.

Common ones: \n (new line), \t (tab).

System.out.println("Hello\nJava");
Hello
Java

8. Comments in Java

Comments explain code without affecting execution.

Types: single-line (//) and multi-line (/* */).

// This is a comment /* Multi-line comment */

9. Programming Style

Good programming style improves readability and reduces bugs.

Follow naming conventions, proper indentation, and meaningful names.

int studentAge; // Good name int a; // Avoid

Practice Questions – Click to Reveal Answers

1️⃣ What is the starting point of a Java program?
The main() method.
2️⃣ What are Java tokens?
Smallest elements like keywords, identifiers, operators, literals.
3️⃣ What is a Java statement?
An instruction for the JVM (declaration, expression, loop, decision).
4️⃣ What is a command line argument?
Values passed in args[] while running the program.
5️⃣ How do you take user input?
Using the Scanner class.
6️⃣ Give an example of escape sequence.
\n → new line, \t → tab
7️⃣ Why use comments?
To explain code without affecting execution.
8️⃣ Name a good programming practice.
Use meaningful variable names and proper indentation.
9️⃣ Write a simple Java print statement.
System.out.println("Hello");
🔟 What is the purpose of main method arguments?
To pass external input to the program.

Quick Summary