-->

Java Fundamentals Tutorial – Step 1 | Learn Java Fundamentals step by step

Java Fundamentals Tutorial



    Introduction

    Java Fundamentals are the foundation of Java programming. Before learning Object-Oriented Programming, Collections, Multithreading, or advanced Java development, you should understand how Java works, how a Java program is structured, how to write and execute code, and how the Java Virtual Machine runs your program.

    In this Step 1 Java Programming Tutorial, you will learn the essential fundamentals of Java from the beginning. No previous Java programming experience is required.




    What You Will Learn

    After completing this lesson, you will understand:

    • What Java is
    • History of Java
    • Why Java is popular
    • Features of Java
    • How Java works
    • JDK, JRE, and JVM
    • Java source code and bytecode
    • Installing Java
    • Java development environments
    • Structure of a Java program
    • The main() method
    • Comments in Java
    • Case sensitivity
    • Java naming conventions
    • How to compile Java programs
    • How to run Java programs
    • Your first Java program
    • Common beginner mistakes
    • Java practice exercises



    What Is Java?

    Java is a high-level, general-purpose programming language designed to create applications that can run on different platforms.

    Java follows the principle:

    Write Once, Run Anywhere

    Java source code is compiled into bytecode, which can be executed by a Java Virtual Machine (JVM) available for the target platform.

    Java is commonly used for:

    • Backend development
    • Enterprise applications
    • Web applications
    • Desktop software
    • Android-related development
    • Cloud applications
    • Distributed systems
    • Financial applications
    • Server-side applications



    History of Java

    Java was developed at Sun Microsystems in the 1990s. The project was initially known as Oak and was later renamed Java.

    Java became popular because developers could compile Java programs into bytecode and run that bytecode on different systems using a JVM.

    Today, Java continues to be widely used for professional software development.




    Why Should You Learn Java?

    Java is an excellent language for learning programming concepts because it provides a structured programming environment and strongly supports Object-Oriented Programming.

    Major advantages of Java

    1. Platform Independent

    Java bytecode can run on different operating systems through compatible JVM implementations.

    2. Object-Oriented

    Java supports important OOP concepts such as:

    • Classes
    • Objects
    • Inheritance
    • Polymorphism
    • Encapsulation
    • Abstraction

    3. Secure

    Java was designed with several features intended to support secure application execution and controlled runtime behavior.

    4. Robust

    Java provides strong type checking, exception handling, and automatic memory management.

    5. Multithreaded

    Java provides built-in support for creating and managing concurrent tasks.

    6. Large Ecosystem

    Java has a large collection of libraries, frameworks, development tools, and community resources.




    Features of Java

    Some important features of Java include:

    • Simple and structured syntax
    • Object-oriented programming
    • Platform independence
    • Portability
    • Security
    • Robustness
    • Automatic memory management
    • Multithreading
    • Exception handling
    • Rich standard library
    • High performance through runtime optimization
    • Networking support



    How Does Java Work?

    A basic Java program follows this process:

    Java Source Code

    Java Compiler

    Java Bytecode

    JVM

    Operating System / Hardware

    For example, suppose you create:

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

    The source file is normally saved as:

    Main.java

    The Java compiler converts the source code into bytecode.

    The resulting file is commonly:

    Main.class

    The JVM then loads and executes the bytecode.




    JDK, JRE, and JVM

    Understanding JDK, JRE, and JVM is one of the most important Java fundamentals.

    JVM – Java Virtual Machine

    The JVM is the runtime environment that executes Java bytecode.

    Its major responsibilities include:

    Loading classes
    Verifying bytecode
    Executing bytecode
    Managing runtime memory
    Supporting garbage collection

    JRE – Java Runtime Environment

    The JRE traditionally refers to the components required to run Java applications, including the JVM and runtime libraries.

    For modern Java distributions, a separate standalone JRE is generally not distributed in the same way as older Java releases.

    JDK – Java Development Kit

    The JDK provides the tools required to develop Java applications.

    It includes tools such as:

    • Java compiler
    • Java launcher
    • Documentation tools
    • Debugging and development utilities
    • Runtime components

    For Java development, you normally install a JDK.

    Simple Relationship

    JDK
     ├── Development Tools
     └── Runtime Components
          └── JVM



    Installing Java

    To start Java programming, install a suitable JDK distribution for your operating system.

    Popular development environments include:

    • Windows
    • macOS
    • Linux

    After installing the JDK, open your terminal or command prompt and check the Java version.

    java -version

    You can also check the Java compiler:

    javac -version

    If Java is installed correctly, these commands should display the installed Java version.




    Java Development Tools

    You can write Java programs using a simple text editor or a Java IDE.

    Popular options include:

    • IntelliJ IDEA
    • Eclipse
    • Apache NetBeans
    • Visual Studio Code

    For beginners, an IDE can make development easier because it provides features such as:

    • Code completion
    • Syntax highlighting
    • Error detection
    • Debugging
    • Project management
    • Refactoring tools

    However, learning basic command-line compilation is also useful because it helps you understand what happens behind the IDE.




    Your First Java Program

    Let's create your first Java program.

    public class Main {
    
        public static void main(String[] args) {
    
            System.out.println("Hello, World!");
    
        }
    }

    Output

    Hello, World!

    Congratulations! You have written your first Java program.




    Understanding the Java Program

    Let's break the program into individual parts.

    Class Declaration

    public class Main

    This defines a class named Main.

    If the class is declared public, the source file name normally needs to match the class name:

    Main.java

    Main Method

    public static void main(String[] args)

    The main() method is the conventional entry point used by the Java launcher to start a standalone Java application.

    Let's examine it:

    public

    The method is accessible to the Java launcher.

    static

    The method belongs to the class rather than requiring an object to be created first.

    void

    The method does not return a value.

    main

    This is the method name recognized as the application entry point.

    String[] args

    This parameter can receive command-line arguments.




    Printing Output in Java

    Java provides several commonly used output methods.

    System.out.println()

    Prints text and moves to a new line.

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

    Output:

    Hello
    Java

    System.out.print()

    Prints text without automatically moving to the next line.

    System.out.print("Hello ");
    System.out.print("Java");

    Output:

    Hello Java

    System.out.printf()

    Provides formatted output.

    String name = "Jitu";
    int age = 20;
    
    System.out.printf("Name: %s, Age: %d%n", name, age);




    Comments in Java

    Comments are notes written inside source code. They are ignored by the compiler.

    Java supports three common comment forms.

    Single-Line Comment

    // This is a comment
    System.out.println("Java");

    Multi-Line Comment

    /*
       This is a
       multi-line comment.
    */
    System.out.println("Java");

    Documentation Comment

    /**
     * Displays a welcome message.
     */
    public static void welcome() {
        System.out.println("Welcome!");
    }

    Documentation comments can be used with Java's documentation tools.




    Java Is Case-Sensitive

    Java is a case-sensitive language.

    For example:

    int number = 10;

    is different from:

    int Number = 10;

    Similarly:

    System.out.println();

    must not be written as:

    system.out.println();

    Correct capitalization is essential when writing Java code.




    Java Statements

    A statement is an instruction that performs an operation.

    For example:

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

    Most Java statements end with a semicolon:

    ;

    Example:

    int age = 20;
    System.out.println(age);

    Forgetting the semicolon can cause a compilation error.




    Java Blocks

    A block is a group of statements surrounded by curly braces:

    {
        ...
    }

    Example:

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

    The class body and method body are examples of blocks.




    Java Identifiers

    Identifiers are names used for programming elements such as:

    • Classes
    • Methods
    • Variables
    • Interfaces

    Examples:

    Student
    calculateTotal
    firstName
    totalMarks

    Basic identifier rules

    An identifier:

    • Can contain letters
    • Can contain digits
    • Can contain _
    • Can contain $
    • Cannot normally begin with a digit
    • Cannot contain spaces
    • Cannot be a Java keyword

    For example:

    int studentAge = 20;

    is valid.

    But:

    int student age = 20;

    is invalid because an identifier cannot contain a space.




    Java Keywords

    Java reserves certain words for specific language purposes.

    Examples include:

    class
    public
    private
    static
    void
    int
    if
    else
    for
    while
    return
    new
    extends
    implements
    final
    try
    catch

    You cannot normally use a reserved keyword as a variable, class, or method name.

    For example:

    int class = 10;

    is invalid.




    Java Naming Conventions

    Following naming conventions makes Java programs easier to read.

    Class Names

    Use PascalCase:

    Student
    BankAccount
    EmployeeManager

    Method Names

    Use camelCase:

    calculateTotal()
    displayMessage()
    getStudentName()

    Variable Names

    Use camelCase:

    studentName
    totalMarks
    accountBalance

    Constants

    Constants are commonly written using uppercase letters with underscores:

    MAX_SIZE
    DEFAULT_TIMEOUT
    PI_VALUE

    Naming conventions do not generally affect whether the compiler accepts your program, but they are important for readable and maintainable code.




    Compiling a Java Program

    Suppose your source code is saved as:

    Main.java

    Open your terminal in the directory containing the file and run:

    javac Main.java

    If compilation succeeds, a class file will normally be generated.

    Main.class




    Running a Java Program

    After compiling the program, run it using:

    java Main

    Do not normally include .class when using the Java launcher.

    Example:

    javac Main.java
    java Main

    Output:

    Hello, World!




    Java Program Structure

    A basic Java program can look like this:

    public class Main {
    
        // Method
        public static void main(String[] args) {
    
            // Statement
            System.out.println("Learning Java");
    
        }
    }

    The basic structure contains:

    1. Class declaration
    2. Class body
    3. Main method
    4. Statements
    5. Comments where appropriate

    As you progress through the course, this simple structure will become much more powerful.




    Java Escape Sequences

    Escape sequences are special character combinations used inside strings.

    New Line

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

    Output:

    Hello
    Java

    Tab

    System.out.println("Name:\tJitu");

    Double Quote

    System.out.println("He said \"Hello\"");

    Common escape sequences include:

    Escape                Meaning
    \n               New line
    \t                   Tab
    \"             Double quote
    \'             Single quote
    \\            Backslash




    A Simple Java Example

    Let's combine some fundamentals.

    public class Main {
    
        public static void main(String[] args) {
    
            System.out.println("===== Java Fundamentals =====");
            System.out.println("Name: Jitu Hasan");
            System.out.println("Course: Java Programming");
            System.out.println("Level: Beginner");
    
        }
    }

    Output:

    ===== Java Fundamentals =====
    Name: Jitu Hasan
    Course: Java Programming
    Level: Beginner

    This example demonstrates:

    • Class
    • Main method
    • Statements
    • Strings
    • Output
    • Comments and formatting concepts



    Common Beginner Mistakes

    When starting Java, beginners commonly encounter the following problems.

    Mistake 1: Wrong Class Name

    If you have:

    public class Main

    the file should normally be:

    Main.java

    Mistake 2: Missing Semicolon

    Incorrect:

    System.out.println("Hello")

    Correct:

    System.out.println("Hello");

    Mistake 3: Incorrect Capitalization

    Incorrect:

    system.out.println("Hello");

    Correct:

    System.out.println("Hello");

    Mistake 4: Incorrect Compilation Command

    Compile:

    javac Main.java

    Run:

    java Main

    Mistake 5: Forgetting Curly Braces

    Incorrect program structure can cause syntax errors.

    Always make sure that opening and closing braces match:

    {
        // code
    }




    Practice Exercises

    Practice is essential for learning Java.

    Exercise 1

    Create a Java program that prints:

    Welcome to Java Programming

    Exercise 2

    Print your:

    • Name
    • Country
    • Learning goal

    Example:

    Name: Your Name
    Country: Bangladesh
    Goal: Become a Java Developer

    Exercise 3

    Print the following using separate statements:

    Java
    Programming
    Tutorial
    2026

    Exercise 4

    Create a program that prints a simple introduction card.

    Example:

    ========================
         STUDENT PROFILE
    ========================
    Name: Rahim
    Course: Java Programming
    Level: Beginner
    ========================

    Exercise 5

    Use escape sequences to produce:

    Name:    Rahim
    Course:  Java
    Level:   Beginner




    Mini Project – Java Welcome Program

    Let's create a small beginner project.

    public class Main {
    
        public static void main(String[] args) {
    
            System.out.println("==============================");
            System.out.println("     JAVA PROGRAMMING COURSE");
            System.out.println("==============================");
            System.out.println("Welcome to Java!");
            System.out.println("Start learning from the basics.");
            System.out.println("Practice every day.");
            System.out.println("==============================");
    
        }
    }

    Expected Output

    ==============================
         JAVA PROGRAMMING COURSE
    ==============================
    Welcome to Java!
    Start learning from the basics.
    Practice every day.
    ==============================

    This simple project helps you practice Java class structure, the main() method, strings, output statements, and formatting.




    Quick Revision

    Let's review the most important concepts from Step 1.

    TopicKey Point
    Java                  General-purpose programming language
    JDK                  Development kit used to develop Java applications
    JVM                 Executes Java bytecode
    JRE                 Runtime environment concept used with Java applications
    Source Code                 Human-readable Java program
    Bytecode                Compiled representation executed by the JVM
    Class                Blueprint containing Java members
    main()                Conventional entry point for a Java application
    println()                Prints output followed by a line break
    Comments                Notes ignored by the compiler
    Identifier                Name of a programming element
    Keyword                Reserved word in Java
    Compilation               Converting source code into bytecode
    Execution               Running the compiled program


    What You Should Know Before Step 2

    Before moving to the next lesson, make sure you can:

    • Explain what Java is.
    • Explain the basic Java execution process.
    • Understand the difference between JDK and JVM.
    • Explain the traditional role of JRE.
    • Install and verify a JDK.
    • Create a basic Java program.
    • Understand the main() method.
    • Print output using System.out.println().
    • Write comments.
    • Explain Java's case sensitivity.
    • Identify basic Java keywords.
    • Follow common naming conventions.
    • Compile a Java source file.
    • Run a Java program.
    • Solve the practice exercises.



    Conclusion

    Java Fundamentals are the first and most important step in your Java programming journey. Understanding the Java environment, JDK, JVM, source code, bytecode, program structure, classes, the main() method, statements, comments, identifiers, and compilation will make the upcoming lessons much easier.

    Don't rush through the fundamentals. Write each example yourself, change the code, intentionally make small mistakes, and observe the results. Programming becomes easier when you actively practice rather than simply reading code.

    In Step 2, we will learn Java Variables and Data Types, including primitive data types, variable declaration, initialization, type conversion, constants, and practical coding examples.

    Next Lesson → Step 2: Java Variables and Data Types


    Frequently Asked Questions (FAQ)

    What are Java Fundamentals?
    Java Fundamentals are the basic concepts required to start programming with Java, including Java syntax, program structure, JDK, JVM, variables, data types, operators, statements, methods and basic programming concepts.
    What is Java?
    Java is a high-level, general-purpose programming language widely used for developing applications, backend systems, enterprise software and many other types of software.
    What is the difference between JDK and JVM?
    The JDK provides tools and components required for Java development, while the JVM is the runtime environment responsible for executing Java bytecode.
    What is the main method in Java?
    The main method is the conventional entry point used by the Java launcher to start a standalone Java application.
    How do I compile a Java program?
    Save the Java source file with a .java extension and use the javac command, such as javac Main.java, to compile it.
    How do I run a Java program?
    After compiling the program, use the Java launcher with the class name, such as java Main, to run the application.
    Is Java case-sensitive?
    Yes. Java is case-sensitive, so identifiers such as name and Name are treated as different identifiers.

    0/Post a Comment/Comments

    Thank You For Visit My Website.
    I Will Contact As Soon As Possible.