![]() |
Channels | ![]() |
In Focus |
Cartoons |
Education |
Environment |
Opinion |
Photo Essays |
Columns |
Business |
Random Thoughts |
Our Heritage |
Astrology |
Ayurveda |
Buddhism |
Cinema |
Culture |
Festivals |
Hinduism |
History |
People |
Places |
Sikhism |
Spirituality |
Society & Lifestyle |
Parenting |
Perspective |
Recipes |
Society |
Teens |
Women |
Creative Writings |
Computing |
Humor |
Individuality |
Literary Shelf |
Memoirs |
Quotes |
Stories |
Travelogues |
Workshop |
Computing | Share This Page | |
Statements & Expressions
|
||
by Deepak Chandrasekaran |
![]() |
|
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; 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 Class variables Local variables 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. |
||
Share This: | ||
29-Jul-2001 | ||
More by : Deepak Chandrasekaran | ||
Views: 1920 Comments: 0 | ||
| ||
Top | Computing |
|