|
Java Tutorial |
YourFirstProgramThese pages make up the course notes for my Java programming course (run at Dallam, Milnthorpe, Cumbria). Hopefully they also make a useful self-learning tutorial. Most IDEs have a concept of a “Project”. This is nothing to do with the Java language, it is a convenient way of grouping together all the files created as part of one application. So start by creating a new project. In Eclipse (including EasyEclipse) we do this by by selecting the File Menu a the top left and chooing New -> Project ![]() this brings up the New Project Wizard ![]() Choose Java -> Java Project to bring up the following screen ![]() Now that we have a project set up we need to add a new Class. This creates the file in which we will store our source code. To do this either use File -> New -> Class or right click on the project and choose New -> Class. ![]() In the next dialog name the class ![]() Ignore the warning about the "default package" at this stage and click finish, this creates a new class file and drops you back to th editor - the place where you can edit your code. ![]() Notice that some of the code has been generated for you, look at the Copy and Paste the code from the Now what we need to do is compile and run the code. Compiling is something that EasyEclipse takes care of automatically, so for now we will ignore that step. To run the code right click in the edit window (i.e. place the mouse somewhere over the code and click the righthand button) and choose Run As -> Java Applciation ![]() Before moving on make sure you have grasped this:
Remember to Right Click and choose Run As -> Java Applciation to see the effects of your changes. A word about code formatting You will notice that throughout this tutorial the code examples for a specific style. For example code inside curly braces { ... } is indented. Class names begin with CAPITAL letters whilst variable and method names begin with lower case letters. Something close to a religious war can break out from time to time about the formatting of code, some people get very upset if the { is on the same line as the if (...) { , preferring it on the line after. Some aspects of formatting will make your life easier (such as consistent use of capitalisation and indentation) and you should pick a style and stick to it. Eclipse has a facility to reformat your code, so if it gets in a mess Eclipse can help, but it is not hard to format your code as you go. This work is Copyright Chris Hunter 2007, you may use it for non-commercial purposes |