Hello world, variables and operators Flashcards
what is the name given to a variable
the identifier
words that cannot be used as variable names
reserved keywords
byte
8 bit signed twos complement integer
default value 0
used to save space in large arrays
short
16 bit sign twos complement integer
min (-2^15)
max (2 ^16)
can also be used to save memory as is two times smaller than an int
int
32 bits
min value (-2^31)
max value(2^32)
default data type unless there is a concern about memory
long
64 bit twos complement integer
default value is 0
float
32 bit floating point default is 0.0f
mainly used to save memory in large arrays of floating point numbers
double
64 bit IEEE 754 floating point
generally default data type used for floating point number values
boolean
1 bit of information
default value is false
char
16 bit is a single 16 bit unicode character
min value is \u0000 or 0
max value is \uffff or 65,535
used to store any character
How are reference variables created
using defined constructors of classes
why are reference variables used
to access objects
Default value of a reference variable
null (as opposed to primitive data types where the default value is 0 which means you can store data with no value).
steps of using a variable
declaration - when the variable is declared
initialisation - when the variable is initially given a value
assignment - when a variable is given assignment at some point after being createed
what is a condition
an expression which can evaluate to true or false
example of a selection statement
a selection statement allows a program to make a decision based on a conditions value
If and switch statements
equality operators
== and !=
relational operators`
> and < and >= and <=
Under the bonnet
java is platform independent - this means it will run on almost any operating system
portability - java must run similarly on any supported hardware/operating system platform
java portability
bytecode - portability achieved by compiling java into an intermediate representation called java bytecode instead of directly to platform specific machine code
bytecode instructions are analogous to machine code, but are interpreted by a JVM (java virtual machine)
compiling and running java
step 1 - developers write the source code which is saved with the file extension .java
step 2 - Javac is used to to turn (compile) the source code into byte code
step 3 - After javac has finished compiling the bytecode, it creates a new file with the extension .class
step 4 - one the class file has been created, it can be passed onto and run on the JVM
compiler vs interpreter
compiler - translates entire source code into machine or intermediate code, then an executor generates the ouput
interpreter - a program which reads one statement at a time and translates it to the machine code or virtual machine code and executes it straight away.
JVM platform independent
there is a jvm for each platform