Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Variables in Java
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


nandu
Variables in Java
1 Answer(s)      6 years and 8 months ago
Posted in : Java Beginners


What are the variables in Java?


Advertisement
View Answers

February 28, 2008 at 7:21 PM


Variable :

Variables are the temporary memory location where we can store the data for the time being .We can assign the value to the variable once when it is declared. The value of the variable can be changed anywhere in the program if the variable is accessible in that scope. We can declare the variables of any data types.

Single variable declaration in single line

int weight = 100; or

char = 'a'; or

float = 10 .45 f ;

multiple variables declaration in single line

int weight = 100,height = 200,height = 600; // correct

int circle_Height=24 ; radius = 15 ; // incorrect

during the variable declaration we have to follow some rules such as

(1) variable name always begin from alphabet letters, sometimes we can use underscore and ampersand sign before the variable name.

(2) variable name should be meaning full.

(3) we can't use the white space between the variable name ,but can use underscore

(4) variable name should not be a keyword

Constants :

In java we use the keyword final for making the variables constant . The values of the constant can't be changed once its declared.

final (constant) variables declaration like this :

final int length=145;

The value of the final variable will be fixed until the program execution.



Literal :

Literal is used for giving the value to a variable of any data type may be string , integer , float etc . Literal is an explicit number or string constant used in Java programs. This specifies the syntax of your declaration of different types of values and operations. . Whenever you want to show the message with java special symbols then you have to use the literals .

Literal declaration like this :

int age = 20 ; // integer literal

float p1 = 3.14f; // float literal

char a = 'A' ; // char literal

String name = "Neha" ; // string literal

Difference between variable , constant & literal is that :

(1) Variables are used for allocating the memory .

(2) Constant(final keyword) is used for giving the fixed value to the variable till the program execution .

(3) Literal is used for giving the value to the variable of any data type .

;)


Related Tutorials/Questions & Answers:
Java - Declaring variables in for loops
Java - Declaring variables in for loops  Java - Declaring variables in for loops
Variables in Java
variables) Java Primitive Data Types Data Type Description... 0.0d In this section, you will learn about Java variables. A variable... when a program executes. The Java contains the following types of variables
Advertisements
Java Substituting Variables
Java Substituting Variables  Java Substituting Variables
Variables In Java
This tutorial demonstrates you about the variables and their types in java
transient variables in java
transient variables in java  hello, What are transient variables in java?   hii, Transient variables are variable that cannot be serialized
Static & Instance variables in java
Static & Instance variables in java  What are the Difference between Static & Instance variables in java
Java Variables - Java Beginners
Java Variables  Hi, I had a small doubt. What are Object Reference variables in java..What actually they do.. And What actually an Object Reference variable will contain? As there are no pointers in Java, what are object
Java Variables - Java Beginners
Java Variables  Hi, I had a small doubt. What are Object Reference variables in java..What actually they do.. And What actually an Object Reference variable will contain? As there are no pointers in Java, what are object
java protected variables
java protected variables   Can we inherit the Java Protected variable..?   of course you can. But I think what you mean is "override"? Is tha so? There are some restriction
instance variables - Java Beginners
instance variables  instance variables
interface variables - Java Beginners
interface variables  why interface variables are final? explain me with good program example?? i knw why the variable is static but,i dont knw why it is final by default? thanks in advance
Variables in Java
Variable in Java In this section you will learn about variables in java. First... values persist. In Java, all variable must be declared first before... identifier = value; This is the basic syntax of declaring variable in java. You
Java Variables Help Please!
Java Variables Help Please!  Hi, I just started with java and i need help with my school project, this is it so far: import java.util.*; public class ProjectCS { public static void main(String[] args) { welcome
interface variables - Java Beginners
interface variables  why interface variable is by default final? what was the necessisity to make it final? plz explain me with good java prog
Variables
Variables  What are the difference between Static variables, instance variables and local variables
Variables in Java
Variables in Java       In this section, you will learn about Java variables... is stored when a program executes. The Java contains the following types of variables
interface variables - Java Interview Questions
interface variables  why interface variables are final? explain me with good program example?? i knw why the variable is static but,i dont knw why it is final by default? thanks in advance..  Hi Friend, The final
Java assignment of variables - JSP-Servlet
Java assignment of variables   .... var strName="Tarunkanti Kar"; .... ... I want to access the script variable in java variable please give the code
take variables in text file and run in java
take variables in text file and run in java  I have a text file which have variables 17 10 23 39 13 33 How to take "17"in java code
java memory allocation for member variables and member functions
java memory allocation for member variables and member functions  ...() and its variables ?? 4>When does java set default values of variables declared...() that has three variables a=5,b=6.My questions are 1>When will the memory be allotted
Jsp Scope Variables - Java Interview Questions
application scope variables in JSP?Am not understanding where which scope.....please, explain me clearly with good java code of each variable..Thanks in advance.  Hi Friend, JSP Scope Variables: Page scope-It makes
How do I set environment variables from Java?
How do I set environment variables from Java?  How do I set environment variables from Java
Passing java variables from JSP to Servlet - return null values
Passing java variables from JSP to Servlet - return null values  I want to pass some variables from a JSP page to a servlet. These variables are from... to get java variables from JSP tp servlet? If there is some error in my code
Environment variables
Environment variables  How to set Environment Variables in JAVA 6 n Tomcat 6 CLASSPATH, JAVA_HOME, PATH, & CATALINA variables plzzz plzz help me
getting variables
getting variables   how to get variables from servlet program to webservice program
What are local variables?
What are local variables?   hi, What are local variables? thanks... a block of syntax like methods. Local variables should be initialised before accessing them. For details related to Local Variables
What is JavaScript Variables ?
What is JavaScript Variables ?  Hi, My question is that What is Variable in JavaScript Programming Language. How to declare variables in JavaScript Program. Thanks
What are instance variables?
What are instance variables?   Hi, What are instance variables... for these non-static variables so we can say that these are related to objects (instances of the class).Hence these variables are also known as instance variables
javascript where to declare variables
variables   Javascript variable always be declared inside script tag... variables in Javascript   JavaScript where to declare variables To declare... = Java; age = 7; document.write(name); document.write("<br>"); document.write
Variables in Smarty
Variables in Smarty Templates Engine for PHP Smarty Template variables...; Object properties and methods, Config file variables Smarty Variables can be declared as: {$new}, {$1212},{$_} Except
Advertisements
 

 

 

DMCA.com