In your terminal, copy paste the code below to clone this repository and turn off git so that it's simply a copy of the folder structure in your IDE. You will NOT be able to push.
git clone git@github.com:hstatsep/apcsa.git
cd apcsa
rm -rf .git
echo "Done"
- Open
Template.java - Do NOT edit the file. Just look at it!
Note: your filename MUST match the class name. Naming convention: FirstLetterOfEveryWordCapitalized.java
cd u00-other
mkdir HelloWorld
cd HelloWorld
touch Hello.java
-
Open
Hello.javaand paste in the same code from your template (but update the class name toHello). Then run the following commands: -
javac Hello.java -
java Hello -
You should see
Hello Worldin your terminal -
As a general rule of thumb, use this same format when making new programs (
cdinto the correct directory, make a folder with the appropriate name,cdinto it, then name your fileWhateverYouWant.javawhich will then get compiled toWhateverYouWant.class). We make an entire folder because sometimes we will have multiple Java files that relate to each other, so this helps keep them organized.- As a shortcut, you can copy with the
cp source destinationcommand. I.e. once you make yourHelloWorlddirectory andcdinto it, you could docp /workspaces/apcsa/Template.java ./WhateverYouWant.java
- As a shortcut, you can copy with the
- Copy/paste the following into the terminal.
echo "" >> ~/.bash_profile
echo "jcar() { javac \$1.java && java \$1 ; }" >> ~/.bash_profile
echo "" >> ~/.bash_profile
echo "Done"
To see the command take effect, you must reload your IDE.
- Try this out by adding
!to your Hello World program so that it outputsHello World! - Run the shortcut by doing
jcar Hello
- Copy/paste the following into the terminal.
echo "" >> ~/.bash_profile
echo "alias gp=\"git add ." >> ~/.bash_profile
echo "git commit -m 'update repo'" >> ~/.bash_profile
echo "git push\"" >> ~/.bash_profile
echo "Done"
- If you still see the last command in your terminal, press ENTER
- Close the terminal and open a new one
- In the future, you can simply type
gpto automatically add/commit/push all updated files in a repo - You can continue to use
git add filenameif you would like to be more selective, and/orgit commit -m "message"if you would like to be more specific