©Xiaoying Gao, Peter Andreae First Java Program COMP 102 #2 2014T2 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
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
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.
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.
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#
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Program Elements and Syntax.
© Xiaoying Gao, Peter Andreae Class, method, statements COMP 102 #3 2014T2 Xiaoying Sharon Gao Computer Science Victoria University of Wellington.
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.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
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.
PYTHON. Python is a high-level, interpreted, interactive and object- oriented scripting language. Python was designed to be highly readable which uses.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 1 Chapter 1 Introduction.
First Java Program COMP 102 #2 2015T2 Xiaoying Sharon Gao Computer Science Victoria University of Wellington.
© 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.
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
J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition Second Edition D.S. Malik D.S. Malik.
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.
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.
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:
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 …
Basic 1960s It was designed to emphasize ease of use. Became widespread on microcomputers It is relatively simple. Will make it easier for people with.
Sections Basic Concepts of Programming
CSCI-235 Micro-Computer Applications
Problem Solving Using C: Orientation & Lecture 1
Computer science By/ Midhat Mohiey. Introduction to Programming using C ++ 2.
Problem Solving.
Introduction to Algorithm Design
Problem Solving Using C: Orientation & Lecture 1
Presentation transcript:

©Xiaoying Gao, Peter Andreae First Java Program COMP 102 #2 2014T2 Xiaoying Sharon Gao Computer Science Victoria University of Wellington

©Xiaoying Gao, Peter Andreae COMP 102 2:2 Menu Simple Java Programs Cycle: design, edit, compile, test Program elements Reading: Text Book Chapter 1 Admin: Assignment 1 is handed out. Sign up for two lab sessions! (Labs start tomorrow) 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 School Study Help: CO253

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

©Xiaoying Gao, Peter Andreae COMP 102 2:4 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:5 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:6 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 COMP 102 3:7 Constructing Programs 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 COMP 102 3:8 BlueJ 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.

© Xiaoying Gao, Peter Andreae COMP 102 3:9 Using BlueJ for Java Programs 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.

© 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 Inout/Output. The way to generate loginName is much more simplified */ 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 COMP 102 3:13 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

© Xiaoying Gao, Peter Andreae COMP 102 3:14 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

© 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