Home | Hindi | Kabir | Poetry | Workshop | BoloKids | Writers | Contribute | Search | Contact | Share This Page!                      Shop Online

  News
Channels
In Focus

Analysis  
Bolography  
Cartoons
Environment   
Opinion 

Columns
 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
Jagoji
Literary Shelf 
Love Letters  
Memoirs
Musings
Ramblings
Stories
Travelogues

Computing
  General Articles
 
CC++ 
  Flash 
  Internet Security 
 
Java 
 
Linux     
  Networking  

 

Computing | Java 
Statements & Expressions

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. 

Deepak Chandrasekaran
July 29, 2001

Articles on Java     
By Deepak Chandrasekaran
JAVA: A Beginner's Guide    
Oops... I did it Again!   
Objects and Classes    
First Java Application    
Your First Java Applet   
Statements and Expressions  
Variable Type & Declaration 
Variables and Strings  
Arrays and Overloading in JAVA   

By Neeraj Mathur  
Java – Man Not Again!  
Common Misconceptions About Java 

By Ruchi Gupta
Java Virtual Machine  

Computing 
CC++ | Flash | Internet Security   
Linux | Networking  

General Articles  

Top
 


 

Recommend This Page!

Analysis | Architecture | Astrology | Ayurveda | Book Reviews | Buddhism | Cartoons | Cinema | Computing | Culture | Dances
Environment | Fables | Family Matters | Festivals | Hinduism | Health | History | Home Remedies | Humor | Individuality | Jagoji
Literary Shelf | Memoirs | Musings | Opinion | Parenting | Perspective | Photo Essays | Places | Ramblings
Random Thoughts | Recipes | Sikhism | Society | Spirituality | Stories | Teens | Travelogues | Vastu | Vithika | Women

Home | Hindi | Bolography | BoloKids | Kabir | Poetry | Quotes | Workshop | Writers | Contribute | Search | Contact


Boloji.com is owned and managed by Boloji Media Inc

Privacy Policy | Disclaimer
No part of this Internet site may be reproduced without prior written permission of the copyright holder.