
Originally Posted by
martijno0o0
ok, like the hello world? nooby tutorial step by step if thats not to much for you XD
Ok. Here's a fun lil starting program. You'll have to forgive me for the lack of flare, but Im a lil rusty when it comes to Java, but I need to get back up to speed if I want to program Android. Anyway lets get started.
Lesson: 1
[php]
import javax.swing.JOptionPane; //we are importing the JOptionPane that will make the pretty window for us.
public class HelloName //the name of our class. Unlike C++ everything is a class. A class can be run directly only if it has a main method.
{
public static void main(String[] args) //the main method for all Java programs
{
//
JOptionPane.showMessageDialog(null, "Hello, World"); // the method showMessageDialog() is a static method called from the class JOptionPane
String name = JOptionPane.showInputDialog("what is your name?"); will save your answer into the String name.
JOptionPane.showMessageDialog(null, "Hello " + name);//Now we use String name to greet the user.
System.exit(0); //return 1; in C++ Basically we exit the program. And return control to the system.
}
}
[/php]
This a fun little Hello world program. You enter your name and it greets you.
I commented the code to explain what I can, but feel free to ask questions.
Now since I pretty much gave you the code you should do something with it to be sure you understand it. I want you to create a program that will ask for a persons name and age and then greet the person with both.
EDIT: Oh yeah one more thing... man its been a while since I've done java. I'm a little out of it. Anyway was gonna say that System.exit(0); really isn't needed since Java automatically handles that usually, but you can put it anyway. You can also just put return; too... it doesn't matter in this case.