Translate

Indonesian English French German Spain Italian Russian Portuguese Japanese Dutch Arabic Chinese Simplified

Basic java programming android(2)

Friday, July 2, 2010

This is example for java programming
Making a welcome program for the user, the user has a name and a hobby.
Create two files namely pengguna.java and userInterface.java that contains the following:
In pengguna.java file
import java.io. *; / / retrieve the standard classes available in java

public class users
(
/ / Declaration attribute
private String name;
private String hobby;

/ / Method declaration
/ / No return value
/ / Be used void
public void setNamadanHobi (String name, String Hobbies)
(
this.nama = name;
this.hobi = Hobbies;
)
/ / Method to display the names and hobbies object to be created
public void lihatDataDiri ()

(
System.out.println ("\ n" + this.nama + "which has a hobby:" + this.hobi);
)
)
In userInterface.java file
import java.io. *;

public class userInterface
(
public static void main (String args [])
(
a user user = new object ();// creation of user classes
a.setNamadanHobi ("Stephen", "read ");// give a name and a hobby in objects
System.out.println ("\ n \ tWelcome");
a.lihatDataDiri ();// calls method for manampilkan names and hobbies
)
)
Then at the command prompt move to the directory this file is located and then do this command (javac to compile java programs while running the program)

0 comment:

Post a Comment

 
Theme by New wp themes | Bloggerized by Dhampire