+91 81900 98289

Java Variables

A variable is a named place that holds one value. You declare the type once, then assign with =. Java does not let you put text into an int, and it does not let you use a local variable before it has a value.

Names start with a letter. Use batchSize, not batch size, and not 2ndBatch. The usual style for a variable is lower camel case: first word lower, each next word capitalized.

Example

course holds text. learners holds a whole number. The two + operators join them into one printed line.

public class Variables { public static void main(String[] args) { String course = "Java"; int learners = 18; System.out.println(course + " " + learners); } }
Declare a variable close to the first line that uses it. A long list of empty declarations at the top of main is harder to read.