Monday, December 27, 2010

How to write programs in java

In java everything is done in the form of object.
What is object?
object is in the form of physical anything exist in the real world.
how to create these objects?
you need to write the classes for creating the object. objects have behaviors and it's actions. these are also called as object members.
what is an class?
class is an model to create the objects. by using classes you write the java programs

I am going to explain the sample program to print hello in console.
//createing the class by using the ClassName
class ClassName {
public static void main(String args[]){
System.out.println("hello");
}
}
In above example class is an keyword to represent the classes. ClassName is what ever you want to write the class name.
public static void main(String args[])
in this line everyone having some functionality.

public is an access specifier which is used to represent the data. this is learn when we are discussed the access specifiers.

Static is an keyword. if you are declare the members as static these members are used throughout the application. remember this static members are used and accessed with other static members only. not every where in the applications.

void keyword if one function is return some type of value that type is mention before the function name. if you don't have any return type values you need to mention void before the function name or method name.

main(String args[]) is an method name and parse the string type of array argument args[].

System.out.println("hello");
System is predefined class. out is an printstream class object it represents the standard output stream println is method of printstream class which is used to print the output stream content in system console.

No comments:

Post a Comment