0% found this document useful (0 votes)
38 views19 pages

04 JavaBase PDF

Uploaded by

shahab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views19 pages

04 JavaBase PDF

Uploaded by

shahab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

26/03/2009

Comments
 C-style comments (multi-lines)
/* this comment is so long
that it needs two lines */
Java (basic concepts)
 Comments on a single line
// comment on one line

Version 3 - March 2009

Politecnico di Torino 2

Code blocks and Scope Control statements


 Java code blocks are the same as in C  Same as C
language
if-else,
 Each block is enclosed by braces { } and
starts a new scope for the variables switch,
 Variables can be declared both at the while,
beginning and in the middle of block code do-while,
for (int i=0; i<10; i++){
int x = 12; for,
... break,
int y;
... continue
}

Politecnico di Torino 3 Politecnico di Torino 4

Boolean Passing parameters


 Java has an explicit type (boolean) to  Parameters are always passed by value
represent logic values (true, false)
 ...they can be primitive types or object
 Conditional constructs evaluate references
boolean conditions
Note well - It‟s not possible to evaluate
this condition  Note well: only the object reference is
int x = 7; if(x){…} //NO copied not the value of the object
Use relational operators
if (x != 0)

Politecnico di Torino 5 Politecnico di Torino 6

1
26/03/2009

Constants Elements in a OO program


 The final modifier Structural elements Dynamic elements
final float PI = 3.14; (types) (data)
(compile time) (run time)
PI = 16.0; // ERROR, no changes
final int SIZE; // ERROR, init missing  Class  Reference
 Primitive type  Variable
 Use uppercases (coding conventions)

Politecnico di Torino 7 Politecnico di Torino 8

Classes and primitive types Primitive type


 Defined in the language:
 Class descriptor  type primitive
int, double, boolean
class Exam {} int, char,
float  Instance declaration: int i;
Declares instance name
 Variable of type
0

reference  Variable of type Declares the type


Exam e;
instance
primitive Allocates memory space for the reference
e = new Exam(); int i;

Politecnico di Torino 9 Politecnico di Torino 10

Class
 Defined by developer (eg, Exam) or by the Java
environment (eg, String)
 the following declaration

Exam e; e null
Primitive types
 …allocates memory space for the reference
(„pointer‟)
…and sometimes it initializes it with null by default
 Allocation and initialization of the object value are
made later by its constructor
Object
e 0Xffe1
e = new Exam(); Exam

Politecnico di Torino 11

2
26/03/2009

Primitive types Constants


 Have a unique dimension and encoding  Constants of type int, float, char,
Representation is platform-independent strings follow C syntax
123 256789L 0xff34 123.75
type Dimension Encoding
0.12375e+3
boolean 1 bit -
char 16 bits Unicode ‟a‟ ‟%‟ ‟\n‟ ”prova” ”prova\n”
byte 8 bits Signed integer 2C
short 16 bits Signed integer 2C  Boolean constants (do not exist in C)
int 32 bits Signed integer 2C are
long 64 bits Signed integer 2C
float 32 bits IEEE 754 sp true, false
double 64 bits IEEE 754 dp
void - -

Politecnico di Torino 13 Politecnico di Torino 14

Operators (integer and floating-point) Logical operators


 Operators follow C syntax:  Logical operators follows C syntax:
arithmetical + - * / % && || ! ^
relational == != > < >= <=  Note well: Logical operators work
bitwise (int) & | ^ << >> ~ ONLY on booleans
Assignment = += -= *= /= Type int is NOT considered a boolean
%= &= |= ^= value like in C
Increment ++ -- Relational operators work with boolean
 Chars are considered like integers values
(e.g. switch)

Politecnico di Torino 15 Politecnico di Torino 16

Class
 Object descriptor
 It consists of attributes and methods

Classes

Politecnico di Torino 18

3
26/03/2009

Class - definition Methods


class Car {
String color; Name  Methods are the messages that an
String brand;
boolean turnedOn; Attributes
Car
object can accept
color
void turnOn() { brand turnOn
turnedOn = true; turnedOn
}
turnOn
paint
void paint (String newCol) {Methods
color = newCol;
paint
printState
printState
}
void printState () {
 Method may have parameters
System.out.println(“Car “ + brand + “ “ + color); paint(“Red”)
System.out.println(“the engine is”
+(turnedOn:”on”:”off”));
}
}

