DOC PREVIEW
UW-Madison COMPSCI 302 - CS 302 Lecture Notes

This preview shows page 1-2-3-4 out of 11 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Assignments- Read for next week: 4.1-4.9- Fri 9/17 6:00 PM CodeWarrior Tutorialo Questions?- Fri 9/17 6:00 PM Assignment 0o UML Diagrams Differentiating class and instance stuff in the class: underline class stuff (opposite of object diagram name) Representing methods in the class Arguments Return valueso Questions?- Mon 9/20 11:58 PM CodeLab #2o Questions?- Fri 9/24 11:58 PM CodeLab #3o Should be able to do some; will cover next week: Infer class declaration from sample programs and CodeWarrior Declaring constants Standard inputo Distinction between “expression” and “statement” o Questions?Review: 1.5- What are the five stages of the software life cycle?o Analysis, Design, Coding, Testing, Operation- When does debugging occur?o Testing and (unfortunately) OperationCS 302 Lecture 6 091712.1 The First Java Program- Reference (object) and primitive (numerical) data types- Steps to use an object (how different from primitives?)o Declareo Createo Send messages- Declarationo Memory diagram: primitive versus reference- Creationo Declaration does not create objecto May use same identifier to refer to different instances of the same class at different timeso Memory diagram: primitive versus reference Distinction clear? Note that both always use same size for variable itself, but that the amount of memory used by the object can vary widely (even among objects of the same class; e.g. lists: different people’s favorite numbers)o Assigning one object variable to another Does not create new object Means having two names for the same thing SharingCS 302 Lecture 6 09172- Message sendingo Can only do after the object has been createdo Calling a method Message usually refers externally Method usually refers internally- What types are arguments to setSize and setTitle?o New type for setVisible: booleano setSize refers to pixelsCS 302 Lecture 6 091732.2 Program Components- Three parts to all Java programs- Commentso Computer ignoreso Not necessary for executiono Documentation Help programmers understand program State purpose of program ID/explain/summarize code blocks Note modificationso Disable sections of code during testing- Comment marker: example code- Single-line commento Extends from marker to end of lineo Example- Javadoc comments: later- Header comment: exampleso CodeWarrior Tutorialo Example program- Import: use pre-defined classes whenever possible- Packages: Java comes with many- Package hierarchyo Subpackageso Multiple dots- Import statement o Avoids use of fully qualified nameo Allows use of class name by itselfo Does not copy classes into your program- StarCS 302 Lecture 6 09174o Import all classes in a packageo Conventional, but can input by name specifically- Class declarationo “Class” reserved wordo Exampleo Class members Data values Methods Exampleso Main class Every program must include at least one In CodeWarrior, designate by giving it the same name as the file Exampleo Refer to whole application as “<main class> application”; Example- Method declarationo Exampleo Modifiers State which kind of method Manyo Return type states the type of the data value that the method returnsCS 302 Lecture 6 09175- Completely different programs can be created readily by using different objectsCS 302 Lecture 6 091762.3 Edit-Compile-Run Cycle- Steps to execute program- Require more specifics to actually do in particular development tool- Use <main class name>.java for file name- Compilationo May need to place source in project and compile thato Bytecode file: file containing bytecodeo Compilation errors easiest type to correct- Executiono Bytecode is system independento Occurs on interpreter System independent Java Virtual Machine (JVM) Must have specialized for each systemo Errors detected by interpreterCS 302 Lecture 6 091772.4 Simple Java Standard Classes- Right now, learn to use some existing classes- Later, learn to define own- Java APIo Application programming interfaceo Documentation for the standard classes- JoptionPane for outputo Display computed result to usero Window types (in GUI environment) General purpose frame, e.g. JFrame Special purpose dialog- JDialog- Method showMessageDialogo First argument Controlling frame object Dialog positioned at center of this, or, if no arg, of screeno Creates instance of JDialog internallyo Class method Don’t need to create object to use it Just use <class name>.<class method>o Example: display “What’s\nup?” in JFrame jf2CS 302 Lecture 6 09178- Stringo Explicit use of new optional; draw mem diagramo Substring First argument- Beginning position- Count from 0- Is displayed Second argument- End position- Is not displayed Creates new string Original string left intact Generates error if given illogical arguments Examples- “together”o 0-2= “to”o 2-5= “get”o 5-8= “her”- “michelle”: 3-7= “hell”- You think of oneo Length Return # of characters in a String Exampleso IndexOf Locate index position of substring within another string Returns position of first char of substring Returns -1 if substring not found Case-sensitiveCS 302 Lecture 6 09179 Returns first occurrence if multiple exists- Dateo Time instanceo Millisecond precisiono Automatically set to time created (from OS)o toString method converts to human-readable: Sat Apr 20 15:05:18 PDT 2002o internally represented as time since epoch (Jan 1, 1970 00:00:00 GMT)o Use GregorianCalendar for real dates- SimpleDateFormato Change display format of Dateo Pass formatiting string when create instance of SimpleDateFormato Formatting string case-sensitiveSimpleDateFormat simpleDF;simpleDF = new SimpleDateFormat(“…”);System.out.println(simpleDF.format(new Date()));CS 302 Lecture 6 091710- JoptionPane for inputo showInputDialog methodo Access input by assigning return result to String variableo Returns null if cancel clickedo Returns empty string if nothing entered & OK clicked2.5 Sample Development- Get into the habit of developing according to the software life cycle stages (even though not strictly necessary for small programs)- Map out overall plano ID classes necessaryo ID implementation steps to followo Outline program logico Write design document- Consider design alternativeo Better depends on metrico Always developing for usersMonday 9-14- CodeLab #2 Due- More Chapter 2- If finish, review Chapter 3 so farCS 302


View Full Document

UW-Madison COMPSCI 302 - CS 302 Lecture Notes

Download CS 302 Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view CS 302 Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view CS 302 Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?