answersLogoWhite

0


Best Answer

by the use of constructor . we can initialize the variables in java.The name of the constructor should be same as the name of the class .

User Avatar

Kobe Considine

Lvl 10
1y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago

Assuming you mean declaring a variable dynamically the way you can do with a JavaScript or Ruby eval(), it's not really possible - Java explicitly disallows eval, macros and other constructs that would let you do so.

If you just want some more key/value bindings, you could use a Map, Map keys can be generated at runtime.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

"Initializing" in Java or any other program for that matter is the process of setting a variable to a certain value.

Example:

int x; //Declaration

x = 5; //Initialization

String myString; //Declaration

myString = new String("Hello java initializing"); //Initialization

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

With the assignment, i.e., the equal sign. The variable has to be declared first. Declaration and assignment can be separate:

int x;
...
x = 5;

Or they can be combined:

int x = 5;

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

by the use of constructor . we can initialize the variables in java.The name of the constructor should be same as the name of the class .

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you declare variables during run-time in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Who invoke main function in java?

The Java Runtime Environment invokes main methods.


Will Java runtime environment affect your PC?

Probably not, unless you run a virus written in Java.


What is ther role of jre in java?

JRE stands for Java Runtime Environment. JRE is the runtime set up that is required by the JVM to execute java programs. The JRE and JVM (Java Virtual Machine) come packaged along with the Java Development Kit (JDK) that we download and install from the suns website to install Java.


What translates a Java program into Bytecode?

The Java Runtime Environment (JRE) converts the byte code to machine language.


What are the differences between C and Java reference variables?

Java does not have the concept of Reference Variables. We cannot access the memory location where the data is stored in Java.

Related questions

How do you insert a generated number into an existing variable's name?

Renaming runtime variables is only possible in languages that support dynamic variables. Statically typed languages like Java do not support dynamic variables. However, there's nothing to stop you using a map to associate strings with values at runtime.


What is java's purpose on my PC?

Programs that are specifically designed with Java require a Java runtime to work on a computer. (In the case of Java, the runtime is called "Java Virtual Machine".) If you have any such program, you need to have Java.


Where can one download a java runtime environment?

The java runtime environment can be downloaded from several websites. Among them are Oracle, Java, CNET, Softsonic, Eclipse, AfterDawn, Soft32, and OldApps.


Can i read value in JAVA at runtime?

Yes you can...


Can you use programs in Java under Windows 8.1?

Yes you can but for that you must have have a Java Runtime Environment installed in your computer. Also if you are talking about programming in java then you need to install a Java SDK which can help you in executing your java code and run it. (It also contains Java Runtime Environment).


Why cant you run java on Windows 8?

You may have to install Java runtime support.


Who invoke main function in java?

The Java Runtime Environment invokes main methods.


What will java software do for you on your laptop?

The general Java Runtime Environment allows a computer to run Java applets and compiled Java files.


Will Java runtime environment affect your PC?

Probably not, unless you run a virus written in Java.


What is Java reflection?

java.lang.reflect package has the ability to analyze itself at runtime. This is called Java reflection.


What is ther role of jre in java?

JRE stands for Java Runtime Environment. JRE is the runtime set up that is required by the JVM to execute java programs. The JRE and JVM (Java Virtual Machine) come packaged along with the Java Development Kit (JDK) that we download and install from the suns website to install Java.


What translates a Java program into Bytecode?

The Java Runtime Environment (JRE) converts the byte code to machine language.