Statements & Expressions by Deepak Chandrasekaran SignUp
Boloji.com
Boloji
Home Kabir Poetry Blogs BoloKids Writers Contribute Search Contact Site Map Gift Shop Advertise RSS Login Register
Boloji
Channels

In Focus

Analysis
Cartoons
Education
Environment
Going Inner
Opinion
Photo Essays

Columns

A Bystander's Diary
Business
My Word
PlainSpeak
Random Thoughts

Our Heritage

Architecture
Astrology
Ayurveda
Buddhism
Cinema
Culture
Dances
Festivals
Hinduism
History
People
Places
Sikhism
Spirituality
Vastu
Vithika

Society & Lifestyle

Family Matters
Health
Parenting
Perspective
Recipes
Society
Teens
Women

Creative Writings

Book Reviews
Ghalib's Corner
Humor
Individuality
Literary Shelf
Love Letters
Memoirs
Musings
Quotes
Ramblings
Stories
Travelogues
Workshop

Computing

CC++
Computing Articles
Flash
Internet Security
Java
Linux
Networking
Java Share This Page
Statements & Expressions
by Deepak Chandrasekaran Bookmark and Share
 

In the last few articles, we saw how to create an applet and an application in Java. Now lets get into the basics of Java, that is the conditional statements that are used in Java. They form the core of any programming language, because the various conditional loops in a program enable it to work the way we want it to.

A statement is the simplest thing you can do in Java; a statement forms a single Java operation. All the following are simple Java statements:

int i = 1;
import java.awt.Font;
System.out.println("This car is a "+ color + " " + make);
m.engineState = true;

Statements sometimes return values'for example, when you multiply two numbers together or test to see whether one value is equal to another. These kind of statements are called expressions. Always remember that a Java statement always ends with a semicolon. Forget the semicolon and your Java program won't compile.

Java also has compound statements, or blocks, which can be placed wherever a single statement can. Block statements are surrounded by braces ({}).

Variables and Data Types

Variables are locations in memory in which values can be stored. They have a name, a type, and a value. Before you can use a variable, you have to declare it. Variables in short are just like the lockers in a bank. Each locker has a number, a size and a key. In order to use a locker to keep your valuables, you have to tell the bank, so that its officially yours and you have the privacy. Same is the case with variables.

After variable is declared, you can then assign values to it. Similarly as soon as the bank assigns us a locker, we store valuables like will, agreement or jewelry in it.

Java actually has three kinds of variables: 

instance variables, 

class variables, and 

local variables.

Instance variables
are used to define attributes or the state for a particular object. 

Class variables
are similar to instance variables, except their values apply to all that class's instances (and to the class itself) rather than having different values for each object.

Local variables
are declared and used inside method definitions, for example, for index counters in loops, as temporary variables, or to hold values that you need only inside the method definition itself. They can also be used inside blocks ({}) . Once the method (or block) finishes executing, the variable definition and its value cease to exist. Use local variables to store information needed by a single method and instance variables to store information needed by multiple methods in the object.

Although all three kinds of variables are declared in much same ways, class and instance variables are accessed and assigned in slightly different ways from local variables. Now lets focus on variables as used within method definitions, later lets learn how to deal with instance and class variables.

Unlike other languages, Java does not have global variables (like C)'that is, variables that are global to all parts of a program. Instance and class variables can be used to communicate global information between and among objects.

Remember, Java is an object-oriented language, so you should think in terms of objects and how they interact, rather than in terms of programs. In my next article i will give you a briefer insight into how to declare variables.   

Next: Variable Type and Declarations

29-Jul-2001
More by :  Deepak Chandrasekaran
 
Views: 1196
Share This Page
Post a Comment
Bookmark and Share
Name*
Email ID*  (will not be published)
Comment
Verification Code*
Q7Q65
Please fill the above code for verification.

    

 
 
Top | Java



 

~*~
Solitude and other poems by Rajender Krishan 

    A Bystander's Diary     Analysis     Architecture     Astrology     Ayurveda     Book Reviews
    Buddhism     Business     Cartoons     CC++     Cinema     Computing Articles
    Culture     Dances     Education     Environment     Family Matters     Festivals
    Flash     Ghalib's Corner     Going Inner     Health     Hinduism     History
    Humor     Individuality     Internet Security     Java     Linux     Literary Shelf
    Love Letters     Memoirs     Musings     My Word     Networking     Opinion
    Parenting     People     Perspective     Photo Essays     Places     PlainSpeak
    Quotes     Ramblings     Random Thoughts     Recipes     Sikhism     Society
    Spirituality     Stories     Teens     Travelogues     Vastu     Vithika
    Women     Workshop
RSS Feed RSS Feed Home | Privacy Policy | Disclaimer | Site Map

garcinia cambogia

seo services

seo services

No part of this Internet site may be reproduced without prior written permission of the copyright holder.
Developed and Programmed by ekant solutions