1 / 16

COMS W1004 Introduction to Computer Science

Learn about programming environments, such as Eclipse and NetBeans, and how to deal with common compiler errors in Java programming. Includes information on coding conventions and a reminder about upcoming homework.

rsantos
Download Presentation

COMS W1004 Introduction to Computer Science

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COMS W1004Introduction to Computer Science June 3, 2009

  2. Last Time • More object-oriented programming • Methods • Constructors • Implementing Java classes • Java library • String class • Math static methods • System.out.println

  3. Today • Java review • Programming environments • Reading: Big Java sections 1.5-1.7 • Common programming errors • In-class programming assignment • Homework #2

  4. Programming Environments • Generally contain an editor where you write your code • Syntax highlighting of keywords, etc. • Usually contain a compiler to compile code • Sometimes compilation is automatic • Also allow you to execute your code • Debuggers for troubleshooting

  5. Programming Environments • Eclipse: http://www.eclipse.org • NetBeans: http://www.netbeans.org • JEdit: http://www.jedit.org • JCreator: http://www.jcreator.com

  6. Columbia computing facilities • 251 Mudd (aka 251 Engineering Terrace) • NetBeans, but not Eclipse • Usually open 9am-5pm, closed weekends • 213 Butler • Usually open until 9pm, closed Sundays • Support staff at the labs are not TAs!

  7. Dealing with compiler errors • If you get a whole bunch of errors, sometime fixing the first error will make the others go away. • 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.

  8. Common programming errors • These are some of the common errors that students encounter when they’re just starting • Note that these are the error messages you’d see in Eclipse; other programming environments provide slightly different wording

  9. Class name and file name Error: class BankAccont must be defined in its own file Code: public class BankAccont { • This means that the name of the class does not match the name of the file. Remember, they MUST be the same, including capitalization!

  10. Cannot resolve type Error: Scanner cannot be resolved to a type Code: Scanner scan = new Scanner(System.in); • Any error that involves "cannot be resolved" means that the compiler doesn't know what that symbol (which can be a variable or a class name) refers to. • In the code, if the name Scanner is underlined, 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.

  11. Constructor is undefined Error: The constructor Scanner() is undefined Code: Scanner scan = new Scanner(); • This time, the method is “undefined” because it doesn’t have the right arguments. • It probably means that you forgot to put "System.in" inside the parentheses.

  12. Method is undefined Error: Method nextdouble is undefined for type Scanner Code: double x = scan.nextdouble(); • Yet another “undefined" 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!

  13. Duplicates Error: Duplicate local variable x Code: int x = 9; • This means there’s already a variable called x in your code • Remember, you only need to declare (state the type of) each variable the first time you use it

  14. Misleading errors Error: Syntax error on sum, delete this token Code: System.out.println("The sum is " sum); • In this case, the error is rather misleading, as it thinks “sum” is there inadvertently. • However, as you can see, the error is actually that you need a plus sign between the two things you are concatenating.

  15. Java Coding Conventions • Class names should start with an upper-case letter and use camel caps: BankAccount • Attribute and method names should start with a lower-case letter and use camel caps: accountBalance, getBalance • You should average about one single-line comment for every 2-3 lines of code • Use indentation

  16. Homework #2 • Due next Monday, June 8 at beginning of class • Theory • Paper submission only • Programming • Electronic submission and paper submission • Can I have an extension? NO! 

More Related