Total members 9950 | Gratitudes |It is currently Sat Feb 11, 2012 3:12 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 3 posts ] 
Author Question
 Question subject: Elements of a Java Program
PostPosted: Tue Jan 27, 2009 8:59 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2103
Location: Earth
Has thanked: 39 time
Have thanks: 56 time

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:
Code:
<Type> <identifier>;


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


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

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Elements of a Java Program
PostPosted: Thu Jul 22, 2010 1:11 pm 
Offline
Newbie
User avatar

Joined: Mon Jul 19, 2010 1:17 pm
Posts: 3
Has thanked: 0 time
Have thanks: 0 time
Have been trying to do this.
But I had been having small problems with it.
Help please.


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Elements of a Java Program
PostPosted: Sat Nov 27, 2010 12:02 am 
Offline
Newbie
User avatar

Joined: Thu Nov 18, 2010 11:56 am
Posts: 49
Has thanked: 0 time
Have thanks: 15 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


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 3 posts ] 
Quick reply


  


 Similar topics
 Topic title   Forum   Author   Comments 
 C C++ program help using class  C-C++  Anonymous  0
 Java seminar topic with demo  Java  Anonymous  1
 java project code  Java  Anonymous  0
 change Font of text in java  Java examples  msi_333  1
 Read your gmail using Java code  Java examples  msi_333  5

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: Google Adsense [Bot] and 2 guests



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team