Java Tutorials
Java Swing Tutorial: How to Create a GUI in Java with Examples
What is Swing in Java? Swing in Java is a Graphical User Interface (GUI) toolkit that includes the GUI...
Variables are used to store values (name = "John") or expressions (sum = x + y).
Before using a variable, you first need to declare it. You have to use the keyword var to declare a variable like this:
var name;
You can assign a value to the variable either while declaring the variable or after declaring the variable.
var name = "John";
OR
var name; name = "John";
Though you can name the variables as you like, it is a good programming practice to give descriptive and meaningful names to the variables. Moreover, variable names should start with a letter and they are case sensitive. Hence the variables student name and studentName are different because the letter n in a name is different (n and N).
Try this yourself:
<html>
<head>
<title>Variables!!!</title>
<script type="text/javascript">
var one = 22;
var two = 3;
var add = one + two;
var minus = one - two;
var multiply = one * two;
var divide = one/two;
document.write("First No: = " + one + "<br />Second No: = " + two + " <br />");
document.write(one + " + " + two + " = " + add + "<br/>");
document.write(one + " - " + two + " = " + minus + "<br/>");
document.write(one + " * " + two + " = " + multiply + "<br/>");
document.write(one + " / " + two + " = " + divide + "<br/>");
</script>
</head>
<body>
</body>
</html>
What is Swing in Java? Swing in Java is a Graphical User Interface (GUI) toolkit that includes the GUI...
Download PDF We have compiled the most frequently asked Java Interview Questions and Answers that...
In this tutorial, we will learn about Generate Random Numbers- Using Java Random Class Using Java...
What is a Prime Number? A prime number is a number that is only divisible by 1 or itself. For...
What is a Build Tool? A build tool is a programming tool which is used to build a new version of a...
What is this Keyword in Java? this keyword in Java is a reference variable that refers to the...