buckyaustin
Newbie
- Aug 27, 2013
- 32
- 24
Welcome to buckyaustin's java tutorial. From the creators of Learn xHTML/HTML and CSS.
One of the most complicated things to start learning is programming. So in this tutorial I hope to open a world of possibilities to you all. At the end of this tutorial you will be well versed in programming jargon. Cause that is all it really is jargon, nothing more nothing less. It isn't even that hard to do. You will notice that as you follow along.
If you think this is difficult, think again, it is like learning to speak a foreign language. It takes time and practice. I only hope to provide you with the building blocks for this time and practice.
In this first post I just want to get you set up and to learn the basics. I mean the very basics.
Ok download eclipse IDE and the Java Development Kit (JDK). Install the JDK, restart your computer then install Eclipse. There is an additional step in Windows where you have to open Eclipse and point eclipse to the JDK. But I won't be explaining that because it is on the eclipse website.
On Linux open up the command line and type dependent on distro;
[Debian (.deb)]
Code:
sudo apt-get install openjdk-7-jre eclipse
[password]
[Red Hat (.rpm)]
Code:
su
[password]
yum install openjdk-7-jre eclipse
Restart your computer. Open up eclipse, it will ask you for a workspace, Type in the location where you want to store your programs. I use ?\home\unknown\workspace\?. Eclipse will even create the folder if it doesn't exist.
Now this is where I have to explain naming conventions. Projects start with an upper case. Packages come after this and start with a lower-case. Classes come after packages and start with upper case. Then after Classes there is variables which start with a lower-case. Any way notice that it is in the order upper, lower, upper, lower. This is called camel cassing and all programming languages use it. The reason for this is to allow the programmer to know what they are using, a package or a variable. Even thou you should know what you are using this does help.
OK go to file, click new, click project. Name it anything you want. Right click on your project, new, package. Name the package conversion. Right click conversion. Click new and Class. Name the class CurrencyConverter.
The reason you named the package conversion was because the package can hold many different converter programs, and you will want to make the name meaningful but at the same time abstract.
The left side of eclipse is called the package explorer. The middle is the text editor. And the bottom is the console. The top is the toolbar.
Ok go to the text editor and make sure you have this in your CurrencyConverter
Code:
[FONT=Times New Roman][SIZE=3]/*
Author: buckyaustin
Date: 06/10/2013[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]Purpose: To present user with a menu. And display them output[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]Version: Version 1[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]*/[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]public class CurrencyConverter[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]{//start of class[/SIZE][/FONT][INDENT] [FONT=Times New Roman][SIZE=3]public static void main(String [] args) [/SIZE][/FONT]
[/INDENT]
[INDENT][FONT=Times New Roman][SIZE=3]{//start of main method
[/SIZE][/FONT]
[/INDENT]
[INDENT=2] [FONT=Times New Roman][SIZE=3]//lets display an attractive title to our program[/SIZE][/FONT][/INDENT]
[INDENT] [FONT=Times New Roman][SIZE=3] System.[I]out[/I].println("\t\t Currency Converter!");
[/SIZE][/FONT][/INDENT]
[INDENT=2] [FONT=Times New Roman][SIZE=3]//Display the menu for the user to choose from.[/SIZE][/FONT]
[/INDENT]
[INDENT] [FONT=Times New Roman][SIZE=3] System.[I]out[/I].print("1: \t Convert to US Dollar." +[/SIZE][/FONT][/INDENT]
[INDENT=3] [FONT=Times New Roman][SIZE=3]"2: \t Convert to AUS Dollar." +[/SIZE][/FONT]
[/INDENT]
[INDENT=4] [FONT=Times New Roman][SIZE=3]"3: \t Convert to STG. \n");
[/SIZE][/FONT]
[/INDENT]
[INDENT][FONT=Times New Roman][SIZE=3]}//end of main method[/SIZE][/FONT]
[/INDENT]
[FONT=Times New Roman][SIZE=3]}//end of class[/SIZE][/FONT]
[COLOR=#000000]
[/COLOR]
Breakdown;
- The '/*' and '*/' are the start and end of a block comment. In this block comment you give information about the program. Which version it is, what has been changed, creators name etc.
- The '//' is a single line comment anything that comes after this is just ignored, you add them there just for you or anyone else who is going to be working on the program. Make sure you add enough of these for future reference.
- '{' are the start of methods. After these I have added comments, that is because you can easily get confused about which curly bracket belongs where and how many are needed in your program. Each curly bracket gets a line to itself. Opening curly brackets mean on the next line you insert an extra tab, closing brackets mean on the next line you insert one less tab/indent.
- 'System.out.print' in any of it's forms is just a way to display on the console. '\t' is called an escape character, it escapes from 'Sytem.out.prints' normal rules and inserts a tab. '\n' is another but this time it means new line.
- 'System.out.print' displays anything within it's brackets, but just like math anything in the brackts has to be completed before the rest of the math can be done. So the '+' symbol adds/joins the Strings of output together so it displays the way we want.
What's next?:
Well in the next post we will be going onto variables, conditional statements and your first introduction into Object Orientated Programming (OO).
Last edited: