First Java Program COMP 102 #2 2015T2 Xiaoying Sharon Gao Computer Science Victoria University of Wellington.

Slides:



Advertisements
Similar presentations
Designing a Program & the Java Programming Language
Advertisements

MiniDraw Testing COMP 102 # T1
©Xiaoying Gao, Peter Andreae What is Programming About COMP 102 #2 2013T2 Xiaoying Sharon Gao Computer Science Victoria University of Wellington.
Computers Are Your Future
© Peter Andreae What is Programming About COMP 102 # T1 Peter Andreae Computer Science Victoria University of Wellington.
Programming Creating programs that run on your PC
Your First C++ Program Aug 27, /27/08 CS 150 Introduction to Computer Science I C++  Based on the C programming language  One of today’s most.
Overview of Programming Paradigms
This set of slides is provided by the author of the textbook1 Introductory Topics l Computer Programming l Programming Life-Cycle Phases l Creating an.
The Analytical Engine Module 6 Program Translation.
Chapter 2: Impact of Machine Architectures What is the Relationship Between Programs, Programming Languages, and Computers.
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages C++ Programming:
Programming Concepts and Languages Chapter 12 – Computers: Understanding Technology, 3 rd edition 1November
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
1 Building Java Programs Chapter 1: Introduction to Java Programming These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may.
Computer Science 101 Introduction to Programming.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Java Programs COMP 102 #3.
Programming Languages: Telling the Computers What to Do Chapter 16.
A First Program Using C#
© Xiaoying Gao, Peter Andreae Class, method, statements COMP 102 #3 2014T2 Xiaoying Sharon Gao Computer Science Victoria University of Wellington.
COMPUTER PROGRAMMING Source: Computing Concepts (the I-series) by Haag, Cummings, and Rhea, McGraw-Hill/Irwin, 2002.
An intro to programming. The purpose of writing a program is to solve a problem or take advantage of an opportunity Consists of multiple steps:  Understanding.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
Chapter 1. Introduction.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
Introduction to Computers and Programming – Computer Programming.
©Xiaoying Gao, Peter Andreae First Java Program COMP 102 #2 2014T2 Xiaoying Sharon Gao Computer Science Victoria University of Wellington.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Chapter 1 What is Programming? Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 1 Chapter 1 Introduction.
© Xiaoying Gao, Peter Andreae Introduction to Computer Program Design COMP T2. Xiaoying (Sharon) Gao Computer Science Victoria University of Wellington.
© Peter Andreae What is Programming About COMP 102 # T1 Peter Andreae Computer Science Victoria University of Wellington.
1.8History of Java Java –Based on C and C++ –Originally developed in early 1991 for intelligent consumer electronic devices Market did not develop, project.
Programming With C.
Chapter 1 Introduction to Computers and C++ Programming Goals: To introduce the fundamental hardware and software components of a computer system To introduce.
Java Programming, Second Edition Chapter One Creating Your First Java Program.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
Visual C++ Programming: Concepts and Projects
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
Computer Programs and Programming Languages What are low-level languages and high-level languages? High-level language Low-level language Machine-dependent.
© Xiaoying Gao, Peter Andreae Introduction to Computer Program Design COMP T2. Xiaoying (Sharon) Gao Computer Science Victoria University of Wellington.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 1 Simple Python Programs Using Print, Variables, Input.
C Language: Introduction
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 05, 2005 Lecture Number: 4.
© Peter Andreae What is Programming About COMP 102 # T1 Peter Andreae Computer Science Victoria University of Wellington.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
Programming Languages
Xiaoying Gao Computer Science Victoria University of Wellington Copyright: Xiaoying Gao, Peter Andreae, Victoria University of Wellington UI methods, Graphical.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Java Programs COMP 102 #3.
© Xiaoying Gao, Peter Andreae Variables, Constants, UI methods COMP 102 #4 2014T2 Xiaoying Sharon Gao Computer Science Victoria University of Wellington.
int k = Integer.MAX_VALUE; k++; int k = Integer.MAX_VALUE; k++; What happens when the following code executes? byte b = someFile.readByte(); b = (byte)(b.
Computer Science Reaching Wider Summer School 2012.
Lecture1 Instructor: Amal Hussain ALshardy. Introduce students to the basics of writing software programs including variables, types, arrays, control.
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
© Peter Andreae Java Programs COMP 102 # T1 Peter Andreae Computer Science Victoria University of Wellington.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
Chapter 1: Introduction to Computers and Programming.
Programming Languages Concepts Chapter 1: Programming Languages Concepts Lecture # 4.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Software Engineering Algorithms, Compilers, & Lifecycle.
Basic Concepts: computer, program, programming …
CSCI-235 Micro-Computer Applications
Problem Solving Using C: Orientation & Lecture 1
Problem Solving.
Problem Solving Using C: Orientation & Lecture 1
Presentation transcript:

First Java Program COMP 102 #2 2015T2 Xiaoying Sharon Gao Computer Science Victoria University of Wellington

©Xiaoying Gao, Peter Andreae Admin Sign up for two lab sessions (Labs start today!) Lab time on MyAllocator is fixed Thursday 4-5 lab is cancelled Assignment 1 is handed out. Voting for a Class Rep Put a message about yourself on the forum if you want to be class representative; the class will vote next week. Trouble with passwords? Go to school office: CO 358 Reading: Done: Course outline Start: Assignment 1 Start: Text Book Chapter 1

©Xiaoying Gao, Peter Andreae COMP 102 2:3 Menu Simple Java Programs Cycle: design, edit, compile, test Program elements

©Xiaoying Gao, Peter Andreae COMP 102 2:4 First Java Program import ecs100.*; public class FirstClass { public void firstMethod() { UI.println( “Hello World!" ); }

©Xiaoying Gao, Peter Andreae COMP 102 2:5 Machine & Assembly Language What the computer can understand Different for each computer Very detailed, low-level control of the computer Horrible to read : : copy the contents of memory location 143 into register 1. add the contents of memory location 116 to the contents of register 1. copy the contents of register 1 to memory location 181. : LD d1 143 AD d1 116 ST d1 181 :

©Xiaoying Gao, Peter Andreae COMP 102 2:6 High Level Programming Languages designed for people to use designed to be translated into machine language Must be Precise: no ambiguity about what to do Expressive:must be able to specify whatever you want done. Readable: People must be able to read the instructions. Translatable:able to be translated into machine language Concise: not “long-winded” or redundant Smalltalk ML Ada C++ Eiffel Prolog Haskell Miranda Java C# Python Scratch GameMaker Alice FORTRAN LISP Algol COBOL Basic C Pascal Simula Modula PHP Javascript

©Xiaoying Gao, Peter Andreae COMP 102 2:7 Java A high-level Object-Oriented programming language Designed by Sun Microsystems, early-mid 1990's. Widely used in teaching and industry. Related to C++, but simpler. Similar to C#. Good for interactive applications. Supports implementation in Web environment (applets). Extensive libraries of predefined classes to support, UIs, graphics, databases, web applications,... Very portable between kinds of computers.

©Xiaoying Gao, Peter Andreae Constructing Programs COMP 102 3:8 Design Edit typing in the Java code Compile Translating to executable instructions Run Testing the program to see that it works Specification syntax errors logic errors

©Xiaoying Gao, Peter Andreae BlueJ is an IDE for Java (Integrated Development Environment) Class manager, for keeping track of the files in your program Editor for entering and modifying the program Built-in compiler interface to help compile and fix the syntax errors Special interface to make it easy to construct objects and call methods on them. Simple use of BlueJ for simple programs: 1.Edit the class file(s) to define the methods 2.Compile the class 3.Create an object of the class right click on the rectangle representing the class select “new…..” ⇒ a red square representing the object 4.Call methods on the object right click on the square representing the object select the method. COMP 102 3:9

©Xiaoying Gao, Peter Andreae Example 1 import ecs100.*; public class Example1{ public void welcomeMessage(){ String name = "Sharon"; String course = "COMP102"; UI.println(“My name is " + name); UI.println("Welcome to " + course); } COMP 102 3:10

©Xiaoying Gao, Peter Andreae Example 2 /** An example for simple string Input/Output. The way to generate loginName is much more simplified Be aware this is not your real login name */ import ecs100.*; public class Example2{ public void printMessage(){ String course = "COMP102"; String name = UI.askString("type your first name: "); String family = UI.askString("your family name? "); UI.println("Hello "+ name + ", Welcome to " + course); String loginName = family.substring(0,2) + name; UI.println("your Login name is " + loginName); } COMP 102 3:11

©Xiaoying Gao, Peter Andreae DrawLabel import ecs100.*; public class DrawLabel { public void drawSimple() { double x = 100; double y = x + 200; double w = 223; double h = w/2; UI.drawRect(100,200,50,50); UI.drawRect(x, y, w, h); } COMP 102 3:12

©Xiaoying Gao, Peter Andreae Elements of the program Comments Keywords : words with special meaning in the Java Language, eg: public, class, if, while mostly to do with the structure of the program Identifiers : other words, used to refer to things in the program. mostly made up by the programmer, some are predefined. Strings : bits of text that the program will manipulate. always surrounded by “ and ” numbers operators and punctuation : + - * / ;, ( ) { } [ ] all have precise meanings and rules for use COMP 102 3:13

©Xiaoying Gao, Peter Andreae Elements of the program Program Structure: Import list the library files you will use. Class Top level components of program Describes a class of objects Specifies the set of actions this kind of object can perform (Can also specify information the objects can hold) Note name, and conventions for naming. Methods Main elements of a class Each method describes one action that the objects of this class can perform COMP 102 3:14

©Xiaoying Gao, Peter Andreae Variables A place to hold a value Type Name Value int x = 100; COMP 102 3:15

©Xiaoying Gao, Peter Andreae Actions in a program Method calls telling an object to do one of its methods, passing the necessary information: UI.println(“Hello"); What are the objects? what are the methods. UI object has methods for printing asking reading drawing …. Assignment statements putting a value in a place Int x = y/2; COMP 102 3:16