Top Banner
Start of every class Start up DrJava Open class web site with browser Read entire class entry Download indicted files Try to figure out why the picture and title for the day are appropriate
29

Comments are for people Header comments supply basic information about the artifact.

Dec 29, 2015

Download

Documents

Blaze Garrett
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Comments are for people Header comments supply basic information about the artifact.

Start of every class Start up DrJava

Open class web site with browser

Read entire class entry

Download indicted files

Try to figure out why the picture and title for the day are appropriate

Page 2: Comments are for people Header comments supply basic information about the artifact.

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

Page 3: Comments are for people Header comments supply basic information about the artifact.

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

Comments are for people

Header comments supply basic information about the artifact

Page 4: Comments are for people Header comments supply basic information about the artifact.

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

Comments also used to describe class elements

Page 5: Comments are for people Header comments supply basic information about the artifact.

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

Whitespace is also for people

Blank lines make elements stand out

Page 6: Comments are for people Header comments supply basic information about the artifact.

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

Indentation is a form of whitespace

Indentation is used to indicate that what follows is a part of what proceeded

Page 7: Comments are for people Header comments supply basic information about the artifact.

Indentation is a form of whitespace

Indentation is used to indicate that what follows is a part of what proceeded

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

Page 8: Comments are for people Header comments supply basic information about the artifact.

Keywords are reserved lowercase words that have special meaning

public – what follows is shareable

class – program or object definition

static – not part of an object definition

void – method does not return a value

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

Page 9: Comments are for people Header comments supply basic information about the artifact.

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

Name of the class

A Java name must be an identifier

Java has syntax rules for stating what is a valid name; e.g., identifiers begin with letter and can be followed letters and numerals

Page 10: Comments are for people Header comments supply basic information about the artifact.

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

To encourage program understanding style rules give name understanding

Convention to capitalize the first letter in a class name

General convention to capitalize successive words in a name

Page 11: Comments are for people Header comments supply basic information about the artifact.

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

PrintQuote, main, String, args, System, out, and println are all names

Convention that identifiers not indicating a class begin with a lower case letter

Page 12: Comments are for people Header comments supply basic information about the artifact.

Braces delimit a class definition

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

Page 13: Comments are for people Header comments supply basic information about the artifact.

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

Braces delimit a block of code

Page 14: Comments are for people Header comments supply basic information about the artifact.

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

A program begins executing the code in method main()

Method main() must be public, static, and void

Page 15: Comments are for people Header comments supply basic information about the artifact.

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

Every method has a parameter list following its name.

The list is contained with a pair of parentheses.

For some methods, the list is empty

Page 16: Comments are for people Header comments supply basic information about the artifact.

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

Method main() takes a single parameter of type String[]

Everybody who is anybody calls that parameter, args

Page 17: Comments are for people Header comments supply basic information about the artifact.

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

Following the parameter list is the body of the method

The method body lists the statements (i.e., actions) it is to perform when invoked (started up)

Page 18: Comments are for people Header comments supply basic information about the artifact.

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

The statements are performed from top to bottom

Page 19: Comments are for people Header comments supply basic information about the artifact.

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

The statements are performed from top to bottom

Page 20: Comments are for people Header comments supply basic information about the artifact.

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

Because statements are allowed in general to span multiple lines an indicator is needed for separating statements from one another

Java statements are terminated with a semicolon

Page 21: Comments are for people Header comments supply basic information about the artifact.

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

The dot is the selection operator

Page 22: Comments are for people Header comments supply basic information about the artifact.

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

Sometimes multiple selecting is needed to get a hold of the desired component

Page 23: Comments are for people Header comments supply basic information about the artifact.

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

System is the name of a class library whose elements are automatically available to a program

Page 24: Comments are for people Header comments supply basic information about the artifact.

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

The System library has an element named out

out represents an object configured to be associated with your display

Page 25: Comments are for people Header comments supply basic information about the artifact.

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

out has a println() behavior

println() is a method

println() displays text to its display

Page 26: Comments are for people Header comments supply basic information about the artifact.

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

println() displays the value of its argument

Page 27: Comments are for people Header comments supply basic information about the artifact.

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

This use of println() says to print the literal string ”I’m never going to the Louvre again.” to its display

A literal string is a sequence of characters within a pair of the double-quote characters

Page 28: Comments are for people Header comments supply basic information about the artifact.

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

This use of println() says to print the literal string ”-- Joanne Cohoon” to its display

Page 29: Comments are for people Header comments supply basic information about the artifact.

// author: J. P. Cohoon

// email id: jpc

// purpose: print text

public class PrintQuote {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( "I’m never going to the Louvre again." );

System.out.println( "-- Joanne Cohoon." );

}

}

A program terminates when all of the statements in method main() are completed