|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
. . . . . |
Java For Kids tutorial 2Start the java tutorial Now ! Run JUDO. Before you write your program you have to select which program type you are going to use. This is done by clicking the "Program" menu and then clicking "Program Properties...". Then chose the type of program(in this case "Text") and click "OK". Start by writing in the top text box
void main() {
}
This is the core inside which we start to program. Every program must go inside a
void main() method which is followed by curly brackets { }
Java Statements are :
Methods are calls to action , they do something.
Flash Tutorials in Video Format -
Watch them now at LearnFlash.com Java VariablesVariables can be a many different types. They represent a memory location and stand for a value and can be changed by the program. They must be declared what type they are at the start of a program. Notice after each line or statement is finished with a semi-colon ( ; ) . Rules for variables:
Exercises Java Declaration
All variables must be declared. That is, they must tell the processor what type of data they are
(datatype). Datatypes can be a number such as int or double. Or Text such as a String.
Or a True/False datatype called a boolean. int myAge ; double price ; String myName ; boolean likesJava ; Java Initialisation
Initialisation must be done after the declaration. Its purpose is to give a value to the variable.
If given no value, Java assumes that the value is "0", or false for a boolean. myAge = 14 ; price = 12.95 ; myName = "Fred Durst" ; likesJava = false ; Variables can be declared and initialized in the one line: int myAge = 14 ; double price = 12.95 ; String myName = "Fred Durst" ; boolean likesJava = false ; Declaration and initialization should be done at the top of the program before the variables are used.
Number Variables int- integer or whole numbers such as 3, 9, 32, 456int age = 9; int year = 2003;
double- numbers with a decimal point in them such as 1.00 , 34.54, 234.07double price = 12.45 ; double pi = 3.412 ; Java Text VariablesJava String- a sequence of characters or letters such as "a string of text" , "Steve Happ" , "GameBoy 3.34". String myName = "Steve Happ" ; String gameType = "Shoot 'em up"; boolean - True or False Variables
boolean - is either "True" or "False" boolean isLearningJava = true ; boolean likesIceCreams = false ; (Just joking ! ) Java Comments
Comments start a line with "//" . They are not executed. They are inserted by the programmer to
explain what she is doing. And when coming back later, you or another programmer can quickly
follow what has been done.
Now lets write a program that uses these ideas.
void main() {
// declaration and initialization of variables
int sum = 4 + 3 ;
double price = 12.34 ;
String book = "Learning Java" ;
String name = "steve happ" ;
// do the programming work
printLine("Attention Computer Book Shop");
printLine("I want to buy " + sum + book +
" at the price of $" + price);
printLine("Yours Sincerely");
printLine(name) ;
}
Type in the above code(in red) into the code window and press the "Run" button. What did you get ?
Notes on Java program above
Key wordsThese words are reserved--you cannot use any of these words as names of variables in your Judo/Java programs.
. Java EXERCISES Go to my good friend Khoa's Java Tutorials - for beginners . |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
. | Home | Flash MX | Actionscript 2.0 | Flash 3D | Flash 8 | Flash Database | Flash Mobile | Flash CS3 | Java For Kids | Video Course | General Video | Photoshop | Web Design | Digital Photography | Games | free backgrounds | Resume | Streaming Video | Students Work | Links | Contact me | sitemap | reviews | . . |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||