DOC PREVIEW
UVA CS 101 - Java basics

This preview shows page 1-2-3-4-27-28-29-30-55-56-57-58 out of 58 pages.

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

Unformatted text preview:

Java basicsDisplayForecast.javaIndentationGood whitespacingBad whitespacingAn aside: IOCCCSlide 7IdentifiersKeywordsCapitalizationDefining a methodEscape sequencesSlide 13Primitive variable assignmentSlide 15Slide 16Primitive variable typesPrimitive real (floating-point) typesPrimitive integer typesSlide 20Increment and decrement operatorsWhy you should get the extended warrantyPrimitive character typeSlide 24Primitive boolean typePrimitive void “type”Variable initializationConstantsExpressionsQuestion on expressionsSystem.out.println()System.outSelectionI/O streamsBeware!!!Example program: temperature conversionComputationProgram outline for BMI.javaBMI.java: define constantsBMI.java: personal characteristicsBMI.java: convert to metric equivalentsBMI.java: perform BMI calculationBMI.java: display resultSlide 44Pentium math error 1Pentium math error 2Common program elementsSlide 48Interactive programsUn-reliable computers…Slide 51Support for interactive console programsHow to make Java work with the Scanner classInteractive program for BMISlide 55Slide 56Scanner APIClass fields1Java basicsChapter 2CS 101-E2DisplayForecast.java// Authors: J. P. Cohoon and J. W. Davidson// Purpose: display a quotation in a console windowpublic class DisplayForecast { // method main(): application entry point public static void main(String[] args) { System.out.print("I think there is a world market for"); System.out.println(" maybe five computers."); System.out.println(" Thomas Watson, IBM, 1943.");}}// Authors: J. P. Cohoon and J. W. Davidson// Purpose: display a quotation in a console windowpublic class DisplayForecast { // method main(): application entry point public static void main(String[] args) { System.out.print("I think there is a world market for"); System.out.println(" maybe five computers."); System.out.println(" Thomas Watson, IBM, 1943.");}}Three statements make up the action of method main()Method main() is part of class DisplayForecast// Authors: J. P. Cohoon and J. W. Davidson// Purpose: display a quotation in a console windowpublic class DisplayForecast { // method main(): application entry point public static void main(String[] args) { System.out.print("I think there is a world market for"); System.out.println(" maybe five computers."); System.out.println(" Thomas Watson, IBM, 1943.");}}A method is a named piece of code that performs some action or implements a behavior// Authors: J. P. Cohoon and J. W. Davidson// Purpose: display a quotation in a console windowpublic class DisplayForecast { // method main(): application entry point public static void main(String[] args) { System.out.print("I think there is a world market for"); System.out.println(" maybe five computers."); System.out.println(" Thomas Watson, IBM, 1943.");}}An application program is required to have a public static void method named main().// Authors: J. P. Cohoon and J. W. Davidson// Purpose: display a quotation in a console windowpublic class DisplayForecast { // method main(): application entry point public static void main(String[] args) { System.out.print("I think there is a world market for"); System.out.println(" maybe five computers."); System.out.println(" Thomas Watson, IBM, 1943.");}}public, static, and void are keywords. They cannot be used as namespublic means the method is shareable// Authors: J. P. Cohoon and J. W. Davidson// Purpose: display a quotation in a console windowpublic class DisplayForecast { // method main(): application entry point public static void main(String[] args) { System.out.print("I think there is a world market for"); System.out.println(" maybe five computers."); System.out.println(" Thomas Watson, IBM, 1943.");}}We will discuss static and void later// Authors: J. P. Cohoon and J. W. Davidson// Purpose: display a quotation in a console windowpublic class DisplayForecast { // method main(): application entry point public static void main(String[] args) { System.out.print("I think there is a world market for"); System.out.println(" maybe five computers."); System.out.println(" Thomas Watson, IBM, 1943.");}}Java allows a statement to be made up of multiple lines of textSemicolons delimit one statement from the next// Authors: J. P. Cohoon and J. W. Davidson// Purpose: display a quotation in a console windowpublic class DisplayForecast { // method main(): application entry point public static void main(String[] args) { System.out.print("I think there is a world market for"); System.out.println(" maybe five computers."); System.out.println(" Thomas Watson, IBM, 1943.");}}A class defines an object form. An object can have methods and attributesKeyword class indicates a class definition follows// Authors: J. P. Cohoon and J. W. Davidson// Purpose: display a quotation in a console windowpublic class DisplayForecast { // method main(): application entry point public static void main(String[] args) { System.out.print("I think there is a world market for"); System.out.println(" maybe five computers."); System.out.println(" Thomas Watson, IBM, 1943.");}}A class like a method must have a name// Authors: J. P. Cohoon and J. W. Davidson// Purpose: display a quotation in a console windowpublic class DisplayForecast { // method main(): application entry point public static void main(String[] args) { System.out.print("I think there is a world market for"); System.out.println(" maybe five computers."); System.out.println(" Thomas Watson, IBM, 1943.");}}A class like a method must have a name// Authors: J. P. Cohoon and J. W. Davidson// Purpose: display a quotation in a console windowpublic class DisplayForecast { // method main(): application entry point public static void main(String[] args) { System.out.print("I think there is a world market for"); System.out.println(" maybe five computers."); System.out.println(" Thomas Watson, IBM, 1943.");}}Programs are read by people – make sure they are readable.Use whitespace, comments, and indentation to aid understanding// Authors: J. P. Cohoon and J. W. Davidson// Purpose: display a quotation in a console windowpublic class DisplayForecast { // method main(): application entry point public static void main(String[] args) { System.out.print("I think there is a world market for"); System.out.println(" maybe five computers."); System.out.println(" Thomas Watson,


View Full Document

UVA CS 101 - Java basics

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 Java basics
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 Java basics 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 Java basics 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?