DOC PREVIEW
UVA CS 101 - Java Basics

This preview shows page 1-2-3-4-5-6-38-39-40-41-42-78-79-80-81-82-83 out of 83 pages.

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

Unformatted text preview:

Java basicsDisplayForecast.javaIndentationGood whitespacingBad whitespacingA whitespacing aside: IOCCCSlide 7IdentifiersKeywordsCapitalizationStatementsVariablesDefining variablesMore on variablesPrimitive variable assignmentSlide 17Slide 18Printing variablesSlide 20Variable initializationYou can only declare variables onceToday’s demotivatorsTypesPrimitive variable typesPrimitive real (floating-point) typesPrimitive integer typesSlide 28Increment and decrement operatorsWhy C++ was named C++Primitive character typePrimitive boolean typeVariables must be declared before useA bit of humor: 1989 Computer AdvertisementSlide 35ConstantsExpressionsQuestion on expressionsJava operatorsSlide 40System.out.printlnSlide 42Removing your car in snow…MethodsFunctionsSlide 46System.out.println()print() vs. println()Escape sequencesSlide 51New York DriversProgram ExamplesExample program: temperature conversionProgram demo…ComputationProgram outline for BMI.javaBMI.java: define constantsBMI.java: personal characteristicsBMI.java: convert to metric equivalentsWhat we wish computers could doBMI.java: perform BMI calculationBMI.java: display resultSlide 64Slide 65Common program elementsCarved egg shells (done via laser)Scanner usageInteractive programsReading in a value from the keyboardReading in more values from the keyboardScanner usage exampleSlide 73How to make Java work with the Scanner classSlide 75BMI CalculatorInteractive program for BMISlide 78Slide 79Slide 80Scanner APIWhy you should get the extended warrantyCastingSlide 84More casting examples1Java basicsChapter 2Spring 2006CS 101Aaron Bloomfield2DisplayForecast.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,


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?