Politecnico di Torino 19 Politecnico di Torino 20

Overloading Overloading
 In a Class there may be  public class Foo{
different methods with class Car { public void doIt(int x, long c){
the same name String color; System.out.println("a");
 But they have a void paint(){
}
different signature color = “white”;
public void doIt(long x, int c){
 A signature is made System.out.println("b");
} }
by: void paint(int i){} public static void main(String args[]){
Method name
void paint(String Foo f = new Foo();
Ordered list of
parameters types newCol){ f.doIt( 5 ,(long)7 ); // “a”
color = newCol; f.doIt( (long)5 , 7 ); // “b”
 the method whose }
parameters types list }
matches, is then } }
executed
Politecnico di Torino 21 Politecnico di Torino 22

Objects Objects
class Car {
 An object is identified by: String color;
Its class, which defines its structure void paint(){
(attributes and methods) color = “white”;
}
Its state (attributes values) void paint(String newCol) {
An internal unique identifier color = newCol;
}
 Zero, one or more reference can point }
to the same object Car a1, a2;
a1 = new Car();
a1.paint(“green”);
a2 = new Car();

Politecnico di Torino 23 Politecnico di Torino 24

4
26/03/2009

Objects and references Objects Creation


Car a1, a2; // a1 and a2 are uninitialized
a1 = new Car();  Creation of an object is made with the
a1.paint(“yellow”);// Car “yellow” generated, keyword new
// a1 is a reference pointing to “yellow”
a2 = a1; //now two references point to “yellow”  It returns a reference to the piece of
a2 = null; // a reference points to “yellow” memory containing the created object
a1 = null;// no more references point to “yellow”
// Object exists but it is no more reachable
// then it will be freed by Motorcycle m = new Motorcycle();
// the garbage collector

 Note Well: a reference IS NOT an object

Politecnico di Torino 25 Politecnico di Torino 26

The keyword new Heap


 Creates a new instance of the specific Class,  It is a part of the memory used by an
and it allocates the necessary memory in executing program…
the heap  …to store data dynamically created at run-
 Calls the constructor method of the object time
(a method without return type and with the
same name of the Class)
 C: malloc, calloc and free
 Returns a reference to the new object Instances of types in static memory or in heap
created
 Java: new
 Constructor can have parameters Instances (Objects) are always in the heap
String s = new String(“ABC”);

Politecnico di Torino 27 Politecnico di Torino 28

Constructor Constructors with overloading


 Constructor method contains operations class Window {
String title;
(initialization of attributes etc.) we want to String color;
execute on each object as soon as it is Window() {
// creates a window with no title and no
created color
 Attributes are always initialized }
Window(String t) {
Attributes are initialized with default values // creates a window with title but no color
...
 If a Constructor is not declared, a default title = t;
one (with no parameters) is defined }
Window(String t, String c) {
 Overloading of constructors is often used // creates a window with title and color...
title = t;
color = c;
}}
Politecnico di Torino 29 Politecnico di Torino 30

5
26/03/2009

Destruction of objects Methods invocation


 It is no longer a programmer concern  A method is invoked using dotted
 See section on Memory management notation
 Before the object is really destroyed if objectReference.Method(parameters)
exists method finalize is invoked:
public void finalize()  Example:

Car a = new Car();


a.turnOn();
a.paint(“Blue”);

Politecnico di Torino 31 Politecnico di Torino 32

Caveat Caveat (cont‟d)


 If a method is invoked within another  In such cases this is implied
method of the same object  “this” is a reference to the current object
DO NOT need to use dotted notation class Book {
class Book { int pages;
int pages; void readPage(int n){…}
void readPage(int n) void readAll() {
{… } for(…)
void readAll() {
readPage(i);
for (int i=0; i<pages; i++) void readAll() {
readPage(i); }
for(…)
} }
this.readPage(i);
}
}

Politecnico di Torino 33 Politecnico di Torino 34

Access to attributes Access to attributes


 Dotted notation  Methods accessing attributes of the
objectReference.attribute same object do not need using object
Reference is used like a normal variable reference
class Car {
String color;
Car a = new Car();
a.color = “Blue”; //what‟s wrong here? void paint(){
boolean x = a.turnedOn; color = “green”;
// color refers to current obj
}
}

Politecnico di Torino 35 Politecnico di Torino 36

6
26/03/2009

this Combining dotted notations


 It can be useful in methods to distinguish  Dotted notations can be combined
object attributes from local variables System.out.println(“Hello world!”);
this represents a reference to the current object

System is a Class in package java.lang


class Car{ Out is a (static) attribute of System referencing
String color; an object of type PrintStream (representing the
... standard output)
void paint (String color) { Println() is a method of PrintStream which
this.color = color; prints a text line on the screen
}
}

Politecnico di Torino 37 Politecnico di Torino 38

Operations on references
 Only the relational operators == and != are
defined
Note well: the equality condition is evaluated on
the values of the references and NOT on the
values of the objects ! Strings
The relational operators tell you whether the
references points to the same object in memory
 Dotted notation is applicable to object
references
 There is NO pointer arithmetic

Politecnico di Torino 39

String Operator +
 No primitive type to represent string  It is used to concatenate 2 strings
 String literal is a quoted text “This string” + ” is made by two strings”
C
char s[] = “literal”  Works also with other types
Equivalence between string and char (automatically converted to string)
arrays
System.out.println(”pi = ” + 3.14);
 Java System.out.println(”x = ” + x);
char[] != String
String class in java.lang library

Politecnico di Torino 41 Politecnico di Torino 43

7
26/03/2009

String String
 String valueOf(int)
 int length() Converts int in a String – available for all primitive
returns string length types
 boolean equals(String s)  String toUpperCase()
compares the values of 2 strings  String toLowerCase()
String s1, s2;
s1 = new String(“First string”);
 String concat(String str) - like ‘+’
s2 = new String(“First string”);  int compareTo(String str)
System.out.println(s1);
Compare w.r.t alphabetical order
System.out.println(“Length of s1 = ” +
s1.length()); <0 if this < str
if (s1.equals(s2)) // true ==0 if this == str
if (s1 == s2) // false
>0 if this > str
Politecnico di Torino 44 Politecnico di Torino 45

String StringBuffer
 String subString(int startIndex)
String s = “Human”;
 insert
s.subString(2) returns “man”  append
 String subString(int start, int end)  delete
Char „start‟ included, „end‟ excluded
 reverse
String s = “Greatest”;
s.subString(0,5) returns “Great”
 int indexOf(String str)
Returns the index of the first occurrence of str
 int lastIndexOf(String str)
The same as before but search starts from the end
Politecnico di Torino 46 Politecnico di Torino 47

Character
 Utility methods on the kind of char
isLetter(), isDigit(),
isSpaceChar()
 Utility methods for conversions Scope and encapsulation
toUpper(), toLower()

Politecnico di Torino 48

8
26/03/2009

Example Example (cont‟d)


 Laundry machine, design1  Washing machine, design3
commands: command:
time, temperature, amount of soap Wash!
Different values depending if you wash insert clothes, and the washing machine
cotton or wool, …. automatically select the correct program
 Laundry machine, design2
commands:  Hence, there are different solutions
key C for cotton, W for wool, Key D for with different level of granularity /
knitted robes
abstraction

Politecnico di Torino 50 Politecnico di Torino 51

Motivation Scope and Syntax


 Modularity = cut-down inter-components  private (applied to attribute or method)
interaction attribute/method visible by instances of the
 Info hiding = identifying and delegating same class
responsibilities to components  public
components = Classes
attribute / method visible everywhere
interaction = read/write attributes
interaction = calling a method
 protected
attribute / method visible by instance of the
 Heuristics
same class and sub-classes
attributes invisible outside the Class
Visible methods are the ones that can be  Forth type (later)
invoked from outside the Class

Politecnico di Torino 52 Politecnico di Torino 53

Info hiding Info hiding


