SE 450 Fall 2001/2002

Week 1 Lecture Notes


450 Logistics


Java Architecture


Object-oriented


Platform Independence


Security for Downloaded Code (Applets)


Other features


Obligatory Hello World Program

import java.io.*; public class HelloWorld { public static void main(String[ ] args) { System.out.println("Hello, world"); } }

Comparison with C++


Java syntax vs. C++


Primitive data types


Operators and Control Flows


Reference types


Packages


Code file names


Object-oriented Programming


Java Classes and Objects


Class Declaration

ClassModifiers class ClassName [extends SuperClass] [implements Interfaces] { list of method or variable declarations } Class modifiers:

Methods Declaration

MethodModifiers ReturnType Name (ArgumentList) { body of the method } Method modifiers:

Field Declarations

FieldModifiers Type VarName; Field modifiers:

Java naming conventions


Objects


Examples

Point point1 = new Point(); // no-arg Point point2 = new Point(20, 20);

Example: A Stack class

How would we do this with an array, a linked list??

Example of Reference types

Reference types really are pointers import java.io.*; public class foo { public static void main (String[] s) { test v1 = new test(1), v2; v2 = v1; v2.setint(3); v1.printit(); } } class test { private int x; test(int y) { x = y; } public void printit() { System.out.print(x); } public void setint(int z) { x = z; } }