DOC PREVIEW
UVA CS 101 - Review for Exam 1

This preview shows page 1-2-3-19-20-38-39-40 out of 40 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 40 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 40 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 40 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 40 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 40 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 40 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 40 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 40 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 40 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Review for Exam 1Today’s classChapter 1IntroComputer organizationSoftwareCompilationTerminologyOOP TerminologyProblem solving stepsChapter 2Readable programsIdentifiersComputer bugsJava classesJava methodsProgram executionMisc stuffEscape sequencesPrimitive variable typesSymbolic names vs. literal valuesReferences and variablesMathExpressionsOverflowOperatorsCastingScanner classReferencesStringsString methodsRectangle classChapter 3Logical expressionsLogical operatorsEqualityOrderingIf statementsSwitchesMiscReview for Exam 1Spring 2007CS 101/CS 101-E2Today’s classAn overview of chapters 1-3Stop me if you want me to go over something in more detail!33Chapter 1Chapter 14IntroComputers think in bits (1 or 0)00101001 = 81Eight bits per byte1024 bytes = 1 Kb1024 Kb = 1 Mb1024 Mb = 1 Gb5Computer organizationCPU = brainMicroprocessor: computer on a single chipNetwork: when two or more computers are plugged into one another6SoftwareOS: the program that manages a computer’s resourcesProgram: a sequence of instructions that performs some taskPerforming an instruction is called “executing” an instruction7CompilationTranslator: translates a program from one language to anotherMachine language: the ones and zeros that a computer understandsA low level language!Compiler: a translator which typically translates a high-level language into a low-level oneJava is a high-level languageJava’s compiler translates Java code into bytecodeBytecode is like machine language, but not tied to a specific machineA Java bytecode interpreter is used to execute the bytecodeCalled a Java Virtual Machine (JVM)8TerminologyAbstractionSimilar objects exhibit similar behaviorThe ability to do the same “thing” on many objectsEncapsulationNot revealing how the method does it’s workConsider String.substring()ModularityDividing code into smaller pieces (modules), each one of which is easier to code9OOP TerminologyOOP (Object-Oriented Programming) languages:Abstract things into the class’ methodsEncapsulate code inside the class’ methodsUse additional methods for modularityA (primitive) type is the basic unit of storage in JavaA type is a template for a variableA class is composed of types (or other classes) as well as methodsA class is a template for an objectCreating a variable/object from a type/class is called instantiating the type/class10Problem solving stepsAnalysisWhat needs to be done?DesignHow is it going to be done?ImplementationMake it so!TestingDoes it work correctly?1111Chapter 2Chapter 212Readable programsComments are English textHave a // before them in a Java file/* *//** */Blank lines make a program easier to readIndentation helps humans identify which code is within the methodKeywords have special meanings in JavaExamples: int, double, class, static, public13IdentifiersIdentifiers: programmer-defined namesFor classes, variables, methods, etc.Cannot be a keywordMust start with a letter (or _ or $)Can contain numbers also (but not as the first character)Good identifiers: radius, width, positionBad identifiers: x, y, q, the_really_really_long_variable_name_hi_mom14Computer bugsA bug is an error in the programTo debug is to remove bugs15Java classesThe class keyword is used to start a class declarationCan be made public (for this course, always do so)A class is a “template” for an objectJust as a type is a “template” for a variable16Java methodsAll methods have the following syntax:modifers type name ( parameters ) { statements }Propertiesof themethodTypethat itreturnsA namefor themethodAny number(including zero)of parametersThe body ofthe method(can be empty)public static void main (String[] args) { ... }17Program executionJava starts executing a program at the beginning of the main() methodBraces { } are used to specify where a method begins and endsA statement ends when a semicolon is encounteredA statement can span multiple lines18Misc stufA literal character string is a sequence of characters enclosed by double quotesSystem is the Java class that allows you to access parts of the computer systemSystem.in: access to the keyboardSystem.out: access to the monitorPeriod is used for selection: Math.roundGiven String s, select a method via: s.substring()An exception is when Java “panics”It means something is wrong19Escape sequencesJava provides escape sequences for printing special characters\b backspace\n newline\t tab\r carriage return\\backslash\" double quote\‘ single quote20Primitive variable typesJava has 8 (or so) primitive types:floatdoublebooleancharbyteshortintlongreal numbersinteger numberstwo values: true and falsea single characterAlso the void “type”Can make a variable final21Symbolic names vs. literal valuesWhich is easier to enter:Math.PI3.141592653589793Entering a symbolic name (i.e. a constant) reduces chances of errorsIt allows for changing the constant later onAre usually final22References and variablesA variable is an actual spot in memory that holds a (primitive type) valueA reference is a memory address that points to another spot in memory where the object isVariables defined in a class are initialized to a default valueVariables defined in a method are not initialized to a default value23MathStandard operators: + - * /Note that / can be either integer division or floating-point division% computes the remainder (aka modulus)Can provide numbers in decimal or scientific notation24ExpressionsEvaluating an expression yields a result and a typeExample: 4/3 yields 1 of type intExample: 3.5*2.0 yields 7.0 of type doubleBinary operator has two operandsExample: 3+4, 6*3, etc.Left one is evaluated firstUnary operator has one operandExample: -3, etc.Operators have precedenceFor example, * and / are evaluated before + and -25OverflowConsider:byte b = 100;b = b * 100;A byte can only hold up to +127This is called overflowJava does not tell you that this happened!Underflow: b -= b*100;26OperatorsAssignment: =Increment (++) and decrement


View Full Document

UVA CS 101 - Review for Exam 1

Documents in this Course
Classes

Classes

53 pages

Recursion

Recursion

15 pages

Iteration

Iteration

88 pages

PLEDGED

PLEDGED

6 pages

Objects

Objects

33 pages

PLEDGED

PLEDGED

11 pages

CS 101

CS 101

42 pages

Classes

Classes

83 pages

Iteration

Iteration

92 pages

Classes

Classes

186 pages

Classes

Classes

208 pages

Hardware

Hardware

21 pages

Arrays

Arrays

70 pages

Load more
Download Review for Exam 1
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 Review for Exam 1 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 Review for Exam 1 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?