Three Main Components in my Simple Java Program

Let’s take a look at my simplest java Source Code “Hello Tony!”

At least I have to write 3 component:

1. Firstly, I must to define my CLASS Name

with sintax

————-

class name {

}

————-

in here I read this concept like: “this is a class named … and the content of the class inside {}

in here my Class name is ‘HelloTony’

class HelloTony
{
public static void main(String[] args)
{
System.out.println(“Hello Tony!”);
}
}

————————————————————

2. then, I must define my main METHOD

as I understand that in Java, a class must be having method or methods

(as a characters of the class: what kinds of actions can be done by the class. for example: class CAR have methods go forward, go backward, stop, turn right, turn left )

so when I define an Class, I also must define the main METHOD with sintax:

———————————–

public static void main (String [ ] args)

{ ….

Object.method ( ) ;

}

—————————————-

a main Method in Java language must be starting with

public static void main (String [ ] args)

Note: ‘String’ with CAPITAL ‘S‘ !!!

The modifiers ‘public’ and ‘static’ can be written in either order ( public static or static public ) but the convention is to use Public Static as shown above.

Also, we can name the argument anything we want (args….or…..argv…or….arguments….etc) but most programmers choose “args” or “argv”

the ‘public static void‘ keywords means JVM interpreter can call the ‘main Method’ to start the program (public)…..without creating an instance of the class (static), and the program does not return data to the JVM (void) when it ends.

class HelloTony
{
public static void main(String[ ] args)
{
System.out.println(“Hello Tony!”);
}
}

Note: System.out.println (“…”); with CAPITAL “S

———————————————-

3. I must define my all OBJECTs or CLASS in side the main Method & Methods invoke by Object/Class

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: