|
 
- Thread
- 30
- Credit
- 0
- Money
- 0
- Read Perm.
- 150
- Joined
- 3-3-2009
|
First Time on java, for newbee
Post Last Edit by psv_jupiter at 18-3-2009 17:43
Post Last Edit by psv_jupiter at 18-3-2009 17:43
Post Last Edit by psv_jupiter at 18-3-2009 17:42
Post Last Edit by psv_jupiter at 18-3-2009 17:41
Post Last Edit by psv_jupiter at 14-3-2009 12:18
Post Last Edit by psv_jupiter at 14-3-2009 12:18
Post Last Edit by psv_jupiter at 14-3-2009 12:17
Post Last Edit by psv_jupiter at 14-3-2009 02:13
This post is for those who never know anything about java programming only.
Thing to take note.
1) To run java program you have to have JDK=Java Development Kit in your operating system.
to download JDK 1.6 click here
2) After you install JDK, you can either use IDE=integrated development environment to do your coding or use simple notepad program to type your code in. For me I highly recommend you use IDE.
There are quite a numbers of IDE, such as NetBean, Esclipse, JGraps,........
For me, I personally recommend you to use Net Bean. The current most updated version of net bean is 6.7
to dl net bean 6.7 with java, click here
3. Run your first time program
Type this code and save with name "Welcome.java". Please take note that your file name and your class name must be the same. As in this case it is "Welcome". what is class? class is the file you obtain when you compile your code. In addition to that, the class name should be in what it is liked "Uppercase Letter every first word".
For e.g a class name might be : "BinarySearchTree". (Thank to ePrasart for reminding me )
public class Welcome{
public static void main(String[] args){
System.out.println("Welcome to java");
}
}
If you use net bean, to run the program click button run or simply press Shift+F6
you can also compile first before you run , to compile click F9 however if you use netbean, or eclipse your syntax errors will be shown clearly, no need to compile.
Another simple but yet show quite fun that will be posted here is : Guess.java that guess your birthday. Wanna know how it work? Copy and paste the following code and Run !
/*Author: Jupiter
*KhmerIT forum
*/
import javax.swing.JOptionPane;
public class Guess {
public static void main(String[] args){
String[] set=new String[5];
set[0]=" 1 3 5 7\n 9 11 13 15\n17 19 21 23\n25 27 29 31";
set[1]=" 2 3 6 7\n10 11 14 15\n18 19 22 23\n26 27 30 31";
set[2]=" 4 5 6 7\n12 13 14 15\n20 21 22 23\n28 29 30 31";
set[3]=" 8 9 10 11\n12 13 14 15\n24 25 26 27\n28 29 30 31";
set[4]="16 17 18 19\n20 21 22 23\n24 25 26 27\n28 29 30 31";
int result=0;
for(int i=0;i<5;i++){
int answer=JOptionPane.showConfirmDialog(null, "Is your birthdate in these number ?\n"+set [/**/i]);
if(answer==JOptionPane.YES_OPTION) result+=(int)(Math.pow(2, i));
if(answer==JOptionPane.CANCEL_OPTION) System.exit(0);
}
JOptionPane.showMessageDialog(null," Your Birday is : "+result+"!");
}
}
To learn more about java programming visit Tutorial in sun java website. The link is : click here |
-
-
Guess.zip (551 Bytes)
-
-
Guess.zip (626 Bytes)
|