Click to Play

SEO And The Year Ahead
Whether or not you're ready, next year is almost here, and this December-to-January transition point is always a convenient time to consider the direction things...

Recent Articles

Understanding The Java Trade Offs Between...
Java is a common programming language and the basic purpose of Java is to develop network programs. Now it is also used to develop system software's and programs too. The Java architecture has trade off...

Learning To Use The Java Sandboxn
The sandbox allows code to be downloaded from any source,but applies restriction on it upon execution. You can also say sandbox isolates particular code during execution to apply the restrictions.

Creating And Using Java Threadsn
Multi threaded applications are the base of all modern computing applications. Threads save lot of time and keeps utilizing computing resources to the optimum levels. It is important for a Java developer...

How To Accurately Test Your Java Speed And Precision
I don't think you need to compute your program execution time everytime you execute your program but sometimes when you need to compare performance then it becomes necessary to compute the...

Starting System Processes Through JAVA Exec...
Java is capable of executing threads by starting and running them. Java Programming language also provides you with the ability to start the heavyweight...


01.05.10



Initializing Your Java Dynamically Using Any Expression

By Vaibhav Pandey

There are two types of variable mainly:-

1. Instance Variable or Class Variable
2. Local Variable or method variable

Instance variable are initialized by JVM to their default values if not defined explicitly. Whereas the local variables needs to be defined each time time they are declared. But the local variables can be used to a greater effect by using the concept of dynamic initialization.

Dynamic Initialization can be defined as the dynamic operation that allows variables to be initialized dynamically using any expression valid at the time of the variable declaration.

Above definition implies that if you need a variable to store value of an expression you can use dynamic initialization. In which value of an expression is assigned to a variable.

Dynamic Initialization can be clear by understanding following example:-

class DynamicInit{
public static void main(String a[]){
int a=2;
int b=5;
int c=a*a+b*b;
System. out. println("value of c is "+c);
}
}


Output :-The output of above program is
value of c is 29

In the above program we have three variables a,b and c. Each has been declared as ' int '. Variable a and b are declared and provided values on declaration whereas the variable c has been assigned a expression to evaluate and store its value. This is done through dynamic evaluation.

NOTE:-One thing which has to be remembered is that the initialization expression may use any program construct including method calls, instance variables, literals etc.

Comments


About the Author:
Vaibhav Pandey got offered employment from an Indian Multinational IT Company. He is 21 years old. He has a huge interest in Java programming and has liked it from his study days. Vaibhav loves to blog and share his experiences and thoughts. He now resides in Lucknow, a state capital in India. Check out his blog at http://javatutorialsworld.blogspot.com.
About JavaProNews
JavaProNews is a collection of news and commentary designed to keep you in step with the ever evolving landscape of Java environments. News and Advice for Java Professionals





JavaProNews is brought to you by:

SecurityConfig.com NetworkingFiles.com
NetworkNewz.com WebProASP.com
DatabaseProNews.com SQLProNews.com
ITcertificationNews.com SysAdminNews.com
LinuxProNews.com WirelessProNews.com
CProgrammingTrends.com ITmanagmentNews.com





-- JavaProNews is an iEntry, Inc. publication --
iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509
2010 iEntry, Inc. All Rights Reserved Privacy Policy Legal

archives | advertising info | news headlines | free newsletters | comments/feedback | submit article