UMass Lowell Computer Science 91.460 Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 5 Java Fundamentals Fri. 9/15/00.

Slides:



Advertisements
Similar presentations
LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class.
Advertisements

UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 6 Java Fundamentals Mon. 9/18/00.
Introduction to Java Kiyeol Ryu Java Programming Language.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 - Introduction to Java Applets Outline 3.1 Introduction 3.2 Sample Applets from the Java 2.
Introduction to Java Programming, 4E
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 1 Introduction/Overview Wed. 9/6/00.
Principles of Object-Oriented Software Development The language Java.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
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 2 Introduction/Overview Fri. 9/8/00.
Java Applets. Road Map Introduction to Java Applets Review applets that ship with JDK Make our own simple applets –Introduce inheritance –Introduce the.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 7 Java Fundamentals Operators and Expressions.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 3 HW#1 Jini Overview C++ Diagnostic Results.
Chapter 2 - Introduction to Java Applications
Course Map The Java Programming Language Basics Object-Oriented Programming Exception Handling Graphical User Interfaces and Applets Multithreading Communications.
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.
Relational Operators Control structures Decisions using “if” statements  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course.
Programming Software Applications Week 1 Dr. Xiaohong Gao Trent Park – B107, ext. 2252
Program Design With Methods And Graphics / Chapter 4 1 Abstract Window Toolkit.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 24 - Introduction to Java Applications and Applets Outline 24.1Introduction 24.2Basics of a Typical.
Developing User Interfaces (DUI) Chris North cs3724: HCI.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 - Introduction to Java Applets Outline 3.1 Introduction 3.2 Sample Applets from the Java 2.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
Introduction to Java Programming with JBuilder 4
S.W. Ma/CIM/LWL41211/2 Prog. IIA Page 1 HKIVE (Lee Wai Lee Campus) Department of CIM Course : Year 2 Module : Programming IIA Textbook : Introduction.
Computer Science [3] Java Programming II - Laboratory Course Lab 6: Introduction to Java Applets Sample Applets from the Java Simple Java Applet: Drawing.
Java Workshop for Teachers May 6, 2005 A Brief Look at the Java Programming Language.
Advanced Java New York University School of Continuing and Professional Studies.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
Java Programming, 3e Concepts and Techniques Chapter 2 - Part 2 Creating a Java Application and Applet.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
INTRODUCTION TO JAVA CHAPTER 1 1. WHAT IS JAVA ? Java is a programming language and computing platform first released by Sun Microsystems in The.
Introduction to Java Programming. History F James Gosling and Sun Microsystems F Oak F Java, May 20, 1995, Sun World F HotJava –The first Java-enabled.
1 Part I : Chapter 01 Introduction to Java Programming.
9/21/99www.cs.vt.edu/wwtut/1 User Interface Programming In Java Part 1 – Introduction Marc Abrams Virginia Tech CS Dept courses.cs.vt.edu/wwwtut/
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Java Applets. 2 Introduction to Java Applet Programs  Applications are stand alone programs executed with Java interpreter executed with Java interpreter.
OOP (Java): Simple/ OOP (Java) Objectives – –give some simple examples of Java applications and one applet 2. Simple Java Programs Semester.
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
POS 406 Java Technology And Beginning Java Code
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Introduction to Java Programming with Forte Y. Daniel Liang.
CS 3131 Introduction to Programming in Java Rich Maclin Computer Science Department.
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.
Introduction to Java Applets Sangeetha Parthasarathy 05/21/2001.
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.
Applets. What is an applet? Why create applets instead of applications? – Applets are Java programs that can be embedded in an HTML document – In contrast,
Introduction to Java Programming. Introduction Course Objectives Organization of the Book.
Java Applets. 2 Introduction to Java Applet Programs Applications are ___________________ programs –executed with Java interpreter Applet is a small program.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 - Introduction to Java Applets Outline 3.1Introduction 3.2Thinking About Objects 3.3Sample.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 2 - Introduction to Java Applications Outline 2.1Introduction 2.2A Simple Program: Printing a.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
CSE S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing with Graphics.
CSE S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing with Graphics.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Creating a Java Application and Applet
Java Computer Industry Lab. 1 Programming Java Java Basics Incheon Paik.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 - Introduction to Java Applets Will not cover Section 3.7 Thinking About Objects: Identifying.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Introduction to Java Programming, 4E Y. Daniel Liang.
Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection.
CSE S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Applications Active Web Documents Active Web Documents.
Chapter No. : 1 Introduction to Java.
Chapter 2 - Introduction to Java Applications
Chapter 24 - Introduction to Java Applications and Applets
Java Applets.
Presentation transcript:

UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 5 Java Fundamentals Fri. 9/15/00

Homework #1, Part 1 Due today at start of lecture.

Homework #1, Part 2 Mon, 9/18 “Hello World” programming (application and applet) Homework is due at the start of lecture on the due date. 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. Note: When testing an applet in the UML CS UNIX environment, be sure to set the UNIX DISPLAY environment variable appropriately.

Homework #1, Part 2 (continued) Homework is due at the start of lecture on the due date. To submit your files electronically, use the UNIX submit command Example for 3 files: Example for 3 files: submit kdaniels hw1 filename.java filename.class filename.html submit kdaniels hw1 filename.java filename.class filename.html You’ll submit 5 files for HW#1, part 2: 2 for application, 3 for applet You’ll submit 5 files for HW#1, part 2: 2 for application, 3 for applet Submission deadline is 9:30 a.m. on Monday, 18 September Submission deadline is 9:30 a.m. on Monday, 18 September I have now set it up to allow multiple submissions before the deadline I have now set it up to allow multiple submissions before the deadline Bring a paper printout of your code to give to me at start of Monday’s lecture Bring a paper printout of your code to give to me at start of Monday’s lecture

Java Fundamentals ä 1: Java fundamentals ä applets, applications, data types, control structures, OO programming, files ä 2: Advanced Java concepts & Java support for distributed computing ä GUI/events, graphics, exceptions, advanced data structures, threads/ multithreading, RMI ä 3: Distributed computing using a sample Java- based environment: Jini

Syllabus for Part 1 of the Course Closed book; Worth 15% of grade

Why Java & Distributed Computing? ä Platform independence helps with heterogeneous hardware, software challenge ä Built-in support for: ä Multithreading: “concurrent” multiple activities ä Client-Server computing: servlets, JDBC ä Remote Method Invocation (RMI): method calls across network ä Networking: socket-based communication views networking like file I/O For insight into the original Java vision, see the original Java whitepaper by James Gosling at:

Introduction to Java Applications ä Java application is executed using the Java interpreter (but not inside browser like an applet) ä Application begins execution in main( ) ä main( ) is static method inside class ä no convenient input from command line ä System.exit(0); // required to clean up // after GUI/graphics // after GUI/graphics // Save this in file Welcome1.java public class Welcome1{ public static void main( String args[] ) public static void main( String args[] ) { System.out.println( "Java is fun!" ); System.out.println( "Java is fun!" ); }} javac Welcome1.java java Welcome1 Welcome1.class Welcome1.java

javac Welcome1Applet.java appletviewer Welcome1Applet.html Introduction to Java Applets ä Java applet is executed inside a WWW browser (or appletviewer) using a Java interpreter that is inside the browser. Welcome1Applet.class Welcome1Applet.java Welcome1Applet.html // Save this file in Welcome1Applet.java import java.applet.*; import java.awt.*; public class Welcome1Applet extends Applet{ public void paint(Graphics g) public void paint(Graphics g) { g.drawString( "Java is fun!”, 25, 50 ); g.drawString( "Java is fun!”, 25, 50 ); }} <HTML> </APPLET></HTML> Save this file in Welcome1Applet.html

Introduction to Java Applets (continued) ä Order of (a subset of) applet method invocations: ä init( ) ä start( ) ä paint( )

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 Inheritance InheritancePolymorphism 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 ä 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 ä always passed by reference ä 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

Homework 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.