println and print
The println and print methods are used for providing simple output. Concatenate
(combine) values into strings using +. print displays the text then leaves the cursor
at the end of the text, whereas println starts a new line after
Methods that Return a Value (non-void)
Non void methods return a single value.
Methods that return a value are called functions in some programming
The result produced is substituted in place of the method call as if it was a
value of the metho
Introduction to Methods
Methods contain instructions to perform an operation.
Examples of methods are: println, round and nextInt.
To execute a method we say we call the method.
Methods are called using their class name or object name e.g.
A method header shows details about how the method can be used. It specifies
whether the method is static or not, the return type (or void), the method name, and
parameters (data type and name) if any. The method name should be descriptive
Operator Precedence (so far)
Operator precedence refers to the order that operators are evaluated in an
Operators of equal precedence are evaluated from left to right.
Brackets (Parenthesis) can be used to change the order of precedence of
Assume x is 7 in the following examples.
Negative e.g. -12
Floating point Division (one or both of the values are doubles e.g. 10 / 2.3)
Integer division (both values are
Most of the methods we have looked at so far are static methods.
The Math class has many useful methods used for calculating things such as:
square roots, raising numbers to a power, rounding, absolute values,
minimum and maximum
To save reinventing the wheel, Java provides a huge code library: the Java
API (Application Programmer Interface). The Java API is organised
into packages which contain groups of related classes. For convenience Java
automatically imports m
Primitive types are very simple data types.
Examples of primitive types are: int, double, char and boolean.
Primitive types don't have any operations (methods) or constants associated
with them, and are stored as a simple data v