class Car {
public String color; class Car{
} private String color;
Car a = new Car();
public void paint(); no
a.color = “white”; // ok
class Car { } yes
private String color;
class B {
public void paint(String color)
{this.color = color;} public void f1(){
} ...
Car a = new Car();
better };
a.color = “white”; // error
a.paint(“green”); // ok }

Politecnico di Torino 54 Politecnico di Torino 55

9
26/03/2009

Access Getters and setters


Method in the Method of  Methods used to read/write a private
same class another class attribute
 Allow to better control in a single
Private yes no
point each write access to a private
(attribute/
field
method) public String getColor() {
return color;
Public yes yes }
public void setColor(String newColor) {
color = newColor;
}

Politecnico di Torino 56 Politecnico di Torino 57

Example without getter/setter Example without getter/setter


public class Student { class StudentExample {
public String first; public static void main(String[] args) {
// defines a student and her exams
public String last;
// lists all student‟s exams
public int id; Student s=new Student(“Alice",“Green",1234);
public Student(…){…} Exam e = new Exam(30);
} e.student = s;
// print vote
public class Exam { System.out.println(e.grade);
public int grade; // print student
public Student student; System.out.println(e.student.last);
public Exam(…){…} }
} }

Politecnico di Torino 58 Politecnico di Torino 59

Example with getter/setter Example with getter/setter


class StudentExample { public class Student {
public static void main(String[] args) {
Student s = new Student(“Alice”, “Green”, private String first;
1234); private String last;
Exam e = new Exam(30); private int id;
public String toString() {
e.setStudent(s);
// prints its values and asks students to return first + " " +
// print their data last + " " +
e.print(); id;
} }
} }

Politecnico di Torino 60 Politecnico di Torino 61

10
26/03/2009

Example with getter/setter


public class Exam {
private int grade;
private Student student;
public void print() {
System.out.println(“Student ” +
Array
student.toString() + “got ” + grade);
}
public void setStudent(Student s) {
this.student =s;
}
}

Politecnico di Torino 62

Array Array declaration


 An array is an ordered sequence of  An array reference can be declared
variables of the same type which are with one of these equivalent syntaxes
accessed through an index int[] a;
int a[];
 Can contain both primitive types or
object references (but no object  In Java an array is an Object and it is
values) stored in the heap
 Array dimension can be defined at  Array declaration allocates memory
run-time, during object creation space for a reference, whose default
value is null
(cannot change afterwards) a null

Politecnico di Torino 64 Politecnico di Torino 65

Array creation Example - primitive types


 Using the new operator… a heap
int[] a; null
int[] a;
a = new int[10];
String[] s = new String[5];
a heap
a = new int[6];
 …or using static initialization,
0
0
0

filling the array with values


0
0
0

int[] primes = {2,3,5,7,11,13}; primes heap


Person[] p = { new Person(“John”), int[] primes = 2
new Person(“Susan”) }; 3
{2,3,5,7,11,13}; 5
7
11
13

Politecnico di Torino 66 Politecnico di Torino 67

11
26/03/2009

Example - object references Operations on arrays


String[] s = new
s heap
 Elements are selected with brackets [ ]
(C-like)
null
String[6]; null
null
null

But Java makes bounds checking


null
null

s heap
s[1] = new null
String(“abcd”); null “abcd”
 Array length (number of elements) is
null

given by attribute length


null
null

Person[] p =
{new Person(“John”) , p heap for (int i=0; i < a.length; i++)
new Person(“Susan”)}; John a[i] = i;
Susan

Politecnico di Torino 68 Politecnico di Torino 69

Operations on arrays For each


 An array reference is not a pointer to  New loop construct:
the first element of the array for( Type var : set_expression )
 It is a pointer to the array object Notation very compact
set_expression can be
either an array
 Arithmetic on pointers does not exist
a class implementing Iterable
in Java
The compiler can generate automatically
loop with correct indexes
Thus less error prone

Politecnico di Torino 70 Politecnico di Torino 71

For each - example Homework


