Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Java Platform Fundamentals and Hello World Application

Tech 1

Getting Started with Java

Java technology consists of both a programming language and a runtime platform. The language is high-level, object-oriented, and designed for simplicity and portability. The platform provides the necessary environment to execute Java applications through the Java Virtual Machine (JVM) and associated libraries.

The Java compiler (javac) translates source code files (.java) into bytecode (.class), which is platform-independent. This bytecode runs on any system with a compatible JVM, enabling "write once, run anywhere" capability.

The Java platform includes:

  • Java Virtual Machine: Executes compiled bytecode
  • Java Application Programming Interface (API): Extensive library of pre-built componants organized in packages

Creating Your First Java Application

Prerequisites

Before writing your program, ensure you have:

  • Java Development Kit (JDK)
  • Text editor or Integrated Development Environment (IDE)

Writing Source Code

Create a file named HelloWorldApp.java with the following content:

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

Key points when typing:

  • Java is case-sensitive (HelloWorldApphelloworldapp)
  • Class name must match filename exactly
  • Every application requires a main method as entry point

Compilation Process

Compile the source file using:

javac HelloWorldApp.java

This generates HelloWorldApp.class containing bytecode instructions for the JVM.

Execution

Run the compiled program with:

java HelloWorldApp

Expected output:

Hello World!

Understanding the Hello World Program Structure

The example contains three fundamental elements:

Comments

Java supports three comment styles ignored by the compiler:

  • /* text */: Multi-line comments
  • // text: Single-line comments
  • /** documentation */: Documentation comments processed by javadoc tool

Class Definition

Every Java application begins with a class definition:

class ClassName {
    // class body
}

The class acts as a blueprint containing all program functionality.

Main Method

Applications must include a main method with signature:

public static void main(String[] args)

This serves as the execution starting point where the JVM begins program flow.

Java Language Basics

Variables

Java defines several variable types:

  • Instance variables: Non-static fields unique to each object instance
  • Class variables: Static fields shared across all instances
  • Local variables: Temporary values within method scope
  • Parameters: Variables receiving argumant values

Variable naming follows these conventions:

  • Begin with letter, underscore (_), or dollar sign ($)
  • Subsequent characters can include digits
  • Case-sensitive identifiers
  • Use camelCase for multi-word names

Primitive Data Types

Eight built-in data types provide basic value storage:

Type Size Range
byte 8-bit -128 to 127
short 16-bit -32,768 to 32,767
int 32-bit -2³¹ to 2³¹-1
long 64-bit -2⁶³ to 2⁶³-1
float 32-bit IEEE 754 floating-point
double 64-bit IEEE 754 double-precision
boolean 1-bit true or false
char 16-bit '\u0000' to '\uffff' (Unicode characters)

Fields receive default values when uninitialized:

  • Numeric types: 0
  • boolean: false
  • char: '\u0000'
  • Object references: null

Arrays

Arays store fixed-size sequences of elements with same type:

Declaration:

int[] numbers;

Initialization:

numbers = new int[10];  // Creates array with 10 elements

Alternative syntax:

int[] values = {1, 2, 3, 4, 5};

Access elements via zero-based indexing:

System.out.println(values[0]);  // Prints first element

Multi-dimensional arrays:

String[][] matrix = {
    {"A", "B"},
    {"C", "D"}
};
System.out.println(matrix[0][1]);  // Prints "B"

Array utility operations available through java.util.Arrays:

  • Copying: copyOfRange()
  • Sorting: sort(), parallelSort()
  • Searching: binarySearch()
  • Comparison: equals()
  • Conversion: toString()

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.