The only issue with writing my assignment in an IDE is that we're meant to start writing java in txt files only, and make sure they compile in the command prompt to ensure the IDE isn't assisting when things fall over. It also makes one pay more attention to all the curly brackets and semi-colons when the IDE isn't automatically highlighting mistakes...
Compiling and Running a Java Program from the Command Prompt:
- Check that JDK is installed.
(Somehow I didn't have this installed, I thought that I did, given that Eclipse could compile my programs. Maybe I did have it installed and it was just in a non-default location) - Install JDK
- Create a temporary folder C:\Uni (or whatever you want to call it). Copy and paste the .java files into this folder
- Run Command Prompt (Start > Run > Cmd) Type "cd \uni" to navigate to the directory
- Run javac Company.java and get a funky error: 'javac is not recognized as an internal or external command, blahdy blah blah (why can't the language settings in Windows override the spelling of error messages, so I see "recognised" rather than "recognized"?)
- To tell the system where to find javac and all the other wonderful JDK programs that we installed in step 2, run set path=%path%;C:\Program Files\Java\jdk1.6.0_24\bin\ or whatever the path is. Make sure you include the semi-colon between set path = %path% and the directory, otherwise it doesn't work. NB: There's nothing to indicate this was successful, just the system prompt being displayed again...
- Run javac Company.java again. Once again, there's nothing to display that this was successful, just the next system prompt.
- Run dir to see what's in the directory. Lo and behold, there's some new files - all my .java files now have a .class file
- Run the .class file with the main method by running main Company (no .class or .java required
This is what my command prompt session looked like:
C:\Documents and Settings\mel>cd \uni
C:\uni>javac Company.java'javac' is not recognized as an internal or external command,operable program or batch file.
C:\uni>set path=%path%;C:\Program Files\Java\jdk1.6.0_24\bin\
C:\uni>javac Company.java
C:\uni>dir Directory of C:\uni
09/03/2011 10:34 PM <DIR> .09/03/2011 10:34 PM <DIR> ..09/03/2011 10:56 PM 1,578 Company.class09/03/2011 09:51 PM 2,017 Company.java09/03/2011 10:34 PM 1,451 Employee.class09/03/2011 09:57 PM 2,501 Employee.java09/03/2011 10:34 PM 1,667 Team.class09/03/2011 09:41 PM 2,868 Team.java 6 File(s) 12,082 bytes 2 Dir(s) 9,604,157,440 bytes free
C:\uni>java Company[Team Name]: Team Awesome!![Team Leader]ID: 1003Name: Melissa JonesHourly Salary Rate: 90.0
[Programmer List]ID: 1001Name: Cameron LawsonHourly Salary Rate: 77.0
ID: 1002Name: Carly RodwellHourly Salary Rate: 45.0
ID: 1004Name: Kimberley PhillipsHourly Salary Rate: 44.0
ID: 1005Name: Liam GardeHourly Salary Rate: 33.0
ID: 1006Name: Dan McNaultyHourly Salary Rate: 32.0
ID: 1007Name: Louise LatzHourly Salary Rate: 12.0
[Team Name]: Team of Champions[Team Leader]ID: 1008Name: Tom CaleyHourly Salary Rate: 54.0
[Programmer List]ID: 1009Name: Nick BellasHourly Salary Rate: 63.0
ID: 1010Name: Angela TurnourHourly Salary Rate: 50.0
ID: 1011Name: Eric LimHourly Salary Rate: 60.0
ID: 1012Name: Sanath KumarHourly Salary Rate: 42.0
ID: 1013Name: Sandeep BadwalHourly Salary Rate: 80.0
ID: 1014Name: Germaine YongHourly Salary Rate: 25.0
C:\uni>
No comments:
Post a Comment