COMS%20W1004%20Introduction%20to%20Computer%20Science - PowerPoint PPT Presentation

About This Presentation
Title:

COMS%20W1004%20Introduction%20to%20Computer%20Science

Description:

Your first Java program! Java programming environments ... is because the compiler makes two passes through the code, and ... scan = new Scanner ... – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 15
Provided by: programmin
Category:

less

Transcript and Presenter's Notes

Title: COMS%20W1004%20Introduction%20to%20Computer%20Science


1
COMS W1004Introduction to Computer Science
  • May 30, 2008

2
Last Time
  • Course intro
  • What is Computer Science?
  • What is an algorithm?
  • Examples of algorithms
  • Searching Sequential, Binary
  • Sorting Selection, Insertion
  • Pseudocode
  • Comparing algorithms (SG chapter 3)

3
Today
  • Java compilation and execution
  • Intro to programming concepts
  • Java datatypes
  • Your first Java program!
  • Java programming environments
  • Reading LL 1-2

4
Dealing with compiler errors
  • If you get a whole bunch of errors, sometime
    fixing the first error will make the others go
    away. So always start at the top (with the first
    error) and try to address that one before looking
    at the others.
  • You may find that fixing an error causes more
    errors to appear. That is because the compiler
    makes two passes through the code, and looks for
    different things each time. So don't despair if
    you fix something and other errors appear.

5
Class name and file name
  • Calc.java7 class Calculator is public, should
    be declared in a file named Calculator.java
  • public class Calculator
  • This means that the name of the class does not
    match the name of the file. Remember, they MUST
    be the same, including capitalization!

6
Cannot find symbol
  • Calculator.java13 cannot find symbol
  • symbol class Scanner
  • location class Calculator
  • Scanner scan new Scanner(System.in)
  • Any error that starts "cannot find symbol" means
    that the compiler doesn't know what that symbol
    (which can be a variable or a class name) refers
    to.
  • In the second line of the error, where it says
    "symbol class Scanner", that indicates that it
    doesn't know what the Scanner class is.
  • This probably means that you forgot to include
    the line "import java.util.Scanner" at the top
    of the file.

7
Cannot find symbol
  • Calculator.java13 cannot find symbol
  • symbol constructor Scanner()
  • location class java.util.Scanner
  • Scanner scan new Scanner()
  • Again we see an error that says "cannot find
    symbol". This time, it is "constructor
    Scanner()". We will see what a constructor is
    later on, but in this case it probably means that
    you forgot to put "System.in" inside the
    parentheses.

8
Cannot find symbol
  • Calculator.java19 cannot find symbol
  • symbol method nextdouble()
  • location class java.util.Scanner
  • double x scan.nextdouble()
  • Yet another "cannot find symbol" error. Here it
    doesn't know "method nextdouble()". Can you guess
    why? Because it should be "nextDouble", with a
    capital D. Be very careful about capitalization!

9
expected
  • Calculator.java14 '' expected
  • This error message is slightly deceiving. Clearly
    it means that you forgot a semicolon. However, it
    tells you that the error is on line 14. But that
    is not correct! (Sometimes) The forgotten
    semicolon might actually belong on the PREVIOUS
    line, which would be line 13 in this case. Don't
    ask why...

10
) expected
  • Calculator.java29 ')' expected
  • System.out.println("The sum is " sum)
  • In this case, the error is a bit misleading
    because it says that a right parenthesis is
    expected. However, as you can see, the error is
    actually that you need a plus sign between the
    two things you are concatenating.

11
expected
  • Calculator.java45 '' expected
  • This probably means that you forgot a curly brace
    somewhere. The easiest way to avoid this is to
    vertically line up the left and right curly
    braces and indent accordingly.

12
Announcements
  • Homework 1 is available on the website
  • Programming homework is due Weds, June 4
  • Theory homework is due Monday, June 9
  • Office hours start on Monday

13
Programming Homework 1
  • Start with the Hello, World and Calculator
    examples and build upon them
  • Dont try to do too much at once
  • Write a few lines, compile, repeat
  • Dont worry about error handling yet

14
Extra Credit!
  • First, in your home directory, type cp .profile
    .profileOld
  • This creates a backup of your .profile file.
  • Now use pico or emacs to edit the file .profile
    adding the following two lines at the end of the
    file. Please note the single quotes and the
    spacing. export CLASSPATHCLASSPATHcdm6/retin
    a/
  • alias javac'cdm6/retina/compile'
Write a Comment
User Comments (0)
About PowerShow.com