A variable is a placeholder for a value. Variables Variables are used for storing values. In Java, variables need to be defined with a data-type, to define its storage space requirements. The name of the variable must start with a letter, but it may contain numbers within the name. In processing, variable names are case-sensitive.
...
Code Block |
---|
// variable Declaration int x1 = 15; // an integer i.e a whole number float valF = 0.323; // a floating point number i.e a numbers with a decimal point boolean bFlag = false; // a true or false value i.e a single bit value String message = "hallo 1"; // a collection of characters char character = 'g'; // a siglesingle character. Note the different quotation marks String msg1 = new String("hallo 2"); println(x1); println(valF); println(bFlag); println(message); println(character); println(msg1); |
...
Code Block |
---|
int length1 = 150; int length2 = 200; size(300,300); // define window size background(0); // define background colour stroke(255,255,255); // define line colour line(100,10,100,length1); // draw a line line(150,10,150,length2); line(200,10,200,250); fill(0,0,0); // fill colour strokeWeight(5); // line thickness ellipse(100,length1,50,50); // draw an ellipse ellipse(150,length2,50,50); // draw an ellipse noFill(); // turn off fill ellipse(200,250,50,50); // draw an ellipse |
Primitive Data Types and Memory
Each kind of variable (it's data type) has an allocated amount of memory, which is enough to store a particular range of values.
Type | Bytes | Value range |
---|---|---|
byte | 1 byte | -128 to 127 |
short | 2 byte | -32,768 to 32,767 |
int | 4 byte | -2^31 to 2^31-1 |
long | 8 byte | -2^63 to 2^63-1 |
float | 4 byte | -3.4e38 to 3.4e38 |
double | 8 byte | -1.7e308 to 1.7e308 |
boolean | 1 bit | true or false |
char | 2 byte | '\u0000' to '\uffff' |
Operators
An operator is a symbol that tells the computer to perform a particular arithmetic math or logic operation. Some of the most common operators are:
+ Addition
/ DevisionDivision
- Subtraction
* Multiplacation Multiplication
These you already know but there are some very useful arithmetic operators you may not have seen in the following example:
...