announcements
play

Announcements Posted basic background, will continue review in - PDF document

Announcements Posted basic background, will continue review in class CS1007: Object Oriented Design Tas and Programming in Java Ohan Oda Stanley Tzeng Lecture #2 Check courseworks tomorrow for office hours Jan 19


  1. Announcements • Posted basic background, will continue review in class CS1007: Object Oriented Design • Ta’s and Programming in Java – Ohan Oda – Stanley Tzeng Lecture #2 • Check courseworks tomorrow for office hours Jan 19 survey. Shlomo Hershkop – Let me know asap via email if you have problems shlomo@cs.columbia.edu logging in. From Last Class Unix classes • Unix review courses offered by CUIT • Nice mix of background • Link on webpage, need to sign up • Most will be using Lewis & Loftus as Friday, January 20, 10-12noon, 1pm-3pm background, as soon as I find a copy will post reading pages Tuesday, January 24, 5pm-6:45pm Wednesday, January 25, 5pm-7pm • Most everyone has access to their own computer Friday, January 27, 10-12noon, 1pm-3pm, 3pm-5pm Tuesday, January 31, 5pm-6:45pm 1

  2. Outline Status • Review of Java basics. • Should have plans on acquiring the text • Should have tested your cunix access • Writing classes in Java. • Should have seen the class website • Types • Should setup your work machine for • Object reference vs. Object values – Java – Editor – (eventually) eclipse/netbeans/etc Reading • Background book on relevant subjects • Cunix accounts, will be used for homework • Obtain book and start on chapter 1 submissions Class background Suggestions • Working outside of CUNIX: • There is a wide variety of both JAVA and – Setup correct version of java (1.5) programming skills – Find comfortable programming environment • We will do a super fast overview of JAVA – Save often basics before starting the meat and – Don’t forget to test on cunix before final submission potatoes of the course. • Working on CUNIX • Please bear with me. – Don’t telnet – Putty: available from acis – Work in the labs 2

  3. IMPORTANT Basics I • CS != Programming • Program • Java is a tool to teach programming and • Class problem solving concepts • So if you know everything in Java you still • Methods need to stay awake • Will be introducing many advanced topics along with the background material Java Program Structure Java Program • A Java program contains at least one class definition. • In the Java programming language: public class Hello { –A program is made up of one or more public static void main(String[] args) { System.out.println("Hello, world!") ; classes } –A class contains one or more methods } • This code defines a class named Hello. The definition of –A method contains program statements the public class Hello must be in a file Hello.java. • The main method is the code that runs when you call the java interpreter on the bytecode • A Java application always contains a – java Hello method called main • Advanced: Can have private classes within the same file 3

  4. Java Program Structure Java Program Structure // comments about the class // comments about the class public class Hello public class Hello { { class header // comments about the method public static void main (String[] args) class body { method header method body } Comments can be placed almost anywhere } } 13 14 Comments Identifiers • Comments in a program are called inline documentation • Elements in a program are identified by some name. In Java, identifiers: • They should be included to explain the purpose of the program and describe processing steps – Always start with a letter. – Can include letters, digits, underscore (` ') and the • They do not affect how a program works, they are dollar sign symbol ($). simply ignored. – Must be different from any Java reserved words (or keywords). • Java comments can take three forms: • Often we use special identifiers called reserved // this comment runs to the end of the line words that already have a predefined meaning in the language /* this comment runs to the terminating – Keywords that we've seen so far include: public, symbol, even across line breaks */ static, class and void . /** this is a javadoc comment, will cover later */ 15 4

  5. Reserved Words Case counts • The Java reserved words: • Identifiers and keywords in Java are case abstract else int strictfp sensitive. In other words, capitalization matters. boolean enum interface super break extends long switch Keywords are always in lowercase. The byte false native synchronized following identifiers are all different: case final new this catch finally null throw – SHLOMO char float package throws class for private transient – shlomo const goto protected true continue if public try – SHlomO default implements return void do import short volatile • Bad idea: use all those in one program . double instanceof static while • WHY? 17 Spaces Types • We use the word whitespace to describe blanks, tabs and newline The values a variable can take on and the characters. The Java compiler ignores whitespace except when it is operations we can perform on them is used to separate words. E.g.: determined by its type. Java has the y=m*x+b;total=total+y; following type categories: • Is the same as: • Booleans y = m*x + b ; total = total + y ; • Characters • Which is easier to read? • Integers • Does anyone know the diffence between DOS and UNIX • Floating Points linebreaks? (hint: fixcrlf) • References to Objects 5

  6. Integers Integer Literal • A integer value or literal can be specified in • The java integer type represents both positive decimal, hex, or octal (base 8) and negative integers. An n-bit integer x, can – Decimal is a regular number which doesn’t start with represent the range: zero − − ≤ ≤ − 1 1 2 n 2 n – Hex literals start with 0x…(0x1F = 31 base10) x – Octal literals start with just zero (072 = 58 base10) • Integer literals are by default of type int • byte 8 bits • A long literal ends with L short 16 bits int 32 bits • If an int is small enough to fit into a short, it will long 64 bits be automatically converted, else you need to cast. In general extra bits are thrown away (not always good). Floating Point Type Traditional Program Development • The mechanics of developing a program include several • Floating point are used to represent the activities real numbers, i.e. fractional numbers 1. Skip design • 0.345 = 3.45 X 10 2. writing the program in a specific programming language (such as Java) 3. translating the program into a form that the computer can execute 4. investigating and fixing various types of errors that can occur 5. Go back and design correctly • Software tools can be used to help with all parts of this process 6

  7. Development Environments Syntax and Semantics • There are many programs that support the development of Java software, including: • The syntax rules of a language define how we can put together symbols, reserved words, and identifiers to – Sun Java Development Kit (JDK) make a valid program – Sun NetBeans • The semantics of a program statement define what that – IBM Eclipse statement means (its purpose or role in a program) – Borland JBuilder – MetroWerks CodeWarrior • A program that is syntactically correct is not necessarily logically (semantically) correct – Monash BlueJ • Though the details of these environments differ, the • A program will always do what we tell it to do, not what basic compilation and execution process is we meant to tell it to do essentially the same 26 Errors Errors • A program can have three types of errors • Compile Time • The compiler will find syntax errors and other basic problems ( compile-time errors ) • Run Time – If compile-time errors exist, an executable version of the program is not created • A problem can occur during program execution, such as trying to divide by zero, which causes a program to • Logical terminate abnormally ( run-time errors ) • A program may run, but produce incorrect results, perhaps using an incorrect formula ( logical errors ) 28 7

  8. Basic Program Development Problem Solving • The purpose of writing a program is to solve a problem Edit and save program • Solving a problem consists of multiple activities: errors – Understand the problem errors – Design a solution Compile program – Consider alternatives and refine the solution – Implement the solution – Test the solution Execute program and evaluate results • These activities are not purely linear – they overlap and interact Problem Solving Object-Oriented Programming • Java is an object-oriented programming language • The key to designing a solution is breaking it • As the term implies, an object is a fundamental entity in a Java down into manageable pieces program • Objects can be used effectively to represent real-world entities • When writing software, we design separate • We try to define all our data as objects, and define programs to work pieces that are responsible for certain parts of on those objects the solution • For instance, an object might represent a particular employee in a company • An object-oriented approach lends itself to this • Each employee object handles the processing and data kind of solution decomposition management related to that employee • We will dissect our solutions into pieces called objects and classes 8

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend