Requirements:
Linux Distribution
Java Development Kit (JDK)
Java Runtime Environment (JRE)
A Shell Interface
My Setup:
Debian GNU/Linux
javac
BASH
Variables are pieces of memory which can hold a value. They are used to
describe changing values of a program.
Primitive Types In Java:
- boolean – a variable which represents either the value true
or false. One bit. - char – a variable which represents a unicode character
- byte – a variable which represents an 8-bit signed integer
- short – a variable which represents a 16-bit signed integer
- int – a variable which represents a 32-bit signed integer
- long – a variable which represents a 64-bit signed integer
- float – a variable which represents IEEE 754’s floating
point 32-bit float data type - double -a variable which represents IEEE 754’s floating
point 64-bit double data type
Along with Primitive types, there are non-primitive types.
Non Primitive Types in Java:
- String – a null terminating array of characters that forms words.
(eg. “Hello” is stored as “Hello\0”) - class – a data type which defines a blueprint to create a new data type.
- enum – a special data type used to define collections of constants.
- array – a collection of objects of the same type There are three types of variables when thinking of a java program:
- instance variables – Variables that are used to describe classes. They
are declared within the class and are coupled to the
object. - local variables – Variables that are local are declared within methods
to be used for computation. - static variables – Variables that are labeled static do not require a
class to be instantiated and are coupled to the class
(rather then the object) On top of all these, you have datatype modifiers.
Datatype Modifiers:
- public – visible to the program
- protected – visible to the class and its derived classes
- private – visible only to the class itself
- abstract – a class marked as abstract
- final – a class marked as final can not be extended.
public class variables{
public static void main(String[] args){
int foo; //declares the foo integer .
int bar = 5; //declares and defines the bar integer
foo = 7; //defining the foo character
byte baz = 22;
char c = 'c'; //declaring and defining a character using single quote
String hello = "Hello"; /*declaring and defining a
string using the double quote */
boolean isRunning = true; //defining and declaring a boolean
double pi = 3.14159; //defining a double, the natural floating type variable
float fpi = (float)pi; //defining a float via casting .
}
}