Skip to content

cbfacademy/java-exercises-basics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Our First Java Program

Java Language

The goal of this exercise is to:

  • create a simple Java project
  • create a Java package
  • create and run a simple Java program that prints Hello World! to the screen.

Setup

  • Inside the repository root directory:

    • create a sub-directory called com
    • inside the com directory, create a sub-directory called cbfacademy
  • Inside that last sub-directory (cbfacademy), create a file called HelloWorld.java.

At this point, our project folder structure looks as follows:

Folder Structure

πŸ‘‹ Hello World

Open the HelloWorld.java file in your code editor, type the following Java code, then save your changes.

package com.cbfacademy;

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

βŒ› Compile

In your terminal, navigate to the repository root directory.

Execute this command to compile our Java program

javac com/cbfacademy/HelloWorld.java

A HelloWorld.class file is now created alongside our Java source file.

Folder Structure

πŸƒ Run

To run our Java program, let's execute the following command:

java com.cbfacademy.HelloWorld

πŸŽ‰ Our program prints the following on your screen.

Hello World!

πŸ“ Note

With the above, we've just created and run our first, simple, Java program.

In this exercise, we've done all the work manually to get acquainted with the basics of creating, compiling and running a simple Java program.

In the rest of the course, we'll be using Visual Studio Code to help us with the build and execution process, and focus on the Java language itself.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published