Docsity

Java Programming Fundamentals: CSIS 110 Lecture 3 - Prof. Brian F. Hanks, Study notes of Javascript programming

Toggle sidebar
bg1
CSIS 110 โ€“ Lecture 3
Turn in homework
Review
Project DisplayForecast.java
Key elements of the program
- three statements that display the quote
- method main()
oMethod is a named unit of code that performs some action
oEvery Java program must have a main() method
- Main() is a method of the class DisplayForecast
- Class defines the form of an object
oObjects have methods (behaviors)
oObjects may have attributes (data fields or values)
oClass has same name as its file (with same upper/lower case)
- What are comments for?
oComments are for people
oMany people look at programs โ€“ comments are there to help these people
oComputer ignores the comments โ€“ doesnโ€™t affect how the program is
compiled.
- What is the purpose of indenting?
oImprove readability - indicate that statements are components of some
other program element (such as a method)
oLines are indented if they are a component of the preceding material.
oIndent consistently
- What is a keyword?
oKeywords are reserved words that have specific meanings in Java
oExamples: public, class, static, void
oIdentifiers are names we use to refer to methods, classes, variables
oIs main a keyword?
๏‚งmain is not a keyword โ€“ it is an identifier (the name of a method).
- Who remembers what the identifier rules are?
oMust begin with alphabetic char, $, or _
oSubsequent chars: alpha, digit, $, or _
oAlpha includes foreign language chars such as pi.
oExamples
- What do the statements that start with 'System.out' do?
oSystem.out represents the standard output stream โ€“ it is associated with the
console. System.out has methods print and println that cause their
parameters to be displayed.
oStatement invokes the method, causing the method to be executed โ€“ i.e. it
performs its actions or behavior
pf3

Partial preview of the text

Download Java Programming Fundamentals: CSIS 110 Lecture 3 - Prof. Brian F. Hanks and more Study notes Javascript programming in PDF only on Docsity!

CSIS 110 โ€“ Lecture 3

Turn in homework Review Project DisplayForecast.java Key elements of the program

  • three statements that display the quote
  • method main() o Method is a named unit of code that performs some action o Every Java program must have a main() method
  • Main() is a method of the class DisplayForecast
  • Class defines the form of an object o Objects have methods (behaviors) o Objects may have attributes (data fields or values) o Class has same name as its file (with same upper/lower case)
  • What are comments for? o Comments are for people o Many people look at programs โ€“ comments are there to help these people o Computer ignores the comments โ€“ doesnโ€™t affect how the program is compiled.
  • What is the purpose of indenting? o Improve readability - indicate that statements are components of some other program element (such as a method) o Lines are indented if they are a component of the preceding material. o Indent consistently
  • What is a keyword? o Keywords are reserved words that have specific meanings in Java o Examples: public, class, static, void o Identifiers are names we use to refer to methods, classes, variables o Is main a keyword? ๏‚ง main is not a keyword โ€“ it is an identifier (the name of a method).
  • Who remembers what the identifier rules are? o Must begin with alphabetic char, $, or _ o Subsequent chars: alpha, digit, $, or _ o Alpha includes foreign language chars such as pi. o Examples
  • What do the statements that start with 'System.out' do? o System.out represents the standard output stream โ€“ it is associated with the console. System.out has methods print and println that cause their parameters to be displayed. o Statement invokes the method, causing the method to be executed โ€“ i.e. it performs its actions or behavior

o System.out.print displays the value of its parameter at the current cursor location. The cursor is left at the end of the printed output. o System.out.println displays the value of its parameter, followed by a new line. That is, the cursor moves to the beginning of the next line

  • What is a String literal โ€“ characters between double quotes o Must be on one line
  • Escape sequences o What if we wanted quotation marks around the quotation? o \โ€
  • Escape Sequences o Others: \n, \t, \, \โ€™ o Look at PetDisplay.java and TabularDisplay.java Identifier rules o Must begin with alphabetic char, $, or _ o Subsequent chars: alpha, digit, $, or _ o Alpha includes foreign language chars such as pi. o Examples o Java has naming conventions โ€“ subsets of valid identifiers that are used for different things ๏‚ง Classes โ€“ Begin with UpperCase. Words joined together โ€“ use UpperCase for every word ๏‚ง Methods โ€“ Begin with LowerCase. Words joined together โ€“ use UpperCase for all words after the first Simple Computations o We want programs to do more than just print things o Need to do mathematical operations o Body Mass Index ๏‚ง Ratio of weight in Kg / (Height in Meters)^ ๏‚ง Look at BMI.java types o Java has primitive types and reference types o Primitive types are for storing things such as integers, floating point numbers, and characters o Reference types are for more complex things such as Strings, output streams, or bank accounts โ€“ these types are called objects. o double is a primitive type for storing floating point numbers constants o A constant is a symbolic name for a memory location whose value cannot be changed by the program o Before using a constant, we must define it and give it a value o Definition takes this form