Loading...

Java Fundamentals

Understanding the building blocks and runtime environment.

Java Refresher

A Java program is essentially a collection of objects talking to other objects by invoking each other's methods. Every object is of a certain type, defined by a class or an interface.

Tip: Strict adherence to naming conventions makes your code readable and maintainable.

Did You Know?

J James Gosling
A Arthur
V Van Hoff
A Andy Bechtolsheim
S Stanford
U University
N Network

Core Components & Rules

Java Runtime Environment (JRE)

The JRE is the minimum requirement to run any Java application.

  • Consists of JVM, core classes, and libraries.
  • Can be downloaded separately as a subset of JDK.
  • Available for Windows, Mac, Linux, and Mobile devices.
  • Platform Dependent: You need a specific JRE for your specific OS (e.g., JRE for Linux).

Java Virtual Machine (JVM)

The "heart" of the Java platform, responsible for "Write Once, Run Anywhere".

  • Included within the JRE.
  • Converts platform-independent Bytecode (.class) into machine-specific code.
  • Handles Memory Management and Garbage Collection automatically.
  • Runs inside a virtual environment, isolating code from the hardware.

Source File Declaration

  • Only one public class allowed per file.
  • Filename must match the public class name (e.g., public class DogDog.java).
  • Package statement (if any) must be the first line.
  • Import statements go between package and class declaration.

Legal Identifiers

  • Must start with a Letter, Currency ($), or Underscore (_).
  • Cannot start with a number.
  • Case-sensitive (foo vs FOO).
  • Cannot use Java Keywords (e.g., class, public).

Naming Conventions

Standard practices for writing clean Java code.

Class

PascalCase (Nouns)

Start with Uppercase. If multiple words, capitalize each inner word.

class BankAccount
Interface

PascalCase (Adjectives)

Same as Class, but names are typically adjectives.

interface Runnable
Method

camelCase (Verb-Noun)

Start Lowercase. Inner words capitalized. Action oriented.

getBalance()
Variable

camelCase

Start Lowercase. Short and meaningful names.

int buttonWidth
Constant

UPPER_SNAKE_CASE

All uppercase. Underscores separate words. (static final).

MAX_HEIGHT
Java Bean

Encapsulation Standard

  • Class must be public
  • Private properties
  • Public Getters/Setters
  • Implements Serializable

Escape Sequences

Syntax Description
\tInsert a tab
\bInsert a backspace
\nInsert a newline
\rInsert a carriage return
\fInsert a form feed
\'Insert a single quote
\"Insert a double quote
\\Insert a backslash