top of page

Using Github for Java Practical Lesson

  • Writer: Siah Peih Wee
    Siah Peih Wee
  • Jul 13, 2022
  • 2 min read

Updated: Nov 8, 2022


ree


Install Git


Install Netbeans


Accept your Github Classroom Assignment

First use the link given to you to accept the assignment.


ree

Get your Github Classroom Repository URL

Wait for the repository to setup.

ree

Then keep the repository URL for later use.

ree

Start New Project

  • Start a New Project

ree

  • Choose Java with Ant > Java Application

  • Press Next

ree

  • Type in Project Name

  • Uncheck Create Main Class

  • Press Finish

ree

Create a Java Package for Each Practical

ree

Name the First Package to "Practical1"

ree

Create a Java Class in the Package

Make a Class for Each Question.

ree

Name the Java Class "Q1"

ree


Write the Java Class "Q1"

ree

Make the main function print out "Hello World!"

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

  • Save and Press Run Project

ree

  • If see No Main Classes Found, ensure you saved the file.


Run the Q1 as Main Class

ree

Ensure it is Working

ree

Go to Project Properties

ree

Copy the Project Folder Location

ree

Go to the Project Folder


ree

Create a Text Document in the Project Folder

ree

Name the Text Document to ".gitignore"

ree

Accept the change of file extension.

ree

Put in the list of files or folder to Ignore by Git

ree


Save the ".gitignore" file

ree

Run Command Prompt

ree

Get the Java Project Folder Location

ree

Go to the Folder Location in Command Prompt

ree

Connect Git with Github

Set your user name

$ git config --global user.name "USERNAME"

Set your user email

$ git config --global user.email "email@example.com"

Perform Commit to Github for First Time

Run the following Git commands

git init
git add .
git commit -m "First Commit"
git branch -M main
git remote add origin <REPLACE WITH GITHUB URL>
git push -u origin main

You will see the following

ree

ree


You will see its pushed to Github.

ree

Go to Github to Check

ree

Subsequent Commits

You can now work on more questions and commit the changes to Github by running the following git commands

git add .
git commit -m "DESCRIPTION OF COMMIT"
git push


Comments


Post: Blog2 Post
  • Facebook
  • Twitter
  • LinkedIn

©2022 by Realization Lion. Proudly created with Wix.com

bottom of page