Hello World with Git
After all the installations and configuration we are ready to create the classic Hello World in Java. This Hello World will include using git and GitHub.
Git
Use the Hello World tutorial for detailed explanation on the below steps.
- Create git repository on GitHub
- Name it
hello-word - Initialize with a README
- Name it
- Create a folder to keep git repositories on local machine
mkdir ~/github
- Clone the repository from GitHub to your local machine
cd ~/githubgit clone https://github.com/<username>/hello-world
Hello World in Visual Studio Code
- Open vscode
cd ~/github/hello-worldcode .
- Create
Main.java- Contents:
public class Main { public static void main(String[] args) { System.out.println("Hello, World!"); } }
- Contents:
- Compile and run from terminal
javac Main.java && java Main
- Run the code from vscode
CTRL + F5or useF5to start a debug session- Verify output in Debug Console
- If everything worked then your Development Environment has been successfully configured.
- Create a new commit with your Hello World code
git add -allgit commit --message "Hello World"
- Push your code to GitHub
git push origin master
Hello World in IntelliJ IDEA with Unit Testing
IntelliJ works best when used with Maven or Gradle. I will be using Gradle since I know more about it.
TestNG will be used for writing unit tests. Setting up TestNG can be a daunting task if you are not familiar with Java and Gradle, so to spare you time I have made a scaffold that works out of the box with Gradle. cos212-prac-scaffold can be found on GitHub.
- Download and install IntelliJ IDEA
- Create a directory for the scaffold
mkdir ~/github/hello-world-test
- Download the scaffold archive
curl --location https://github.com/egeldenhuys/cos212-prac-scaffold/archive/master.tar.gz --output /tmp/master.tar.gz--location- Follow redirects
- Extract the archive
tar --extract --file /tmp/master.tar.gz --directory hello-world --strip-components 1--strip-components 1will remove the first component in the path of the file that is being extracted. For example/cos212-prac-scaffold/README.mdwill be extracted toREADME.mdinstead of/cos212-prac-scaffold/README.md
- Open
~/github/hello-world-testwith IntelliJ - To be continued...