Presentation is loading. Please wait.

Presentation is loading. Please wait.

UMass Lowell Computer Science 91.460 Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 6 Java Fundamentals Mon. 9/18/00.

Similar presentations


Presentation on theme: "UMass Lowell Computer Science 91.460 Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 6 Java Fundamentals Mon. 9/18/00."— Presentation transcript:

1 UMass Lowell Computer Science 91.460 Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 6 Java Fundamentals Mon. 9/18/00

2 Homework #1, Part 2 Due at the start of lecture today: electronic code submission electronic code submission paper printout paper printout Note: When testing an applet in the UML CS UNIX environment, be sure to set the UNIX DISPLAY environment variable appropriately. Note: If you want to use Swing on HW#1 in UML CS UNIX environment, use the Java version located in: /usr/opt/java122/bin /usr/opt/java122/bin/javac /usr/opt/java122/bin/javac /usr/opt/java122/bin/java /usr/opt/java122/bin/java Entire class will transition to this Java version starting with HW#2. Entire class will transition to this Java version starting with HW#2. This Java version is on the saturn CS machine.This Java version is on the saturn CS machine. If you are using a workstation (not just an X-terminal), remotely log into saturn so you can access the Java version on saturn. Otherwise, you will default to the Java version that is on that workstation. If you are using a workstation (not just an X-terminal), remotely log into saturn so you can access the Java version on saturn. Otherwise, you will default to the Java version that is on that workstation.

3 Homework #2 1 Fri, 9/8 Fri, 9/15 Part 1 Mon, 9/18 Part 2 Mon, 9/18 Part 2 2Fri, 9/15 Fri, 9/22 Part 1 & Part 2 HW# Assigned Due Content Homework is due at the start of lecture on the due date.

4 C to C++ to Java: At a Glance C Primitive Data Types Arrays Struct, Union, Enum Preprocessor Directives OperatorsExpressions Control Statements FunctionsPointers Dynamic Memory Mgt File I/O Exception Handling JavaC++ Primitive Data Types Arrays Struct, Union, Enum Preprocessor Directives OperatorsExpressions Control Statements FunctionsPointers Dynamic Memory Mgt File I/O Exception Handling Classes Multiple Inheritance PolymorphismTemplates uu Primitive Data Types Arrays OperatorsExpressions Control Statements Dynamic Memory Mgt File I/O Exception Handling Classes, Interfaces Single Inheritance Polymorphism Support for DBs, networks, GUIs, events, graphics, threads, libraries Procedural, Compiled Language Procedural/OO, Compiled Language OO, Interpreted Language

5 Java Variables ä Two types: ä primitive data type variable (a.k.a. variable) ä always “passed-by-value” (i.e. “call-by-value”) ä value of argument is copied ä initialized by default to 0 if numeric; false if boolean ä except for local variables ä value is constant if final keyword is used ä reference variable (a.k.a. reference) ä refers to memory location of object ä reference variable itself is always “passed-by-value” ä method can use reference to manipulate object directly ä initialized by default to null

6 Java Primitive Data Types

7 Java Array Class ä Declarations: ä One-dimensional: ä int c [ ]; c = new int [8]; ä int c [ ] = new int [8]; ä final int ARRAY_SIZE = 8; int c [ ] = new int [ARRAY_SIZE]; ä int c [ ] = { 32, 44, 6, 7, -1, 25, 88, -31 }; ä Multi-dimensional (e.g. 2): ä int c[ ][ ] = { {32, 44, 6, 7 }, {-1, 25, 88, -31} }; ä int c[ ][ ] = new int[2][4]; ä int c[ ][ ] = new int[2][ ]; // allocate rows for non-rectangular array ä c[0] = new int[3]; // allocate columns for row 0 ä c[1] = new int[4]; // allocate columns for row 1 ä Knows its own length! (e.g. c.length) ä Bounds are checked for you!

8 Java String Class (basics) ä String is a series of characters treated as a single unit ä Declarations and Constructors: ä String s; // empty string for now -- its length is 0 ä s = new String(); // String() is null constructor. It yields an empty // string for now whose length is 0 ä s = new String(“hello”); // initializes s to “hello” ä String s = “hello”; // initializes s to “hello” ä s2 = new String (s1); // copy constructor ä String s = “hello” + “ world”; // String concatenation ä s1.equals (s2); // tests equality of contents ä s1 = = s2 // tests if both refer to same object in memory ä Knows its own length! (e.g. s.length) ä Array of Strings: String Pets[ ] = {“dog”, “cat”, “fish”};

9 Some Java Operators [Deitel, p. 271; complete list is in Appendix C] Precedence: Operator higher up the chart is evaluated before operator lower down the chart Associativity: Order of evaluation for operators of equal precedence

10 Expressions ä Sequence of operators and operands that specifies a computation ä May result in a value (e.g., 123, true) ä May cause side-effects (e.g., change a value) ä Compound expressions (e.g., (a*b)+c)) ä Includes literals (numbers or strings)

11 Java Expression BNF expression ::= numeric_expression | testing_expression | logical_expression | string_expression | bit_expression | casting_expression | creating_expression | literal_expression | "null" | "super" | "this" | identifier | ( "(" expression ")" ) | ( expression ( ( "(" [ arglist ] ")" ) | ( "[" expression "]" ) | ( "." expression ) | ( "," expression ) | ( "instanceof" ( class_name | interface_name ) ) ) ) From http://cuiwww.unige.ch/db-research/ Enseignement/analyseinfo/BNFweb.html

12 Statements ä Smallest “executable” unit ä Declaration statements ä Control statements ä Assignment statements ä Method invocation ä Compound statement (block) ä Semicolon-separated list of statements ä Enclosed in “curly” brackets { } ä Deitel calls it a ‘block’ only if it has declarations of its own

13 Java Abstract Windowing Toolkit GUI Components (from java.awt package) ä java.awt.Graphics (see list on p. 530-531) ä Given an object g of Graphics class: ä g.setColor( Color.red ); // Sets current drawing color to red ä g.drawString(“hello”, 200, 25); // Draws String starting at (200,25) ä g.drawLine(20, 28, 40, 10 ); // Draws line from (20,28) to (40,10) ä g.fillRect(100, 5, 20, 15); // Draws filled rectangle whose upper left // corner is at (100, 5). Width = 20. Height = 15 // corner is at (100, 5). Width = 20. Height = 15 ä g.drawOval(60, 9, 20, 13); // Draws oval whose bounding box upper left // corner is at (60, 9). Width = 20. Height = 13 // corner is at (60, 9). Width = 20. Height = 13 (0,0)x y hello usescurrentcolor

14 Java Swing GUI Components (from javax.swing package) ä javax.swing.JOptionPane ä Dialog box ä message ä error ä information ä warning ä question ä plain ä input ä javax.swing.JTextArea ä javax.swing.JScrollPane


Download ppt "UMass Lowell Computer Science 91.460 Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 6 Java Fundamentals Mon. 9/18/00."

Similar presentations


Ads by Google