flash animation video tutorials

 

 

 

START LEARNING
FLASH NOW

Get instant access to over
45 minutes of FREE Flash tutorials on video
 and our newsletter.

Name:
E-Mail:
Phone:
Describe

.

.

.

 
Web video-animation.com

.

.

flash tutorials flash tutorials flash tutorials flash tutorials

Java For Kids tutorial 2

Start 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 :

  • Single executable actions.
  • They usually end with a semi-colon ( ; )

Methods are calls to action , they do something.
eg printLine("this"); // prints out "this"
main() // makes the whole program execute
readInt() // reads in an integer typed in by a user

Flash Tutorials in Video Format - Watch them now at LearnFlash.com  

Java Variables

Variables 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:
  • The first character must be a letter, not a number.
  • Remaining positions can be filled with numbers or letters and "_"
  • Don't have any spaces
  • Variables are case-sensitive. They must be written the same way every time. e.g. Price is not the same as price
  • It is usual for variables to start with a lower-case letter and any subsequent words be capitalized. e.g. costPrice, sellingPrice, myAge , theNumber.
  • Make variables names understandable. Use real words that describe what it does. e.g. rectangleWidth, boxLength, carSpeed, cricketScore .
These variable names are illegal : 2formula, 24_Cost, egg Cost .

Exercises
1. which of these variable names are legal ?
a. result b. Product1 c. a d. textbox e. text1 f. field_2 g. stackDepth h. ball Speed

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.
These are declarations :

	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.
Here are examples of initialization:

	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, 456
		int age = 9;
		int year = 2003;

double

- numbers with a decimal point in them such as 1.00 , 34.54, 234.07

		double price	= 12.45 ;
		double pi		= 3.412 ;

Java Text Variables

Java String

-

a sequence of characters or letters such as "a string of text" , "Steve Happ" , "GameBoy 3.34".
- NB strings are usually enclosed inside Quotation marks - " ".


		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

  1. . See that I have used ( // ) in some lines at the start. These are comments and are not read when the code runs. They are meant to be notes to oneself to help remember what you are doing throughout the code and for others to be able to follow what you have written. They also break up the program into structural chunks .
    	// this is a line of comment
    	// and will not be processed
    	//  it is used for reminders to oneself
    	// and for  structural purposes
    
  2. printLine is a command which does what ? Good guess ! It prints a line out . The usage is as follows:
    	printLine("Whatever is between the quotes will be printed ") ;
    
  3. When you want to print a section of text and follow it with a variable you use the "+" character. As in :
    		printLine("My name is " + name) ;
    

    This will print out :
    My name is Steve Happ
    Sorry, I left out a full stop. So I must add a "." with a "+" after name. Here is what it will look like:
    	PrintLine("My name is " + name + ".") ;
    

    Try this :
    	PrintLine("My name is " + name + ", and my age is " + age) ;
    

    Whoops! I forgot the full stop again. You fix up my mistake.

Key words

These words are reserved--you cannot use any of these words as names of variables in your Judo/Java programs.

abstract double int strictfp
boolean else interface super
break extends long switch
byte final native synchronized
case finally new this
catch float package throw
char for private throws
class goto protected transient
const if public try
continue implementsreturn void
default import short volatile
do instanceofstatic while

.

Java EXERCISES
1. Write a program that prints out your name on the screen.
2. Write a program that prints out your name, street, city, phone number all on different lines.
3. What is a java application ?
4. What method must every application program have ?
5. What is a statement ?
6. What must a statement end with?
7. What is a variable ?
8. What are the rules for variables ?
9. Text (e.g. "Steve") is what type of variable ?
10. What is a datatype ?
11. What datatypes (variable types) have decimal points ?

Go to my good friend Khoa's Java Tutorials - for beginners .

flash 8
.