Rabu, 09 Desember 2009

Java Fundamental

For newbie, this time to learn Java ..
This is a short tutorial on how to create Java files, compile the Java files, and how to run Java programs.
in this apart will also discuss some of the variables in Java ..
Please follow...
Okey now it's short tutorial on Java, not a tutorial game, but the basic tutorials of Java, to assist the novice totally
STEP 1: Create a Java program code
Well the first thing is, how the origin of a Java application program?
To run Java programs, we first create a text file (txt) ordinary, name TitleCase naming format and end with the extension. Java:
For example Test.java
To fill the program code, edit the file using any text editor such as Notepad.
FILE:: Test.java
Fill in the source code is:
Code:
public class Test (
   
/ / Test -> according to the file name: Test.java
   
/ / (Remember the Java case sensitive, unlike Test test)
)

PS: "/ /" are comments, anything written after the / / not be processed
PS2: once again Java is case sensitive, must be consider writing lowercase and uppercase.
STEP 2: compile our code
Compile the source code we have created by using the Java compiler (javac.exe) which has been included in the bundle Java SDK (J2SE), get Java SDK on http://java.sun.com/j2se/.
Use the DOS Prompt, open the Start menu-Run-type CMD.
Write this in a DOS prompt:
Code:
javac Test.java

Once compiled Test.java will produce Test.class
Quote:
Test.java (source code) compile -> Test.class (java bytecode)

STEP 3: Running the program
To run the program above we have used to compile the Java launcher (java.exe), also through a DOS prompt:
Code:
java Test

At this stage of our program will issue an error above can not be executed, because Java does not know where to begin our application of this program.

STEP 4: Start Making an application
Start running a Java application starting from the discovery of keywords (keyword):
Code:
public static void main (String [] args) ()

Now just add these keywords to the file Test.java us:
Code:
public class Test (
  
  
public static void main (String [] args) (
    
/ / Application start-point
  
)

)

So the above Test.java program can already compiled and executed.
But because it is empty, so our program they will not do any one thing, it's a useless program Smile
java Test -> go into the application start-point and finished, nothing done.

STEP 5: Remove the paper
Now to remove the output to the console (DOS prompt) we use the function System.out.println ( "word"):
Code:
public class Test (

  
public static void main (String [] args) (
    
System.out.println ( "Hello World!");
  
)

)

Our program over the run will spend writing Hello World to the console.
Ah ha! Finally we have the road program and do something, whether you are happy enough now?!
Well then we will know variabel2 in the Java programming language.

STEP 6: Recognize the variables and the type-species
Well after we know how the basic Java application from a file extension. Java to run it, it is time to get acquainted with the types of variables contained in Java.
So what's the variable??
To save a certain value in our application programs (computer memory), the value must be stored into a variable according to the type according to the type of value.
We can not save the value type to a variable number of type character value or vice versa.
In the Java programming language, the types of variables that are available include:
Quote:
- Int: to save the value of integer numbers, for example: 10
- Double: to save the value of a decimal number, for example: 0.5
- String: to save the value of words of text, for example: "Hello World"
- Boolean: to save the value of a simple yes or no, for example: true

To declare a variable that can store these values by simply using:
Code:
[tipe_variabel] [nama_variabel];

eg: int tipeInt;
declaring a variable named tipeInt as variable of type int

To fill the value to a variable they will use the sign =
Code:
int tipeInt;

  
tipeInt = 10; / / fill values tipeInt with 10


Examples of programs:
Code:
public class Test (

  
public static void main (String [] args) (
    
int a = 10;
    
double b = 0.5;
    
String c = "Hello";
    
boolean d = true;

    

    
System.out.println (a); / / console written: 10
    
System.out.println (b); / / console is written: 0.5
    
System.out.println (c); / / console is written: Hello
    
System.out.println (d); / / console is written: true

    
/ / Replace the value of a variable
    
a = 100;
    
System.out.println (a); / / console written: 100
  
)

)


Once we know the kinds of variable types and how to use it, now we see how to process it / manipulate it.

STEP 7: Operation variable
These variables can be if the same as in mathematics, namely by using the operation increase (+), subtraction (-), multiplication (*), division (/), or the result of (%).
For example: int a = 10 + 10; / / increase
Nothing special in the process variable data, simply use the +, -, *, /,%
Example:
Code:
public class Test (

  
public static void main (String [] args) (
    
int a = 10;
    
int b = 20;
    
int c = a + b; / / 10 + 20 = 30
    
int d = a - b; / / 10 - 20 = -10

    
System.out.println (a);
    
System.out.println (b);
    
System.out.println (c);
    
System.out.println (d);


    
double e = 2;
    
double f = 4;
    
double g = e * f; / / 2 x 4 = 8
    
double h = e / f; / / 2 / 4 = 0.5

    
System.out.println (e);
    
System.out.println (f);
    
System.out.println (g);
    
System.out.println (h);

    
System.out.println (5% 3); / / = 2 -> 5 / 3 = 1 remainder 2
  
)

)

Java also provides a way to streamline certain operations:
Code:
int a = 0;
  
/ / Add to the 10
  
way 1: a = a + 10;
  
I 2: a + = 10; / / shorter

Similarly, subtraction, multiplication, division.
Code:
a -= 10;
  
a *= 10;
  
a / = 10;

And Java also provides for the addition of a special condensation / reduction with 1:
Code:
a = a + 1; -> a + = 1; -> a + +;
a = a - 1; -> a -= 1; -> a -;

Tidak ada komentar: