"Computer programming is tremendous fun. Like music, it is a skill that derives from an unknown blend of innate talent and constant practice. Like drawing, it can be shaped to a variety of ends – commercial, artistic, and pure entertainment. Programmers have a well-deserved reputation for working long hours but are rarely credited with being driven by creative fevers. Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination, but because their imagination reveals worlds that others cannot see." ~ Larry O'Brien and Bruce Eckel
This week is all about getting started programming in Java, learning about different errors you can make and how to correct them, and working with variables and print statements to produce meaningful output.
By the end of this unit you will be able to:
- compile and run Java programs in the BlueJ development environment
- write programs using variables and print statements, and perform simple computations
- debug basic syntax and logic errors
- Start using git to get assignments
- Read chapter 1 and 2.
- Install Java and BlueJ on your own computer.
- Clone the repo for assignment 1 and follow the instructions in the README.md file.
- Make sure your name appears in a comment within each .java file
- Then, in BlueJ, choose Project>Create JAR File.
- In the dialogue that pops up, check the “Include Source” box
- Click continue, then navigate to the location you want the jar file to be placed.
- TBD
The Java Developement Kit (JDK) contains a command line compiler for java programs. As a programmer you should:
- Know how to use a terminal/command window.
- Know how to use javac from the command line!!
Important
Windows Users Read THIS!!: As discussed in class, the java and javac must be added to the Windows PATH environment variable before you can use them in PowerShell or a Command Window. Instuctions for configuring the PATH variable can be found here. You will also need to set the JAVA_HOME environment variable.
Windows: Go to the start menu. Then follow the instructions here
Mac OS X: The Terminal application can be found at /Applications/Utilities/Terminal.app
. Just double click it to launch it.
Linux: If you are running linux you should already know how to open a terminal :-)
- Write a simple java program and save it. (e.g. HelloWorld.java).
- In the terminal, change to the directory that contains the java file. On Windows, you change to the drive containing the java file and then cd to the directory.
# Windows
U:
cd \Path\To\Directory\With\Java\File.
# Mac/Linux
cd /Path/To/Directory/With/Java/File
- Compile the java code using the command:
javac [filename]
. For example:javac HelloWorld.java
. This example will create a file named HelloWorld.class.
A simple java program can be run using java command: java [classname]
.
In our example it's java HelloWorld
. Important: Notice that we do not use an extension!! When we pass 'HelloWorld' to java, it knows to look for 'HelloWorld.class'
Since Java 11, you can run a single file Java program without using javac
. For example, if you have a file HelloWorld.java
, you can compile it and run it in a single step using java HelloWorld.java
.
rm
- Remove file e.g.rm HelloWorld.class
cd
- Change directory:cd csisi10a
ls
- list directory contents:ls
orls csis10a
pwd
- present working directorymkdir
- Make directory:mkdir csis10a