Java Primer 1: Types, Classes and Operators
Java Primer 1: Types, Classes and Operators
Java Primer 1
Java Primer 1
An Example Program
Java Primer 1
Java Primer 1
Identifiers
q
Java Primer 1
Base Types
q
Java Primer 1
Instance variables, which are also called fields, represent the data
associated with an object of a class. Instance variables must have a type,
which can either be a base type (such as int, float, or double) or any class
type.
Methods in Java are blocks of code that can be called to perform actions.
Methods can accept parameters as arguments, and their behavior may
depend on the object upon which they are invoked and the values of any
parameters that are passed. A method that returns information to the
caller without changing any instance variables is known as an accessor
method, while an update method is one that may change one or more
instance variables when called.
Java Primer 1
Another Example
Java Primer 1
Java Primer 1
Continued Example
Java Primer 1
10
Java Primer 1
11
Wrapper Types
q
Java Primer 1
12
Java Primer 1
13
Signatures
q
Java Primer 1
14
Defining Classes
q
Java Primer 1
15
Java Primer 1
16
Parameters
q
All parameters in Java are passed by value, that is, any time
we pass a parameter to a method, a copy of that parameter is
made for use within the method body.
n
n
n
Java Primer 1
17
2.
3.
Java Primer 1
18
Java Primer 1
19
Arithmetic Operators
q
Java Primer 1
20
Java Primer 1
21
Logical Operators
q
Java Primer 1
22
Bitwise Operators
q
Java Primer 1
23
Operator Precedence
Java Primer 1
24
Casting
Casting is an operation that allows us to
change the type of a value.
q We can take a value of one type and
cast it into an equivalent value of
another type.
q There are two forms of casting in Java:
explicit casting and implicit casting.
q
Java Primer 1
25
Explicit Casting
q
Java Primer 1
26
Implicit Casting
q
Java Primer 1
27