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

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Chapter 3: Beginning Problem Solving Concepts for the Computer Programming Computer Programming Skills /1436 Department of Computer Science.
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Chapter 3 - Java Programming With Supplied Classes1 Chapter 3 Java Programming With Supplied Classes.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Java Programming, 3e Concepts and Techniques Chapter 3 Manipulating Data Using Methods.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 4 HW#1: Electronic Submission of Part 2 Jini.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 7 Java Fundamentals Operators and Expressions.
Chapter 3 - Introduction to Java Applets Outline 3.1Introduction 3.2Thinking About Objects 3.4A Simple Java Applet: Drawing a String 3.5Two More Simple.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Review CSC 171 FALL 2004 LECTURE 21. Topics Objects and Classes Fundamental Types Graphics and Applets Decisions Iteration Designing Classes Testing and.
Chapter 2 - Java Programming Fundamentals1 Chapter 2 Java Programming Fundamentals.
Chapter 8 Arrays and Strings
JavaScript, Third Edition
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 5 Java Fundamentals Fri. 9/15/00.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
CSC 142 C 1 CSC 142 Object based programming in Java [Reading: chapter 4]
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Java Programming, 2E Introductory Concepts and Techniques Chapter 3 Manipulating Data Using Methods.
CS 100: Roadmap to Computing Fall 2014 Lecture 01.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
University of Houston-Clear Lake Proprietary© 1997 Evolution of Programming Languages Basic cycle of improvement –Experience software difficulties –Theory.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 14 Java Fundamentals 2D Graphics Wed. 10/11/00.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Java SE 8 for Programmers, Third Edition
CS 112 Department of Computer Science George Mason University CS 112 Department of Computer Science George Mason University Final Review Lecture 14.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Arrays.
CIS-165 C++ Programming I CIS-165 C++ Programming I Bergen Community College Prof. Faisal Aljamal.
1 Block1 – unit 2 (The Case study in Budd 5-6).  create a small application that uses the Abstract Windowing Toolkit (AWT)  Swing packages to simulate.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 8 Java Fundamentals Control Structures Fri.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 25 - Beyond C & C++: Operators, Methods, and.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Arrays Chap. 9 Storing Collections of Values 1. Introductory Example Problem: Teachers need to be able to compute a variety of grading statistics for.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
CPCS 391 Computer Graphics Lab One. Computer Graphics Using Java What is Computer Graphics: Computer graphics are graphics created using computers and,
Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection.
Java Programming Language Lecture27- An Introduction.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
JAVA MULTIPLE CHOICE QUESTION.
Chapter 3 Syntax, Errors, and Debugging
CS 100: Roadmap to Computing
JavaScript Objects.
Java Programming: From Problem Analysis to Program Design, 4e
Java Programming Language
Chapter 2: Basic Elements of Java
The Building Blocks Classes: Java class library, over 1,800 classes:
Review Session Biggest discrepancy questions
In this class, we will cover:
ICOM 4029 Fall 2003 Lecture 2 (Adapted from Prof. Necula UCB CS 164)
String Class.
Review for Midterm 3.
Presentation transcript:

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

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.

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.

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

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

Java Primitive Data Types

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!

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”};

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

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)

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 Enseignement/analyseinfo/BNFweb.html

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

Java Abstract Windowing Toolkit GUI Components (from java.awt package) ä java.awt.Graphics (see list on p ) ä 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

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