📘LESSON 4
3.1 Lesson Outcomes
After completing this lesson, learners will be able to:
- Explain the structure of a simple Java project.
- Identify Java source and class directories.
- Compile Java source code.
- Run compiled Java programs.
- Explain the Java compilation and execution process.
3.2 Overview
Java applications are developed within organized project structures that contain source files, compiled class files, and supporting resources. Java programs must first be compiled before they can be executed.
This lesson introduces learners to Java project organization and explains how Java source code is compiled and executed using the Java compiler and JVM.
Compilation and execution are important processes in:
- software development,
- enterprise systems,
- Java application deployment,
- and programming environments.
Understanding Java project structures and execution processes is important because they form the foundation of Java application development.
KT0401 — Simple Java Project
A Java project is an organized collection of:
- Java source files,
- packages,
- libraries,
- and resources.
A simple Java project contains:
- source code,
- compiled files,
- and project folders.
Example of a Simple Java Project Structure
MyProject
├── src
├── bin
└── libraries
Components of a Java Project
| Component | Purpose |
|---|---|
| src Folder | Stores source code |
| bin Folder | Stores compiled files |
| libraries | External dependencies |
Importance of Java Projects
Java projects support:
- organized development,
- easier maintenance,
- and project management.
KT0402 — Java Source and Class Directories
Java projects contain separate directories for source files and compiled files.
Source Directory
The source directory stores:
.java
files written by developers.
Example Source File
Main.java
Class Directory
The class directory stores:
.class
files generated after compilation.
Example Class File
Main.class
Comparison of Directories
| Directory | Purpose |
|---|---|
| Source Directory | Stores source code |
| Class Directory | Stores compiled bytecode |
Importance of Directories
Directories help developers:
- organize projects,
- separate source code,
- and manage compiled files.
KT0403 — Compiling the Java Source Code
Compilation is the process of converting Java source code into bytecode.
Java source code is compiled using:
javac
Example Java Source Code
public class Main {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
Compilation Command
javac Main.java
Result of Compilation
Compilation produces:
Main.class
Importance of Compilation
Compilation:
- checks syntax,
- converts source code into bytecode,
- and prepares programs for execution.
KT0404 — Running the Compiled Java Code
After compilation, Java programs are executed using the Java Virtual Machine (JVM).
Java programs are executed using:
java
command.
Execution Command
java Main
Program Output
Hello World
Java Execution Process
| Step | Process |
|---|---|
| Write Code | Create source code |
| Compile | Generate bytecode |
| Execute | JVM runs program |
Importance of Program Execution
Execution allows:
- applications to run,
- output to be displayed,
- and software to perform tasks.
3.5 Key Notes / Summary
- Java projects organize application resources.
- Source directories store
.javafiles. - Class directories store
.classfiles. - Compilation converts source code into bytecode.
javaccompiles Java programs.- The JVM executes compiled Java programs.
- Java execution follows compile-and-run processes.