Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Today’s lecture Review of Chapter 1 Go over homework exercises for chapter 1.
Chapter 1: Computer Systems
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Primitive Data Types and Operations. Introducing Programming with an Example public class ComputeArea { /** Main method */ public static void main(String[]
C Programming Basics Lecture 5 Engineering H192 Winter 2005 Lecture 05
If You Missed Last Week Go to Click on Syllabus, review lecture 01 notes, course schedule Contact your TA ( on website) Schedule.
Outline Java program structure Basic program elements
Primitive Data Types byte, short, int, long float, double char boolean Are all primitive data types. Primitive data types always start with a small letter.
COMP 110 Introduction to Programming Mr. Joshua Stough September 10, 2007.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
Question of the Day  What card(s) must you flip to verify the following statement: Cards with a vowel on one side, have an even number on the other side.
Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage  Weekly assignments.
Simple Programs from Chapter 2 Putting the Building Blocks All Together (corresponds with Chapter 2)
Java: Chapter 1 Computer Systems Computer Programming II.
CSC 107 – Programming For Science. Announcements  Tutors available MTWR in WTC206/WTC208  Special lab (with Macs) & not in the Tutoring Center  Can.
CSC 107 – Programming For Science. Spacing in a Program  C++ ignores spaces in a program  This also means where newlines placed ignored  #define &
The Java Programming Language
CSC204 – Programming I Lecture 4 August 28, 2002.
JAVA BASICS: Variables and References SYNTAX, ERRORS, AND DEBUGGING.
Board Activity Find your seat on the seating chart Login – Remember your login is your first initial your last name and the last three numbers of your.
School of Computer Science & Information Technology G6DICP - Lecture 9 Software Development Techniques.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
CSC 107 – Programming For Science. History of C  Dennis Ritchie developed C from 1969 – 1973  Based upon B (& other) earlier languages  Since its creation,
Problem of the Day  Why are manhole covers round?
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
PHY 107 – Programming For Science. History of C  Dennis Ritchie developed C from 1969 – 1973  Based upon B (& other) earlier languages  Since its creation,
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
Problem of the Day  Why are manhole covers round?
Chapter 2: Java Fundamentals
Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage  Weekly assignments.
CSC 107 – Programming For Science. Announcements.
Question of the Day You overhear a boy & his mother talking: Mom:What is ? Boy: That's easy, 33. Mom: Good. What's ? Boy:Simple. It's 40. Mom:Excellent!
CSC 107 – Programming For Science. The Week’s Goal.
CSC 107 – Programming For Science. Announcements  Locations of Macs to use outside of lab time  Can find on Library ground floor (6) & main floor (6)
CSC 107 – Programming For Science. History of C  Dennis Ritchie developed C from 1969 – 1973  While at Bell Labs, created language to develop Unix 
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics.
Applications Development
CSC 212 – Data Structures Prof. Matthew Hertz WTC 207D /
Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis Chapter 5: Methods.
Question of the Day You overhear a boy & his mother talking: Mom:What is ? Boy: That's easy, 33. Mom: Good. What's ? Boy:Simple. It's 40. Mom:Excellent!
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics Lecture 5.
Lab 4 - Variables. Information Hiding General Principle: – Restrict the access to variables and methods as much as possible Can label instance variables.
CSC 213 – Large Scale Programming Prof. Matthew Hertz WTC 207D /
CSC 212 – Data Structures Lecture 2: Primitives, References, & Classes.
CSC Programming for Science Lecture 10: Boolean Expressions & More If ­ Else Statements.
Question of the Day  What three letter word completes the first word and starts the second one: DON???CAR.
CS/ENGRD 2110 SPRING 2016 Lecture 2: Objects and classes in Java 1.
Question of the Day You overhear a boy & his mother talking: Mom:What is ? Boy: That's easy, 33. Mom: Good. What's ? Boy:Simple. It's 40. Mom:Excellent!
PHY 107 – Programming For Science. Announcements no magic formulas exist  Need to learn concepts: no magic formulas exist  Single solution not useful;
CSC 107 – Programming For Science. Announcements  Lectures may not cover all material from book  Material that is most difficult or challenging is focus.
Chapter 2 Wrap Up 2/18/16 & 2/22/16. Topics Review for Exam I DecimalFormat More Style Conventions Debugging using eclipse The Java API.
Programming for Interactivity Professor Bill Tomlinson Tuesday & Wednesday 6:00-7:50pm Fall 2005.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Problem of the Day  Why are manhole covers round?
Lecture 2 D&D Chapter 2 & Intro to Eclipse IDE Date.
Elementary Programming
Lecture 3: Operators, Expressions and Type Conversion
Lecture 2: Data Types, Variables, Operators, and Expressions
Introduction to Java Programming
An overview of Java, Data types and variables
Chapter 1: Computer Systems
Units with – James tedder
Units with – James tedder
Building Java Programs
Java Programming Review 1
Chapter 2 Programming Basics.
Presentation transcript:

Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage

Style Guide  Good style helps when writing code  Program logic becomes easier to follow  Easier to read and fix errors  Much simpler to start & stop work on a project  Prevents  Prevents many common errors  Style includes two parts:  Formatting  Documentation

Indentation  Traditionally indent code within set of braces ({})  Be consistent with indentation size (I use 2 spaces)  Nothing is more annoying than looking for the next line.

Indentation char _ [3141 ],__3141[3141];_314159[31415],_3141[31415];main(){register char* _3_141,*_3_1415, *_3__1415; register int _314,_31415,__31415,*_31, _3_14159,__3_1415;*_ =__31415=2,_ [0][_ ]=1[__3141]=5;__3_1415=1;do{_3_14159=_314=0,__ ;for( _31415 =0;_31415<(3,14-4)*__31415;_ )_31415[_3141]=_314159[_31415]= - 1;_3141[*_314159=_3_14159]=_314;_3_141=_ __3_1415;_3_1415= __3_1415 +__3141;for(_31415 = __3_1415 ;_31415;_ ,_3_141 ++,_3_1415++){_314 +=_314<<2 ;_314<<=1;_314+= *_3_1415;_31 =_ _314; if(!(*_31+1) )* _31 =_314 / __31415,_314 [_3141]=_314 % __31415 ;* ( _3__1415=_3_141 )+= *_3_1415 = *_31;while(* _3__1415 >= 31415/3141 ) * _3__1415+= - 10,(*--_3__1415 )++;_314=_314 [_3141]; if ( ! _3_14159 && * _3_1415)_3_14159 =1,__3_1415 = 3141-_31415;}if( _314+(__31415 >>1)>=__31415 ) while ( ++ * _3_141==3141/314 )*_3_141--=0 ;}while(_3_14159 ) ; { char * __3_14= "3.1415"; write((3,1) (--*__3_14,__3_14 ),(_3_ ,++_3_14159)) ; } for ( _31415 = 1; _31415< ;_ )write( 31415% 314-( 3,14),_ [ _31415 ] + " ","314" [ 3]+1)-_314; puts((*_ =0,_ )) ;_314= *" ";}

Braces  Always use braces:  Always use braces: for (int i = 0; i < n; i++); sum = sum + i; sumSquare = sumSquare + (i*i);

Braces  Always use braces:  Always use braces: for (int i = 0; i < n; i++); sum = sum + i; sumSquare = sumSquare + (i*i);  Using braces vs. fixing a bug 10 seconds 30 minutes

Increment/Decrement Operators  Only use ++ & -- on own line (or for loops) // What gets stored at each line while (++k < n) { a[i++] = (2 * i) + 6; b[j] = (j++ * j) - 1; c[j] = a[j] +++ b[j]; }

Statements  Use variables to break up complex ideas // What is this computing? return ( (year % 4 == 0) && (year % 100 != 0)) || ( (year % 100 == 0) && (year % 400 == 0));

Statements  Use variables to break up complex ideas divisibleBy4 = ((year % 4) == 0); divisible100 = ((year % 100) == 0); divisible400 = ((year % 400) == 0); return (divisible4 && !divisible100) || (divisible100 && divisible400);

Comments  We program using “code”  Not easy to read even simple projects  Review your CSC 111 projects  (even better, review a friend’s CSC 111 project)  Comments break up this code  Provide simple English descriptions  State assumptions and preconditions  Describe the outcome of a section

Comments private static void compileResults(String server, String handle) throws IOException { for (Experiment e : Experiment.values()) { Benchmark[] benches = e.getResults(); File newFile = getOutFile(server, e.name(), handle); newFile.createNewFile(); PrintStream out = new PrintStream(newFile); Double[] baselines = computeBaselineMeans(server, e.getResults(), handle, BASELINE, benches); for (Build b : Build.values()) { File[] files = new File[benches.length]; Scanner[] scanners = new Scanner[benches.length]; for (int i = 0; i < files.length; i++) { files[i] = getInFile(server, benches[i], b, handle); scanners[i] = new Scanner(files[i]); } String[] lines = new String[scanners.length]; int heapSize = 0; while (scanners[0].hasNextLine()) { out.print(b.name() + "\t"); for (int i = 0; i < scanners.length; i++) { lines[i] = scanners[i].nextLine(); out.print(lines[i] + "\t"); }

Data Types  8+1 primitive data types  Examples: boolean, byte, char, int, double, String *  Only types that work with Java operators  Operators include: +, -, %, &&, ||, >=, <, !  Primitives used natively by computers  Means using them is very quick  Implies greater support within the language

Primitive Types  Primitive variables are simple to use  Each variable is “xerox” holding a value  Assignment copies value  Update assigned variable only; changes not reflected

Tracing Primitives int x = 5; int sum = 0; for (int i=0; i < x; i++) { sum = sum + x; System.out.println(sum); }

Tracing Primitives int val = 6; String result = “”; while (val > 0) { int digit = val % 2; result = digit + result; val = val / 2; } System.out.println(result);

Your Turn  Get into your groups and complete activity

For Next Lecture  Mourn summer’s end & start of homework  There is no reading for Friday  Spend time reviewing Java you forgot this summer  There is weekly assignment problem on Angel  Due before Friday’s lecture (via )  Get back into the swing of writing Java code