Advanced Programming CS206

Slides:



Advertisements
Similar presentations
Chapter 1: Computer Systems
Advertisements

 2005 Pearson Education, Inc. All rights reserved Introduction.
Building Java Programs Chapter 1 Introduction to Java Programming.
The Java Programming Language
Copyright 2008 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading: self-check: #1-14.
Outline Java program structure Basic program elements
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 1: Introduction to Java Programming.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
Copyright 2013 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
1 Building Java Programs Chapter 1: Introduction to Java Programming These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may.
Copyright 2008 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading: self-check: #1-14.
Java: Chapter 1 Computer Systems Computer Programming II Aug
Ch 1 - Introduction to Computers and Programming Hardware Terminology Main Memory Auxiliary Memory Drives Writing Algorithms Using Pseudocode Programming.
CSE:141 Introduction to Programming Faculty of Computer Science, IBA BS-I (Spring 2010) Lecture 3.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Topic 2 Java Basics “When a programming language is created that allows programmers to program in simple English, it will be discovered that programmers.
Java: Chapter 1 Computer Systems Computer Programming II.
Java Language and SW Dev’t
1 Computer Systems -- Introduction  Chapter 1 focuses on:  the structure of a Java application  basic program elements  preparing and executing a program.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Copyright 2009 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading: self-check: #1-14.
Chapter 2: Java Fundamentals
Building Java Programs Chapter 1 Introduction to Java Programming Copyright (c) Pearson All rights reserved.
Object- Oriented Programming (CS243)
1 WELCOME TO CIS 1068! Instructor: Alexander Yates.
Copyright 2010 by Pearson Education CSE 142, Fall 2011 Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
Advanced Programming CS206 Introduction 1. Programming Language Code A programming language is a language that uses specially defined words, grammar,
Copyright 2010 by Pearson Education CSE 142, Spring 2012 Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading: 1.1 -
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Welcome to CSE 142! Zorah Fung University of Washington, Summer Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs.
Copyright 2010 by Pearson Education APCS Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
Fundamental of Java Programming (630002) Unit – 1 Introduction to Java.
Zorah Fung University of Washington, Winter 2016
Lecture 1: Basic Java Syntax
JAVA MULTIPLE CHOICE QUESTION.
Working with Java.
Welcome to CSE 142! Whitaker Brand and Benson Limketkai
Chapter No. : 1 Introduction to Java.
Chapter 3 GC 101 Java Fundamentals.
CSCI 161 – Introduction to Programming I William Killian
CSE 190D, Winter 2013 Building Java Programs Chapter 1
Advanced Programming CS206
University of Central Florida COP 3330 Object Oriented Programming
Benson Limketkai and Marty Stepp University of Washington, Spring 2010
null, true, and false are also reserved.
Introduction to Java Programming
CS-0401 INTERMEDIATE PROGRAMMING USING JAVA
An overview of Java, Data types and variables
Chapter 1: Computer Systems
Benson Limketkai University of Washington, Spring 2011
Building Java Programs
Whitaker Brand University of Washington, Winter 2018
Units with – James tedder
Ch 1 - Introduction to Computers and Programming
Units with – James tedder
Brett Wortzman University of Washington, Summer 2011
Topic 2 Java Basics “When a programming language is created that allows programmers to program in simple English, it will be discovered that programmers.
Building Java Programs
Building Java Programs
Welcome to CSE 142!.
CSE 142, Summer 2012 Building Java Programs Chapter 1
Focus of the Course Object-Oriented Software Development
CSE 142, Spring 2012 Building Java Programs Chapter 1
Zorah Fung University of Washington, Spring 2015
CSE 142, Winter 2014 Building Java Programs Chapter 1
Zorah Fung University of Washington, Winter 2016
Presentation transcript:

Advanced Programming CS206 Introduction

Programming Language Code 10 Programming Language Code A programming language is a language that uses specially defined words, grammar, and punctuation that a computer understands. Some of the more popular programming languages are VisualBasic, C++, and Java. Example: Write Java code that finds the average miles per hour value for a given car trip.

The Compilation Process for Non-Java Programs 11 The Compilation Process for Non-Java Programs After writing a program, you'll normally want to have a computer perform the tasks specified by the program. Getting that to work is normally a two-step process: 1) Perform a compile command, 2) Perform a run command. compile command, tell the computer to translate the program's instructions to a binary format (all 0's and 1's). run command, tell the computer to read the binary-format instructions and perform the tasks specified by them.

The Compilation Process for Non-Java Programs 11 The Compilation Process for Non-Java Programs if you submit source code to a compiler, the compiler translate the source code and produces object code as the result. Source code is the formal term for programming language instructions. Object code is the formal term for binary-format instructions.

The Compilation Process for Non-Java Programs 12 The Compilation Process for Non-Java Programs source code (programming language instructions) Programmers write this. Compilers compile source code into object code. object code (binary instructions) Computers run this.

14 Portability A piece of software is portable if it can be used on many different types of computers. Object code is not portable. Those binary-format instructions are tied to a particular type of computer. The Java solution to improve portability: Java compilers don't compile all the way down to object code. Instead, they compile down to bytecode, which possesses the best features of both object code and source code: Like object code, bytecode uses a format that works closely with computer hardware, so it runs fast. Like source code, bytecode is generic, so it can be run on any type of computer.

