1.1 Your First Program
|
|
|
- Sylvia Lee
- 10 years ago
- Views:
Transcription
1 Why Programming? 1.1 Your First Program Why programming? Need to tell computer what you want it to do. Naive ideal. Natural language instructions. Please simulate the motion of N heavenly bodies, subject to Newton s laws of motion and gravity. Prepackaged software solutions? Great, when what they do is what you want. Computer programming. Enables you to make a computer do anything you want. well, almost anything [stay tuned] Ada Lovelace Languages Analytic Engine 2 Why Program? Machine languages. Tedious and error-prone. Why program? Natural languages. Ambiguous; can be difficult to parse. Kids Make Nutritious Snacks. Red Tape Holds Up New Bridge. Police Squad Helps Dog Bite Victim. Local High School Dropouts Cut in Half. A natural, satisfying and creative experience. Enables accomplishments not otherwise possible. Opens new world of intellectual endeavor. First challenge. Learn a programming language. [ real newspaper headlines, compiled by Rich Pattis ] Next question. Which one? High-level programming languages. Acceptable tradeoff. Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to human beings what we want a computer to do. Donald Knuth Naive ideal. A single programming language. 3 4
2 Our Choice: Java Why Java? Java features. Widely used. Widely available. Embraces full set of modern abstractions. Variety of automatic checks for mistakes in programs. Java features. Widely used. Widely available. Embraces full set of modern abstractions. Variety of automatic checks for mistakes in programs. Facts of life. Java economy. Mars rover. Cell phones. Blu-ray Disc. $100 billion, 5 million developers No language is perfect. We need to choose some language. Our approach. There are only two kinds of programming languages: those people always [gripe] about and those nobody uses. Bjarne Stroustrup Web servers. Minimal subset of Java. Medical devices. Supercomputing. James Gosling Develop general programming skills that are applicable to many languages It s not about the language 5 6 A Rich Subset of the Java Language Built-In Types int double System System.out.println() Math Library Math.sin() Math.cos() Program Development long String System.out.print() Math.log() Math.exp() char boolean System.out.printf() Math.sqrt() Math.pow() Math.min() Math.max() Flow Control Parsing Math.abs() Math.PI if else Integer.parseInt() for while Double.parseDouble() Primitive Numeric Types + - * Boolean true false Punctuation Assignment = / -- % > ++ < && ( ) <= >= ==, ; = String Arrays Objects + "" a[i] class static length() compareto() new public private charat() matches() a.length tostring() equals() new main() 7 8
3 Program Development Program Development (virtual terminals) Program development in Java (bare-bones) Program development in Java (using virtual terminals). 1. Edit your program. 1. Edit your program using any text editor. Use a text editor. 2. Compile it to create an executable file. Result: a text file such as HelloWorld.java. 3. Run your program. 2. Compile it to create an executable file. Use the Java compiler Result: a Java bytecode file file such as HelloWorld.class Mistake? Go back to 1. to fix and recompile. editor running in virtual terminal virtual TV 3. Run your program. Use the Java runtime. Result: your program s output. Mistake? Go back to 1. to fix, recompile, and execute second terminal for commands 9 Program Development (virtual terminals) 10 Program Development (virtual terminals) Program development in Java (using virtual terminals). Program development in Java (using virtual terminals). 1. Edit your program. 1. Edit your program. 2. Compile it by typing javac HelloWorld.java at the command line. 2. Compile it to create an executable file. 3. Run your program. 3. Run your program by typing java HelloWorld at the command line. creates HelloWorld.class uses HelloWorld.class invoke Java runtime at command line invoke Java compiler at command line 11 12
4 Program Development (using DrJava) Program Development (using DrJava) Program development in Java (using DrJava). Program development in Java (using DrJava). 1. Edit your program using the built-in text editor. 2. Compile it to create an executable file. 3. Run your program. 1. Edit your program. 2. Compile it by clicking the compile button. 3. Run your program. text editor compile button creates HelloWorld.class Program Development (using DrJava) Note: Program Style Program development in Java (using DrJava). Three versions of the same program. 1. Edit your program. 2. Compile it to create an executable file. 3. Run your program by clicking the run button or using the command line. // java HelloWorld public class HelloWorld public static void main(string[] args) System.out.println("Hello, World"); Alternative 1: run button (OK if no args) both use HelloWorld.class Fonts, color, comments, and extra space are not relevant to Java. /************************************************************************* * Compilation: javac HelloWorld.java * Execution: java HelloWorld * * Prints "Hello, World". By tradition, this is everyone's first program. * * % java HelloWorld * Hello, World * *************************************************************************/ public class HelloWorld public static void main(string[] args) System.out.println("Hello, World"); Alternative 2: command line (to provide args) public class HelloWorld public static void main(string[] args) System.out.println("Hello, World"); 15 16
5 Note: Program Style 99% of program development Different styles are appropriate in different contexts. DrJava Booksite Book COS 126 assignment Enforcing consistent style can Stifle creativity. Confuse style rules with language rules. Debugging. Cyclic process of editing, compiling, and fixing mistakes (bugs). You will make many mistakes as you write programs. It's normal. As soon as we started programming, we found out to our surprise that it wasn't as easy to get programs right as we had thought. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs. Maurice Wilkes Program Development Environment. Software to support cycle of editing to fix mistakes, compiling programs, running programs, and examining output. Emphasizing consistent style can Make it easier to spot errors. Make it easier for others to read and use code. Enable development environment to provide useful visual cues. Bottom line for COS 126: Life is easiest if you use DrJava style. Examples: Terminal/editor, DrJava. Naive ideal. Please compile, execute, and debug my program. Bad news. Even a computer can t find all the mistakes in your program. 1.2 profound idea 17 [ stay tuned ] 18 Program Development Environments: A Short History Historical context is important in computer science We regularly use old software. We regularly emulate old hardware. We depend upon old concepts and designs. Switches and Lights Use switches to enter binary program code, lights to read results PDP-8, circa 1970 First requirement in any computer system: program development Widely-used methods: switches/lights punched cards terminal editor/virtual terminal IDE switches/lights punched card/tape editor/terminal editor/virtual terminal integrated development environment 19 20
6 Punched Cards/Line Printer Timesharing Terminal Use punched cards for program code, line printer for output Use terminal for editing program, reading output, and controlling computer IBM System 360, circa 1975 VAX 11/780 circa 1977 VT-100 terminal Timesharing: allowed many people to simultaneously use a single machine Editor and Virtual Terminal on a Personal Computer Integrated Development Environment Use an editor to create and make changes to the program text. Use a virtual terminal to invoke the compiler and run the executable code. Use a customized application for all program development tasks. Ex. Pros: Cons: Pros: Cons: Works with any language. Good enough for long programs? Easy-to-use language-specific tools. Overkill for short programs? Useful for other tasks. Dealing with two applications. System-independent (in principle). Large application to learn and maintain. Used by professionals. Used by professionals. Skills may not transfer to other languages
7 Lessons from Short History 1.2 Built-in Types of Data First requirement in any computer system: program development Programming is primarily a process of finding and fixing mistakes. Program development environment must support cycle of editing to fix errors, compiling program, running program, and examining output. Two approaches that have served for decades: editor and virtual terminal integrated development environment Xerox Alto 1978 Macbook Air Built-in Data Types Basic Definitions Data type. A set of values and operations defined on those values. Variable. A name that refers to a value. Assignment statement. Associates a value with a variable. type set of values literal values operations char characters 'A' '@' compare String sequences of characters "Hello World" "CS is fun" concatenate int integers add, subtract, multiply, divide double floating-point numbers e23 add, subtract, multiply, divide boolean truth values true false and, or, not declaration statement variable name assignment statement int a = b = int literal a, b; 1234 ; 99; c = a + b; combined declaration and assignment statement 27 28
8 Trace Trace. Table of variable values after each statement. Text a b t int a, b; undefined undefined undefined a = 1234; 1234 undefined undefined b = 99; undefined int t = a; a = b; b = t; Text Example: Subdivisions of a Ruler String data type. Useful for program input and output. values sequences of characters typical literals "Hello, " "1 " " * " operation concatenate operator + String data type Important note: meaning of characters depends on context "1234" + " + " + "99" operator character operator public class Ruler public static void main(string[] args) String ruler1 = "1"; String ruler2 = ruler1 + " 2 " + ruler1; String ruler3 = ruler2 + " 3 " + ruler2; String ruler4 = ruler3 + " 4 " + ruler3; System.out.println(ruler4); "1" "1 2 1" " " expression "Hi, " + "Bob" value "Hi, Bob" white space white space % java Ruler string concatenation "1" + " 2 " + "1" "1 2 1" "1234" + " + " + "99" "1234" + " + " + "99" " " "1234" + "99" "123499" space characters String concatenation examples 31 32
9 Integers Integers int data type. Useful for calculations, expressing algorithms. values integers between and typical literals operations add subtract multiply divide remainder operators + - * / % int data type expression value comment * / 3 1 no fractional part 5 % 3 2 remainder 1 / 0 run-time error 3 * * has precedence 3 * 5 / 2 5 / has precedence left associative ( 3-5 ) better style examples of int operations 34 Integer Operations public class IntOps public static void main(string[] args) int a = Integer.parseInt(args[0]); int b = Integer.parseInt(args[1]); int sum = a + b; int prod = a * b; int quot = a / b; int rem = a % b; command-line arguments System.out.println(a + " + " + b + " = " + sum); System.out.println(a + " * " + b + " = " + prod); System.out.println(a + " / " + b + " = " + quot); System.out.println(a + " % " + b + " = " + rem); Floating-Point Numbers 1234 = 12* % javac IntOps.java % java IntOps = * 99 = / 99 = % 99 = 46 Java automatically converts a, b, and rem to type String 35
10 Floating-Point Numbers Excerpts from Java s Math Library double data type. Useful in scientific applications. values approximations to real numbers typical literals e operations add subtract multiply divide remainder operators + - * / % expression double data type value e23/2 3.01E / % / 0.0 Infinity Math.sqrt(2.0) Math.sqrt(-1.0) NaN examples of double operations special value special value not a number 37 public class Math double abs(double a) double max(double a, double b) double min(double a, double b) double sin(double theta) double cos(double theta) double tan(double theta) absolute value of a maximum of a and b minimum of a and b sine function cosine function tangent function double exp(double a) exponential (e a ) double log(double a) natural log (loge a, or ln a) double pow(double a, double b) raise a to the bth power (a b ) long round(double a) found to the nearest integer double random() random number in [0. 1) double sqrt(double a) double E double PI square root of a value of e (constant) value of p (constant) also defined for int, long, and float inverse functions asin(), acos(), and atan() also available In radians. Use todegrees() and toradians() to convert. 38 Quadratic Equation Testing Ex. Solve quadratic equation x 2 + bx + c = 0. roots = "b ± b2 " 4 c 2 Testing. Some valid and invalid inputs. public class Quadratic public static void main(string[] args) // Parse coefficients from command-line. double b = Double.parseDouble(args[0]); double c = Double.parseDouble(args[1]); // Calculate roots. double discriminant = b*b - 4.0*c; double d = Math.sqrt(discriminant); double root1 = (-b + d) / 2.0; double root2 = (-b - d) / 2.0; // Print them out. System.out.println(root1); System.out.println(root2); % java Quadratic % java Quadratic % java Quadratic NaN NaN not a number command-line arguments golden ratio % java Quadratic 1.0 hello java.lang.numberformatexception: hello % java Quadratic 1.0 java.lang.arrayindexoutofboundsexception x 2 3x + 2 x 2 x - 1 x 2 + x
11 Booleans Booleans boolean data type. Useful to control logic and flow of a program. values literals true or false true false operations and or not operators && boolean data type a a a b a && b a b true false false false false false false true false true false true true false flase true true true true true Truth-table definitions of boolean operations 42 Comparison Operators Leap Year Comparison operators. Two operands of the same type. Result: a value of type boolean. op meaning true false == equal 2 == 2 2 == 3 = not equal 3 = 2 2 = 2 < less than 2 < 13 2 < 2 <= less than or equal 2 <= 2 3 <= 2 > greater than 13 > 2 2 < 13 >= greater than or equal 3 >= 2 2 >= 3 comparison operators Q. Is a given year a leap year? A. Yes if either (i) divisible by 400 or (ii) divisible by 4 but not 100. public class LeapYear public static void main(string[] args) int year = Integer.parseInt(args[0]); boolean isleapyear; // divisible by 4 but not 100 isleapyear = (year % 4 == 0) && (year % 100 = 0); // or divisible by 400 isleapyear = isleapyear (year % 400 == 0); non-negative discriminant? ( b*b - 4.0*a*c ) >= 0.0 beginning of a century? ( year % 100 ) == 0 legal month? ( month >= 1 ) && ( month <= 12 ) System.out.println(isLeapYear); % java LeapYear 2004 true % java LeapYear 1900 false comparison examples % java LeapYear 2000 true 43 44
12 Type Conversion Type Conversion Type conversion. Convert from one type of data to another. Automatic ( done by Java when no loss of precision; or with strings). Explicitly defined by function call. Cast (write desired type within parens). expression type value "1234" + 99 String "123499" automatic Integer.parseInt("123") int 123 explicit (int) int 2 cast Math.round( ) long 3 explicit (int) Math.round( ) int 3 cast (int) Math.round( ) int 3 cast 11 * 0.3 double 3.3 automatic (int) 11 * 0.3 double 3.3 cast, automatic 11 * (int) 0.3 int 0 cast (int) (11 * 0.3) int 3 cast, automatic 46 Type Conversion Example: Random Integer Summary Ex. Generate a pseudo-random number between 0 and N-1. A data type is a set of values and operations on those values. String text processing, input and output. public class RandomInt public static void main(string[] args) int N = Integer.parseInt(args[0]); double r = Math.random(); int n = (int) (r * N); double to int (cast) int to double (automatic) String to int (function) System.out.println("random integer is " + n); % java RandomInt 6 random integer is 3 % java RandomInt 6 random integer is 0 double between 0.0 and 1.0 int to String (automatic) double, int mathematical calculation. boolean decision making. Be aware. Declare type of values. Convert between types when necessary. Why do we need types? Fundamental computational abstraction. Type conversion must be done at some level. Compiler can help do it correctly. Example: In 1996, Ariane 5 rocket exploded Example of bad type conversion % java RandomInt random integer is 3184 after takeoff because of bad type conversion
Interactive Applications (CLI) and Math
Interactive Applications (CLI) and Math Interactive Applications Command Line Interfaces The Math Class Example: Solving Quadratic Equations Example: Factoring the Solution Reading for this class: L&L,
Java Programming Fundamentals
Lecture 1 Part I Java Programming Fundamentals Topics in Quantitative Finance: Numerical Solutions of Partial Differential Equations Instructor: Iraj Kani Introduction to Java We start by making a few
AP Computer Science Java Subset
APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall
First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science
First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca
MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.
Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java
CS 106 Introduction to Computer Science I
CS 106 Introduction to Computer Science I 01 / 21 / 2014 Instructor: Michael Eckmann Today s Topics Introduction Homework assignment Review the syllabus Review the policies on academic dishonesty and improper
CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java
CS1020 Data Structures and Algorithms I Lecture Note #1 Introduction to Java Objectives Java Basic Java features C Java Translate C programs in CS1010 into Java programs 2 References Chapter 1 Section
CS170 Lab 11 Abstract Data Types & Objects
CS170 Lab 11 Abstract Data Types & Objects Introduction: Abstract Data Type (ADT) An abstract data type is commonly known as a class of objects An abstract data type in a program is used to represent (the
For live Java EE training, please see training courses
2012 Marty Hall Basic Java Syntax Originals of Slides and Source Code for Examples: http://courses.coreservlets.com/course-materials/java.htmlcoreservlets com/course-materials/java html 3 Customized Java
Java Crash Course Part I
Java Crash Course Part I School of Business and Economics Institute of Information Systems HU-Berlin WS 2005 Sebastian Kolbe [email protected] Overview (Short) introduction to the environment Linux
Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.
1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays
CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013
Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)
Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.
Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java
AP Computer Science Static Methods, Strings, User Input
AP Computer Science Static Methods, Strings, User Input Static Methods The Math class contains a special type of methods, called static methods. A static method DOES NOT operate on an object. This is because
An Introduction to Computer Science
An Introduction to Computer Science Robert Sedgewick Kevin Wayne Princeton University Copyright 2003 by Robert Sedgewick and Kevin Wayne For information on obtaining permission for use of material from
Crash Course in Java
Crash Course in Java Based on notes from D. Hollinger Based in part on notes from J.J. Johns also: Java in a Nutshell Java Network Programming and Distributed Computing Netprog 2002 Java Intro 1 What is
Basic Programming and PC Skills: Basic Programming and PC Skills:
Texas University Interscholastic League Contest Event: Computer Science The contest challenges high school students to gain an understanding of the significance of computation as well as the details of
Moving from CS 61A Scheme to CS 61B Java
Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you
Example of a Java program
Example of a Java program class SomeNumbers static int square (int x) return x*x; public static void main (String[] args) int n=20; if (args.length > 0) // change default n = Integer.parseInt(args[0]);
CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals
CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasket { public static void main(string[]
Object Oriented Software Design
Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction
Sample CSE8A midterm Multiple Choice (circle one)
Sample midterm Multiple Choice (circle one) (2 pts) Evaluate the following Boolean expressions and indicate whether short-circuiting happened during evaluation: Assume variables with the following names
J a v a Quiz (Unit 3, Test 0 Practice)
Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points
Introduction to Java
Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high
Programmierpraktikum
Programmierpraktikum Claudius Gros, SS2012 Institut für theoretische Physik Goethe-University Frankfurt a.m. 1 of 21 10/16/2012 09:29 AM Java - A First Glance 2 of 21 10/16/2012 09:29 AM programming languages
Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language
Translation Translating to Java Introduction to Computer Programming The job of a programmer is to translate a problem description into a computer language. You need to be able to convert a problem description
Introduction to Python
WEEK ONE Introduction to Python Python is such a simple language to learn that we can throw away the manual and start with an example. Traditionally, the first program to write in any programming language
1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius
Programming Concepts Practice Test 1 1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius 2) Consider the following statement: System.out.println("1
WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.
WA2099 Introduction to Java using RAD 8.0 Student Labs Web Age Solutions Inc. 1 Table of Contents Lab 1 - The HelloWorld Class...3 Lab 2 - Refining The HelloWorld Class...20 Lab 3 - The Arithmetic Class...25
Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C
Basic Java Constructs and Data Types Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C 1 Contents Hello World Program Statements Explained Java Program Structure in
Basic Java Syntax. Slides 2016 Marty Hall, [email protected]
coreservlets.com custom onsite training Basic Java Syntax Originals of slides and source code for examples: http://courses.coreservlets.com/course-materials/java.html Also see Java 8 tutorial: http://www.coreservlets.com/java-8-tutorial/
1.3 Conditionals and Loops
A Foundation for Programming 1.3 Conditionals and Loops any program you might want to write objects functions and modules graphics, sound, and image I/O arrays conditionals and loops Math primitive data
Java Basics: Data Types, Variables, and Loops
Java Basics: Data Types, Variables, and Loops If debugging is the process of removing software bugs, then programming must be the process of putting them in. - Edsger Dijkstra Plan for the Day Variables
1.00/1.001 - Session 2 Fall 2004. Basic Java Data Types, Control Structures. Java Data Types. 8 primitive or built-in data types
1.00/1.001 - Session 2 Fall 2004 Basic Java Data Types, Control Structures Java Data Types 8 primitive or built-in data types 4 integer types (byte, short, int, long) 2 floating point types (float, double)
Part I. Multiple Choice Questions (2 points each):
Part I. Multiple Choice Questions (2 points each): 1. Which of the following is NOT a key component of object oriented programming? (a) Inheritance (b) Encapsulation (c) Polymorphism (d) Parallelism ******
1.4 Arrays Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright 2002 2010 2/6/11 12:33 PM!
1.4 Arrays Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright 2002 2010 2/6/11 12:33 PM! A Foundation for Programming any program you might want
qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq
qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq Introduction to Programming using Java wertyuiopasdfghjklzxcvbnmqwertyui
Informatica e Sistemi in Tempo Reale
Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)
Java Cheatsheet. http://introcs.cs.princeton.edu/java/11cheatsheet/ Tim Coppieters Laure Philips Elisa Gonzalez Boix
Java Cheatsheet http://introcs.cs.princeton.edu/java/11cheatsheet/ Tim Coppieters Laure Philips Elisa Gonzalez Boix Hello World bestand genaamd HelloWorld.java naam klasse main methode public class HelloWorld
Chapter 3. Input and output. 3.1 The System class
Chapter 3 Input and output The programs we ve looked at so far just display messages, which doesn t involve a lot of real computation. This chapter will show you how to read input from the keyboard, use
Introduction to Computer Programming, Spring Term 2014 Practice Assignment 3 Discussion 15.3.2014-20.3.2014
German University in Cairo Media Engineering and Technology Prof. Dr. Slim Abdennadher Dr. Ahmed Gamal Introduction to Computer Programming, Spring Term 2014 Practice Assignment 3 Discussion 15.3.2014-20.3.2014
Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives
Introduction to Programming and Algorithms Module 1 CS 146 Sam Houston State University Dr. Tim McGuire Module Objectives To understand: the necessity of programming, differences between hardware and software,
Java CPD (I) Frans Coenen Department of Computer Science
Java CPD (I) Frans Coenen Department of Computer Science Content Session 1, 12:45-14:30 (First Java Programme, Inheritance, Arithmetic) Session 2, 14:45-16:45 (Input and Programme Constructs) Materials
Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6. Handout 3. Strings and String Class. Input/Output with JOptionPane.
Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6 Handout 3 Strings and String Class. Input/Output with JOptionPane. Strings In Java strings are represented with a class type String. Examples:
Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.
Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to
Object Oriented Software Design
Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 28, 2010 G. Lipari (Scuola Superiore Sant Anna) Introduction
JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4
JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4 NOTE: SUN ONE Studio is almost identical with NetBeans. NetBeans is open source and can be downloaded from www.netbeans.org. I
Introduction to Java. CS 3: Computer Programming in Java
Introduction to Java CS 3: Computer Programming in Java Objectives Begin with primitive data types Create a main class with helper methods Learn how to call built-in class methods and instance methods
System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :
Benjamin Michael Java Homework 3 10/31/2012 1) Sales.java Code // Sales.java // Program calculates sales, based on an input of product // number and quantity sold import java.util.scanner; public class
SOME EXCEL FORMULAS AND FUNCTIONS
SOME EXCEL FORMULAS AND FUNCTIONS About calculation operators Operators specify the type of calculation that you want to perform on the elements of a formula. Microsoft Excel includes four different types
Installing Java. Table of contents
Table of contents 1 Jargon...3 2 Introduction...4 3 How to install the JDK...4 3.1 Microsoft Windows 95... 4 3.1.1 Installing the JDK... 4 3.1.2 Setting the Path Variable...5 3.2 Microsoft Windows 98...
Iteration CHAPTER 6. Topic Summary
CHAPTER 6 Iteration TOPIC OUTLINE 6.1 while Loops 6.2 for Loops 6.3 Nested Loops 6.4 Off-by-1 Errors 6.5 Random Numbers and Simulations 6.6 Loop Invariants (AB only) Topic Summary 6.1 while Loops Many
1001ICT Introduction To Programming Lecture Notes
1001ICT Introduction To Programming Lecture Notes School of Information and Communication Technology Griffith University Semester 2, 2015 1 3 A First MaSH Program In this section we will describe a very
Chapter 1 Java Program Design and Development
presentation slides for JAVA, JAVA, JAVA Object-Oriented Problem Solving Third Edition Ralph Morelli Ralph Walde Trinity College Hartford, CT published by Prentice Hall Java, Java, Java Object Oriented
How to use the Eclipse IDE for Java Application Development
How to use the Eclipse IDE for Java Application Development Java application development is supported by many different tools. One of the most powerful and helpful tool is the free Eclipse IDE (IDE = Integrated
Installing Java (Windows) and Writing your First Program
Appendix Installing Java (Windows) and Writing your First Program We will be running Java from the command line and writing Java code in Notepad++ (or similar). The first step is to ensure you have installed
Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:
Introduction to Programming and Algorithms Module 2 CS 146 Sam Houston State University Dr. Tim McGuire Introduction To Computers And Java Chapter Objectives To understand: the meaning and placement of
Introduction to Java Lecture Notes. Ryan Dougherty [email protected]
1 Introduction to Java Lecture Notes Ryan Dougherty [email protected] Table of Contents 1 Versions....................................................................... 2 2 Introduction...................................................................
CS 111 Classes I 1. Software Organization View to this point:
CS 111 Classes I 1 Software Organization View to this point: Data Objects and primitive types Primitive types operators (+, /,,*, %). int, float, double, char, boolean Memory location holds the data Objects
Chapter 2 Elementary Programming
Chapter 2 Elementary Programming 2.1 Introduction You will learn elementary programming using Java primitive data types and related subjects, such as variables, constants, operators, expressions, and input
Computer Programming I
Computer Programming I COP 2210 Syllabus Spring Semester 2012 Instructor: Greg Shaw Office: ECS 313 (Engineering and Computer Science Bldg) Office Hours: Tuesday: 2:50 4:50, 7:45 8:30 Thursday: 2:50 4:50,
Sources: On the Web: Slides will be available on:
C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,
CS106A, Stanford Handout #38. Strings and Chars
CS106A, Stanford Handout #38 Fall, 2004-05 Nick Parlante Strings and Chars The char type (pronounced "car") represents a single character. A char literal value can be written in the code using single quotes
River Dell Regional School District. Computer Programming with Python Curriculum
River Dell Regional School District Computer Programming with Python Curriculum 2015 Mr. Patrick Fletcher Superintendent River Dell Regional Schools Ms. Lorraine Brooks Principal River Dell High School
4.2 Sorting and Searching
Sequential Search: Java Implementation 4.2 Sorting and Searching Scan through array, looking for key. search hit: return array index search miss: return -1 public static int search(string key, String[]
Variables, Constants, and Data Types
Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class: L&L, 2.1-2.3, App C 1 Primitive Data There are eight
University of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python
Introduction Welcome to our Python sessions. University of Hull Department of Computer Science Wrestling with Python Week 01 Playing with Python Vsn. 1.0 Rob Miles 2013 Please follow the instructions carefully.
Welcome to Introduction to programming in Python
Welcome to Introduction to programming in Python Suffolk One, Ipswich, 4:30 to 6:00 Tuesday Jan 14, Jan 21, Jan 28, Feb 11 Welcome Fire exits Toilets Refreshments 1 Learning objectives of the course An
LOOPS CHAPTER CHAPTER GOALS
jfe_ch04_7.fm Page 139 Friday, May 8, 2009 2:45 PM LOOPS CHAPTER 4 CHAPTER GOALS To learn about while, for, and do loops To become familiar with common loop algorithms To understand nested loops To implement
VIRTUAL LABORATORY: MULTI-STYLE CODE EDITOR
VIRTUAL LABORATORY: MULTI-STYLE CODE EDITOR Andrey V.Lyamin, State University of IT, Mechanics and Optics St. Petersburg, Russia Oleg E.Vashenkov, State University of IT, Mechanics and Optics, St.Petersburg,
COSC 1020 3.0 Introduction to Computer Science I Section A, Summer 2005. Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19
Term Test #2 COSC 1020 3.0 Introduction to Computer Science I Section A, Summer 2005 Family Name: Given Name(s): Student Number: Question Out of Mark A Total 16 B-1 7 B-2 4 B-3 4 B-4 4 B Total 19 C-1 4
In this Chapter you ll learn:
Now go, write it before them in a table, and note it in a book. Isaiah 30:8 To go beyond is as wrong as to fall short. Confucius Begin at the beginning, and go on till you come to the end: then stop. Lewis
Outline. hardware components programming environments. installing Python executing Python code. decimal and binary notations running Sage
Outline 1 Computer Architecture hardware components programming environments 2 Getting Started with Python installing Python executing Python code 3 Number Systems decimal and binary notations running
1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders
1.00 Lecture 1 Course Overview Introduction to Java Reading for next time: Big Java: 1.1-1.7 Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders
Udacity cs101: Building a Search Engine. Extracting a Link
Udacity cs101: Building a Search Engine Unit 1: How to get started: your first program Extracting a Link Introducing the Web Crawler (Video: Web Crawler)... 2 Quiz (Video: First Quiz)...2 Programming (Video:
Chapter 2: Elements of Java
Chapter 2: Elements of Java Basic components of a Java program Primitive data types Arithmetic expressions Type casting. The String type (introduction) Basic I/O statements Importing packages. 1 Introduction
Computer Programming I & II*
Computer Programming I & II* Career Cluster Information Technology Course Code 10152 Prerequisite(s) Computer Applications, Introduction to Information Technology Careers (recommended), Computer Hardware
We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.
LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.
13 File Output and Input
SCIENTIFIC PROGRAMMING -1 13 File Output and Input 13.1 Introduction To make programs really useful we have to be able to input and output data in large machinereadable amounts, in particular we have to
Overview. java.math.biginteger, java.math.bigdecimal. Definition: objects are everything but primitives The eight primitive data type in Java
Data Types The objects about which computer programs compute is data. We often think first of integers. Underneath it all, the primary unit of data a machine has is a chunks of bits the size of a word.
Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions
Phys4051: C Lecture 2 & 3 Functions (Review) Comment Statements Variables & Operators Branching Instructions Comment Statements! Method 1: /* */! Method 2: // /* Single Line */ //Single Line /* This comment
Web Programming Step by Step
Web Programming Step by Step Lecture 13 Introduction to JavaScript Reading: 7.1-7.4 Except where otherwise noted, the contents of this presentation are Copyright 2009 Marty Stepp and Jessica Miller. Client-side
Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go
Debugging ESE112 Java Programming: API, Psuedo-Code, Scope It is highly unlikely that you will write code that will work on the first go Bugs or errors Syntax Fixable if you learn to read compiler error
Java programming for C/C++ developers
Skill Level: Introductory Scott Stricker ([email protected]) Developer IBM 28 May 2002 This tutorial uses working code examples to introduce the Java language to C and C++ programmers. Section 1. Getting
A Short Introduction to Writing Java Code. Zoltán Majó
A Short Introduction to Writing Java Code Zoltán Majó Outline Simple Application: Hello World Compiling Programs Manually Using an IDE Useful Resources Outline Simple Application: Hello World Compiling
Introduction to Programming in Java
Introduction to Programming in Java An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Princeton University O N L I N E P R E V I E W!"#$%&'(')!"*+,,,-./01/23,,,0425,67 Publisher Executive
6.1. Example: A Tip Calculator 6-1
Chapter 6. Transition to Java Not all programming languages are created equal. Each is designed by its creator to achieve a particular purpose, which can range from highly focused languages designed for
Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation
Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science updated 03/08/2012 Unit 1: JKarel 8 weeks http://www.fcps.edu/is/pos/documents/hs/compsci.htm
Habanero Extreme Scale Software Research Project
Habanero Extreme Scale Software Research Project Comp215: Java Method Dispatch Zoran Budimlić (Rice University) Always remember that you are absolutely unique. Just like everyone else. - Margaret Mead
02 B The Java Virtual Machine
02 B The Java Virtual Machine CS1102S: Data Structures and Algorithms Martin Henz January 22, 2010 Generated on Friday 22 nd January, 2010, 09:46 CS1102S: Data Structures and Algorithms 02 B The Java Virtual
Binary Number System. 16. Binary Numbers. Base 10 digits: 0 1 2 3 4 5 6 7 8 9. Base 2 digits: 0 1
Binary Number System 1 Base 10 digits: 0 1 2 3 4 5 6 7 8 9 Base 2 digits: 0 1 Recall that in base 10, the digits of a number are just coefficients of powers of the base (10): 417 = 4 * 10 2 + 1 * 10 1
Third AP Edition. Object-Oriented Programming and Data Structures. Maria Litvin. Gary Litvin. Phillips Academy, Andover, Massachusetts
Third AP Edition Object-Oriented Programming and Data Structures Maria Litvin Phillips Academy, Andover, Massachusetts Gary Litvin Skylight Software, Inc. Skylight Publishing Andover, Massachusetts Skylight
Introduction to Object-Oriented Programming
Introduction to Object-Oriented Programming Programs and Methods Christopher Simpkins [email protected] CS 1331 (Georgia Tech) Programs and Methods 1 / 8 The Anatomy of a Java Program It is customary
Computing Concepts with Java Essentials
2008 AGI-Information Management Consultants May be used for personal purporses only or by libraries associated to dandelon.com network. Computing Concepts with Java Essentials 3rd Edition Cay Horstmann
How To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For
Projet Java Responsables: Ocan Sankur, Guillaume Scerri (LSV, ENS Cachan) Objectives - Apprendre à programmer en Java - Travailler à plusieurs sur un gros projet qui a plusieurs aspects: graphisme, interface
CSC230 Getting Starting in C. Tyler Bletsch
CSC230 Getting Starting in C Tyler Bletsch What is C? The language of UNIX Procedural language (no classes) Low-level access to memory Easy to map to machine language Not much run-time stuff needed Surprisingly
Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard
INPUT & OUTPUT I/O Example Using keyboard input for characters import java.util.scanner; class Echo{ public static void main (String[] args) { Scanner sc = new Scanner(System.in); // scanner for the keyboard
The Java Virtual Machine (JVM) Pat Morin COMP 3002
The Java Virtual Machine (JVM) Pat Morin COMP 3002 Outline Topic 1 Topic 2 Subtopic 2.1 Subtopic 2.2 Topic 3 2 What is the JVM? The JVM is a specification of a computing machine Instruction set Primitive
1 Introduction. 2 An Interpreter. 2.1 Handling Source Code
1 Introduction The purpose of this assignment is to write an interpreter for a small subset of the Lisp programming language. The interpreter should be able to perform simple arithmetic and comparisons
Math Review. for the Quantitative Reasoning Measure of the GRE revised General Test
Math Review for the Quantitative Reasoning Measure of the GRE revised General Test www.ets.org Overview This Math Review will familiarize you with the mathematical skills and concepts that are important
