Saturday, March 8, 2008

JAVA Lesson 3

Writing the first GUI program:
-------------------------------------

import javax.swing.JOptionPane;

public class MyFirstGUI{

public static void main(String args[]){
String name = JOptionPane.showInputDialog("Enter your name");
JOptionPane.showMessageDialog(null,"Your name is : \"" + name + "\"");

// \" is to print the double quotation mark

}
}
---------------*---------------
Screenshot:




Sunday, February 3, 2008

JAVA String

String class is defined in java.lang.String.
It represents character strings (or array of character).

Like any other java class String can be initiated using following syntax:
Class_name identifier = new Class_name(para);

For example, String name = new String("JAVA");

However, as String is commonly used class, it can be initiated as a data type (like int, char),
For example, String name = "JAVA";

JAVA Data Types

There are 8 primitive Data Types in java.
# Data_Type Size Range
1. byte 8-bit 0 to 127

2. short 16-bit -32,768 to +32,767

3. int 32-bit -2,147,483,648 to +2,147,483,647

4. long 64-bit -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807

5. float 32-bit beyond the scope (click here for more information)

6. double 64-bit beyond the scope (click here for more information)

7. boolean Either true true and false
or false

8. char 16-bit '\u0000' (or 0) to '\uffff' (or 65,535).


For more information click here.

JAVA Lesson 2

Variable declaration:
Syntax : variable_data_type identifier;
Example : int number;
String name;


Variable initialization:
Syntax : identifier = value;
Example : number = 5;
name = "your_name";


Declaring and initializing at the same line
Syntax : variable_data_type identifier = value;
Example : int number = 5;
String name = "your_name";

Saturday, February 2, 2008

Ask for help

If anyone has question regarding java, may ask me.
I will be happy to help.

JAVA Lesson 1

//Hello World

public class MyFirstJavaProgram{
public static void main(String args[]){
String msg = "Hello World!";
System.out.println(msg);
}
}


//this code will print "Hello World!"

Friday, January 4, 2008

Iteration in JAVA, the extended "for"

Iteration:
think of a situation where we need to print or manipulate a collection or an array of objects. For that we have to access each object of the collection or array, which we can do using loops (for, while, do-while), mostly we use for loop.

Ex1.
int num[] = new int[]{1,2,3,4,5,6,7,8,9};

for(int i=0; i< num.length; i++
System.out.println (n);

Since JAVA 5 for has been extended, now there is no longer the need of iterator (on the above example 'i' is the iterator). We can now use the short form of for.

Ex2.
int num[] = new int[]{1,2,3,4,5,6,7,8,9};

for(int n : num)
System.out.println (n);

Wicked cool java

Hi guys if you are learning java, or you wanna take your java skills to the next level then you can read "WICKED COOL JAVA" by Brain D. Eubanks.

This book is based on the features of JAVA 5.