Total members 11890 |It is currently Mon May 20, 2024 4:11 pm Login / Join Codemiles














R Scripts


Java Program composed of classes and a class consists of methods and variables. I will give you an introduction to elements of Java program here.

1. Classes and Objects:

Objects are the core of Java Programs , Object may represent a real world problem which we are trying to found solution to .Object is an instance of a class .In Java Program you will write classes and when the program run , objects will be created and do the task .

The Java Class has two components:
  1. Class declaration.
  2. Class Body.

The Class declaration contains the class name and the access modifier .The access modifier defines the accessibility of the class. There are other properties you can set in the declaration like inheritance from other class (Using extend keyword), or the class can't be base for other classes (Using final keyword) or no objects can't be created from this class (Using abstract keyword).

The Class body comes after the class declaration and it is contained within braces. The class body contains functions and variables.

The process of creating an object from the class called "instantiation" .That is why objects are also called instances of classes. Objects can be books, cars, buildings etc .For a example all books are represented by class called book .Each object has status , for example book have a name , category and price , these characteristics are called properties. Each object has a behavior, for example "OpenBook", "CloseBook", these behaviors is called methods.

2. Methods:

The methods contain the logic of the application, it do operation on the data. Each method has a declaration and body .The declaration includes the method name, return type, parameter, and accessibility. The body contains what method do, which determine the behavior of the object.

The method can be static this means, it can be invoke without referencing to an object. For example the main function of your application.

3. Variables:

Variables are the container of data. Object state is carried by variables. Variables have declaration which specifies variable name, type and accessibility. The variable must have legal identifier (name) and not a java keyword.

Rules of java legal identifier:

  1. Start with [a-z][A-Z] , or _ or $ .Don't begin with digit.
  2. First character can by followed by any series of letters or digits.
  3. Must not be a keyword.

The declaration of variable :

Should look like this:
<Type> <identifier>;

You can assign a value to the identifier:
<Type> <identifier> =<value>;

If your data type is a class, your declaration should be like this:
<classname> <identifier>=new <classname>() ;

M. S. Rakha, Ph.D.
Queen's University

User avatar Posts: 2715
Have thanks: 74 time

Have been trying to do this.
But I had been having small problems with it.
Help please.

User avatar Posts: 3
Have thanks: 0 time

rein08 wrote:
Have been trying to do this.
But I had been having small problems with it.
Help please.

Post your code... We help ya!

And great article., Don't forget to ignore <> marks!

Coding my life with Java, PHP, JavaScript, and Python

User avatar Posts: 39
Have thanks: 15 time
Post new topic Reply to topic  [ 3 posts ] 

  Related Posts  to : Elements of a Java Program
 java program     -  
 java program     -  
 java chat program.     -  
 compiling and getting of a java program     -  
 email through JAVA program     -  
 Executing a Java Program     -  
 Need Java program for display the CPU usage     -  
 Java Chat Program between two computers     -  
 Java Program for communicate PC and Mobile     -  
 Java Chat Program with client & Server     -  

Topic Tags

Java Basics

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to 2007-2011
mileX v1.0 designed by codemiles team is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to