Java Virtual Machine How can bytecode be run on any type of computer? 15 Java Virtual Machine How can bytecode be run on any type of computer? As a Java program’s bytecode runs, the bytecode is translated into object code by the computer's bytecode interpreter program. The bytecode interpreter program is known as the Java Virtual Machine, or JVM for short.

The Compilation Process for Java Programs 16 The Compilation Process for Java Programs Java source code Java compilers compile source code into bytecode. bytecode When a Java program is run, the JVM translates bytecode to object code. object code

17 History of Java In the early 1990's, putting intelligence into home appliances was thought to be the next "hot" technology. Examples of intelligent home appliances: Coffee pots and lights that can be controlled by a computer's programs. Anticipating a strong market for such things, Sun Microsystems in 1991 funded a research project (code named Green) whose goal was to develop software for intelligent home appliances. An intelligent home appliance's intelligence comes from its embedded processor chips and the software that runs on the processor chips. To handle the frequent turnover of new chips, appliance software must be extremely portable.

18 History of Java Originally, Sun planned to use C++ for its home appliance software, but they soon realized that C++ was less than ideal because it wasn't portable enough and it relied too heavily on hard-to-maintain things called pointers. Thus, Sun decided to develop a whole new programming language to handle its home appliance software needs. Their new language was originally named Oak (for the tree that was outside project leader James Gosling's window), but it was soon changed to Java. When the home appliance software work dried up, Java almost died before being released. Fortunately for Java, the World Wide Web exploded in popularity and Sun realized it could capitalize on that.

19 History of Java Web pages have to be very portable because they can be downloaded onto any type of computer. Java programs that are embedded in web pages are called applets. Although applets still play a significant role in Java's current success, some of the other types of Java programs have surpassed applets in terms of popularity. We cover Standard Edition (SE) Java applications.

Programming languages

JAVA C 1970 C++ 1979 JAVA 1991 http://java.sun.com/ C# 2000

What can JAVA Do??? Web Application Network Application Desktop Application Network Application

Compiling/running a program Write it. code or source code: The set of instructions in a program. Compile it. compile: Translate a program from one language to another. byte code: The Java compiler converts your code into a format named byte code that runs on many computer types. Run (execute) it. output: The messages printed to the user by a program. source code compile byte code run output

your first application! The Java SE Development Kit 7 (JDK 7). IDE( Integrated Development Environment). 1-JDK 7 http://java.sun.com/javase/downloads/index.jsp JDK 7 : Java SE 7 Java SE 7 Documentation 2-IDE www.textpad.com www.eclipse.org/‎ www.netbeans.org Alternative :JDK7 & NetBeans Bundle

A Simple Java Program Keyword Identifier for Class name Modifier Keyword Identifier for Class name // this program prints “Hello World” to screen public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } Comment Main method declaration Statement Calling the method for printing to screen package cs243; HelloWorld.java

Syntax syntax: The set of legal structures and commands that can be used in a particular language. Every basic Java statement ends with a semicolon ; The contents of a class or method occur between { and } syntax error (compiler error): A problem in the structure of a program that causes the compiler to fail. Examples: Missing semicolon Too many or too few { } braces Illegal identifier for class name Class and file names do not match ...

A Java program Its output: public class Hello { public static void main(String[] args) { System.out.println("Hello, world!"); System.out.println(); System.out.println("This program produces"); System.out.println("four lines of output"); } Its output: Hello, world! This program produces four lines of output

System.out.println A statement that prints a line of output on the console. pronounced "print-linn" sometimes called a "println statement" for short Two ways to use System.out.println : System.out.println("text"); Prints the given message as output. System.out.println(); Prints a blank line of output. 20

Names and identifiers You must give your program a name. public class GangstaRap { Naming convention: capitalize each word (e.g. MyClassName) Your program's file must match exactly (GangstaRap.java) includes capitalization (Java is "case-sensitive") identifier: A name given to an item in your program. must start with a letter or _ or $ subsequent characters can be any of those or a number legal: _myName TheCure ANSWER_IS_42 $bling$ illegal: me+u 49ers side-swipe Ph.D's

Keywords keyword: An identifier that you cannot use because it already has a reserved meaning in Java. abstract default if private this boolean do implements protected throw break double import public throws byte else instanceof return transient case extends int short try catch final interface static void char finally long strictfp volatile class float native super while const for new switch continue goto package synchronized i.e., You may not use char or while for the name of a class.

Strings string: A sequence of characters to be printed. Starts and ends with a " quote " character. The quotes do not appear in the output. Examples: "hello" "This is a string. It's very long!" Restrictions: May not span multiple lines. "This is not a legal String." May not contain a " character. "This is not a "legal" String either." 23

Escape sequences escape sequence: A special sequence of characters used to represent certain special characters in a string. \t tab character \n new line character \" quotation mark character \\ backslash character Example: System.out.println("\\hello\nhow\tare \"you\"?\\\\"); Output: \hello how are "you"?\\

Questions What println statements will generate this output? This program prints a quote from the Gettysburg Address. "Four score and seven years ago, our 'fore fathers' brought forth on this continent a new nation." A "quoted" String is 'much' better if you learn the rules of "escape sequences." Also, "" represents an empty String. Don't forget: use \" instead of " ! '' is not the same as "