 Example:  Create an object representing an
for(String arg: args){ ordered list of integer numbers (at
//... most 100)
}
is equivalent to
 print()
for(int i=0; i<args.length;++i){
prints current list
String arg= args[i];
//...
 add(int) and add(int[])
} Adds the new number(s) to the list

Politecnico di Torino 72 Politecnico di Torino 73

12
26/03/2009

Multidimensional array Rows and columns


 Implemented as array of arrays  As rows are not stored in adjacent
positions in memory they can be
Person[][] table = new Person[2][3]; easily exchanged
table[0][2] = new Person(“Mary”);

double[][] balance = new double[5][6];


table heap table[0][2] ...
null double[] temp = balance[i];
null
null
null
“Mary”
balance[i] = balance[j];
table[0]
null balance[j] = temp;

Politecnico di Torino 74 Politecnico di Torino 75

Rows with different length Tartaglia‟s triangle


 A matrix (bidimen-sional array) is  Write an application printing out the
indeed an array of arrays following Tartaglia‟s triangle
1
int[][] triangle = new int[3][]
triangle 1 1
null
null
null
1 2 1
heap 4=3+1
1 3 3 1
for (int i=0; i< triangle.length; i++)
1 4 6 4 1
triangle[i] = new int[i+1];
triangle 1 5 10 10 5 1
0
0
1 6 15 20 15 6 1
0 0
0
0

Politecnico di Torino 76 Politecnico di Torino 77

Motivation
 Class is a better element of
modularization than a procedure
 But it is still little
Package
 For the sake of organization, Java
provides the package feature

Politecnico di Torino 79

13
26/03/2009

Package Package name


 A package is a logic set of class definitions  A package is identified by a name with
 These classes are made of several files, all a hierarchic structure (fully qualified
stored in the same directory name)
E.g. java.lang (String, System, …)
 Each package defines a new scope (i.e., it
puts bounds to visibility of names)
 Conventions to create unique names
Internet name in reverse order
 It‟s then possible to use same class names
in different package without name-conflicts it.polito.myPackage

Politecnico di Torino 80 Politecnico di Torino 81

Example Creation and usage


 java.awt  Creation:
Window Package statement at the beginning of
Button each class file
Menu package packageName;
 Usage:
 java.awt.event (sub-package) Import statement at the beginning of
class file (where needed)
MouseEvent Import
single
import packageName.className; class
KeyEvent import java.awt.*; (class name
Import all is in scope)
classes but
not the sub
packages

Politecnico di Torino 82 Politecnico di Torino 83

Access to a class in a package Package and scope


 Referring to a method/class of a package  Scope rules also apply to packages
int i = myPackage.Console.readInt()  The “interface” of a package is the set of
public classes contained in the package
 If two packages define a class with the
same name, they cannot be both imported  Hints
 If you need both classes you have to use Consider a package as an entity of
one of them with its fully-qualified name: modularization
import java.sql.Date; Minimize the number of classes, attributes,
Date d1; // java.sql.Date methods visible outside the package
java.util.Date d2 = new java.util.Date();

Politecnico di Torino 84 Politecnico di Torino 85

14
26/03/2009

Package visibility Visibility w/ multiple packages


 public class A { }
Package P
Public methods/attributes of A are visible
class A { outside the package
public int a1; class B {
public int a3;
private int a2; yes
 class B { }
public void f1(){} private int
no a4; No method/attribute of B is visible
outside the package
}
}

Politecnico di Torino 86 Politecnico di Torino 87

Multiple packages Multiple packages


Package P Package P

class A { class B { public class A { class B {


public int a1; public int a3; public int a1; public int a3;
private int a2; private int a4; private int a2; private int a4;
public void f1(){} } public void f1(){} }
} }

no no yes no
Package Q Package Q

class C { class C {
public void f2(){} public void f2(){}
} }

Politecnico di Torino 88 Politecnico di Torino 89

Access rules
Method in the Method of other Method of other
same class class in the same class in other

Private attribute/ Yes


package
No
package
No
Static attributes and
method
methods
Package attribute / Yes Yes No
method
Public attribute / Yes Yes No
method on
package class
Public attribute / Yes Yes Yes
method on public
class

Politecnico di Torino 90

15
26/03/2009

Class variables Static methods


 Represent properties which are common to  Static methods are not related to any
all instances of an object instance
 But they exist even when no object has  They are defined with the static modifier
been instantiated  Access: ClassName.method()
 They are defined with the static modifier
 Access: ClassName.attribute class HelloWorld {
public static void main (String args[]) {
class Car { System.out.println(“Hello World!”);
static int numberOfWheels = 4; }
} }
double y = Math.cos(x); // static method
int y = Car.numberOfWheels;

Politecnico di Torino 92 Politecnico di Torino 93

Enum Enum
 Defines an enumerative type  Enum can be declared outside or inside a class,
public enum Suits { but NOT within a method
SPADES, HEARTS, DIAMONDS, CLUBS  Enums are not Strings or ints, but more like a
} kind of class but constructor can‟t be invoked
 Variables of enum types can assume directly, conceptually like this:
only one of the enumerated values
class Suits {
Suits card = Suits.HEARTS;
public static final Suits HEARTS= new Suits (“HEARTS”,0);
 They allow much more strict static public static final Suits DIAMONDS= new Suits (“DIAMONDS”,1);
checking compared to integer
constants (used e.g. in C) public static final Suits CLUBS= new Suits (“CLUBS”, 2);
public static final Suits SPADES= new Suits (“SPADES”, 3);
public Suits (String enumName, int index) {…}
}
Politecnico di Torino 94 Politecnico di Torino 95

Motivation
 In an ideal OO world, there are only
classes and objects
Wrapper classes for  For the sake of efficiency, Java use
built-in types primitive types (int, float, etc.)

 Wrapper classes are object versions of


the primitive types
 They define conversion operations
between different types

Politecnico di Torino 97

16
26/03/2009

Wrapper Classes Conversions


Defined in java.lang package
Integer
Primitive type Wrapper Class
boolean Boolean Integer.valueOf(s)
intValue() new Integer(i) toString() new Integer(“33”)
char Character
byte Byte
short Short iint String
int Integer
long Long
float Float Integer.parseInt(“33”)

double Double String.valueOf(33)


void Void +

Politecnico di Torino 98 Politecnico di Torino 99

Example Autoboxing
Integer obj = new Integer(88);  In Java 5 an automatic conversion
String s = obj.toString(); between primitive types and wrapper
int i = obj.intValue(); classes (autoboxing) is performed.
Integer i= new Integer(2); int j;
j = i + 5;
int j = Integer.parseInt(“99”); //instead of:
int k = (new Integer(99)).intValue(); j = i.intValue()+5;
i = j + 2;
//instead of:
i = new Integer(j+2);
Politecnico di Torino 100 Politecnico di Torino 101

Variable arguments Variable arguments - example


 It is possible to pass a variable number static void plst(String pre, Object...args){
of arguments to a method using the System.out.print(pre);
for(Object o:args){
varargs notation if(o!=args[0]) System.out.print(", ");
method( Object ... args ) System.out.print(o);

 The compiler assembles an Object }


System.out.println();
array that can be used to scan the }
passed parameters public static void main(String[] args) {
plst("List:","A",'b',123, “ciao”);
}

Politecnico di Torino 102 Politecnico di Torino 103

17
26/03/2009

Memory types
Depending on the kind of elements they
include:
 Static memory
Memory management elements living for all the execution of a
program (class definitions, static variables)
 Heap (dynamic memory)
elements created at run-time (with „new‟)
 Stack
elements created in a code block (local
variables and method parameters)

Politecnico di Torino 105

Objects are stored in the heap Types of variables


heap code  Instance variables (or fields or
Object
attributes)
reference
State
Stored within objects (in the heap)
 Local Variables
Stored in the Stack
 Static Variables
Stored in static memory

Politecnico di Torino 106 Politecnico di Torino 107

Instance Variables Local Variables


 Declared within a Class (attributes)  Declared within a method or a code block
Class Window {
 Stored in the stack
boolean visible;  Created at the beginning of the code block
… where they are declared
Window1
heap  Automatically destroyed at the end of the
code block
Window2
visible
visible

Class Window {
 There is a different copy in each instance of …
the Class void resize () {
int i;
 Create/initialized whenever a new instance for (i=0; i<5; i++) { … }
of a Class is created } // here i is destroyed

Politecnico di Torino 108 Politecnico di Torino 109

18
26/03/2009

Static Variables Static variables in memory


 Declared in classes or methods with static
modifier
Static area
Class ColorWindow { ColorWindow
heap
static String color; color
… ColorWindow1

 Only ONE copy is stored in static memory ColorWindow2

associated to a Class => also called Class


variables

 Created/initialized during Class-loading in


memory

Politecnico di Torino 110 Politecnico di Torino 111

Object destruction Garbage collector


 Is a component of the JVM that has to
 It‟s not made explicitely but it is made clean heap memory from „dead‟
by the JVM when there are no more objects
references to the object
 After a period of time it analyzes
Programmer must not worry about references and objects in memory
objects destruction
 ...and then it deallocates objects with
no active references

Politecnico di Torino 112 Politecnico di Torino 113

19

You might also like