Learning Unit 2 Programming Theory Flashcards
(54 cards)
In Java
Each variable has a data type.
Data types commonly used:
- Integers (whole numbers)
- Real numbers (numbers with decimals)
Important to tell Java what data type a variable will be so
It knows how much space in memory to allocate for each variable.
For input
showInputDialog method of JOptionPane class.
= means
It gets the data or is assigned a value.
Strings
Are enclosed in double quotes.
String is
- A class
- An object
All classes start with
A capital letter.
A variable can be
Joined/concatenated to a text String using a + (plus) sign.
Assignment statement contains
An equals sign.
The subject variable
Has been assigned (or gets) a value.
The value that is assigned
Has been produced (returned) by the showInputDialog method.
The 2 main types of variables used in Java
- Primitive data type
- Object reference
Difference
Objects are stored differently in memory to primitive data types and different behavior.
No real difference between
The way the primitive and objects are declared (must specify type and give variable a name).
Several variables of same type
Can be declared at the same time (use of commas).
After the variable has been declared
It must be initialized.
If you use a variable without initializing
The compiler generates an error.
The only object that can be declared & initialized like primitive types
Because it is so commonly used in programs.
Important to declare variables once
Cannot be 2 boxes in memory with the same identifier.
Ever variable has 3 characteristics:
- Identifier/name
- Data type: Stating what type of data can be stored in it.
- Value that is stored in it.
In a program every variable that is used must be:
- Declared (created) given a identifier and a data type.
- Given a value: This is done using assignment statement.
String data is text data
That cannot have arithmetic calculations carried out on it.
To input numbers
Convert the data from a string to an integer or real type.