Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content
Previous: Types, Variables, and Scope Next: Arrays

Primitive and Non-Primitive Types

import java.util.Date;
public class DateExample {
public static void main(final String[] args) {
final Date date1 = new Date(); // define a new object date1
final Date date2 = date1; // point date2 to date1
// print both objects
System.out.println(date1);
System.out.println(date2);
// Both objects date1 and date2 refer to the same memory
// Modifying date2 changes date1 as well
date2.setTime(1);
// print both objects
System.out.println(date1);
System.out.println(date2);
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content