=== Some words for IB Comp Sci ===
byte - an 8-bit numerical data type with values between -128 and 127
long - a 64-bit numerical data type with values between -2^63 and +2^63-1
paramater passing
- pass by value : the parameter value is sent into the
method, but changes are not returned
Primitive data types (byte, int,
long, double, char, boolean) are passed by value in Java.
String parameters behave
like pass-by-value, even though a Strings are objects.
- pass by reference : a reference ("pointer")
to the object parameter is sent to the method.
Changes in the reference are not sent back,
but changes in the object also apply in the calling
method/program. This applies to all objects
(unless the object is immutable, like a String).
code BLOCK - any set of code inside {curly braces} . For example, all the code in a class, or the contents of a method, or a loop.
scope - the parts of a program where a variable name is valid
(meaningful, usable). In Java, if you create a variable inside a
loop, its scope is limited to that loop, so you cannot access its value
after the loop ends. Parameters and variables inside a method cannot
be accessed outside that method. The following general rule applies:
The scope of a variable (or
parameter) is all commands following creation in the same
block
where it was created, as well as all
sub-blocks inside that same block.
new - used to create an object. Not needed for primitive data types.
life-time - variables created inside a code block (e.g. method) will "die" (no longer exist) when that block stops executing. This applies to methods, classes, loops, and any other blocks. If you need a variable to persist throughout the program, use a global variable, not a local variable.
garbage-collection - When a variable or object "dies", the memory it occupied is no longer needed and is returned to the Operating System as free memory. Then it can be re-used to store something else.
persistence - if you create a variable inside a method, then
change it's value, and the method stops executing, then when you enter the
method again the old value of the variable will no longer exist.
If a method needs to retain a value between calls, it must use global
variables or some other persistent storage, like storing in another
object or in a file on a disk-drive.
** serialization - allows an entire object to be
stored in a disk-file, providing persistence for the
** state of the object (e.g. saving all the values of all
the variables). This is quite remarkable, as it
** must also save all the referenced objects - e.g. serializing a
linked-list object will automatically
** save the entire linked-list. However, this is not as
reliable as it should be, especially the
** encapsulation (protection) of private references.
This is definitely NOT in the IB syllabus.
dynamic - means "changing". In Java, this refers to
changing the size of a data-structure.
Arrays have a fixed-size (.length), so they are
not dynamic data structures.
Linked-lists and trees can get bigger and bigger by
adding new Nodes, so they are dynamic.
reference - a variable representing an object - it
contains the memory address of the object
dereferencing - use a dot (.) following an object name to access
its methods and data members
Like
: head.data = the data in the first
node in a linked-list
or
Math.round(3.99)
or String.length()
or array.length
chained dereferencing - e.g. in a linked list: head.nextnode.nextnode.data = data in 3rd node
concatenate - join two Strings (or lists) together to make a
longer one.
For Strings, use the plus + sign.
Math.abs = absolute value, like Math.abs(-12) --> 12
Math.pow = power, like Math.pow(2,10) --> 1024
Math.floor = rounds down to the nearest whole number ,
like Math.floor(9.99) --> 9.0
(cast) = change a value to a specific type.
char letter = 'A' ;
int ascii = (int)letter;
--> produces 65, the ASCII code of 'A'
final static PI =
3.1415926;
double simplePi =
Math.floor(PI) ; --> 3.0
int simplerPi =
(int)simplePI;
-->
3
static - a data member (or method) that must remain the same in all objects instantiated from this class. Guarantees that another class cannot override a method. It also guarantees that if a variable value is changed in one object, this affects all other objects of that same class type. Static is NOT the opposite of dynamic in Java. Static does NOT mean unchangeable in Java.
final static - this is used to make CONSTANTS - values that will
NEVER CHANGE.
Like final static int BUS_CAPACITY
= 60;
or final
static double PI = 3.1415926;
public / private -
Public means a data member (variable),
method, or class can be accessed from outside the class.
Private means a data member, method or
class cannot be accessed from outside the class.
encapsulation - actually means two things : (1) packaging data
members and methods together;
(2) hiding (protecting) private data members from
incorrect changes from outside.
inheritance - using extend to make a bigger class from an already existing one, adding more data-members. Inheritance actually refers to keeping all the stuff from the smaller class.
polymorphism - using the same name for multiple different (usually
slightly different) purposes.
Two ways: (1) overriding a method from an inherited class,
and thus changing it; (2) using different signatures for
different versions of a method that require different parameter lists.
In IBIO, output is polymorphic, accepting
various different data types. More importantly, a method like
.toString() exists for many different objects, but must be implemented
differently for each of them.
try{ ... } catch(Exception ex) { .... }
This is the built-in error-trapping construct in Java.
Exception - the general Java term for an error. But in Java, it actually refers to the message produced by the error. This can be decoded and printed (or stored in a log-file), like this:
try
{ ..... }
catch(IOExeption ex)
{ System.out.println(
ex.toString() ); }
throws - a different way to handle errors. This "ignores" the error and passes the exception back to a higher level - e.g. the process that created the current process. For example:
void save(String
filename) throws IOException
{ ... }
Now the method can use file commands without try..catch.. The calling object/method is then required to handle the exception - but this part is not in the IB Syllabus. But you may see throws on the exam - interpret this as "ignore the exception".
loop - a construct that causes the same code to execute over and over again.
boolean expression - an expression that produces either true or false as a result.
boolean condition - a boolean expression that controls a loop or a decision (if..)
sentinel - a data value (like "xxx" at the end of an array) that can cause a loop to stop.
endless/infinite loop - a loop that runs forever, like:
for
(int x = 0; x < 10; x = x+1)
{
System.out.println(x);
x
= x - 1;
}
iterative - repeating, like in a loop
recursive - a method that calls itself. This is not normally used instead of loops, but rather to create branching repetition.
stack overflow -
When a method executes, it must store the return address of the
calling method. This is stored in the system Stack. When
the method ends (exits), the return address is removed from the
stack. But if a recursive method calls itself over and over
again, endlessly, eventually the system stack will get full and produce a
stack overflow exception.