COMS W1004 Introduction to Computer Science June 3, 2009.

Slides:



Advertisements
Similar presentations
COMS W1004 Introduction to Computer Science May 30, 2008.
Advertisements

IT151: Introduction to Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
Primitive Data Types and Operations. Introducing Programming with an Example public class ComputeArea { /** Main method */ public static void main(String[]
COMS W1004 Introduction to Computer Science June 15, 2009.
How to Create a Java program CS115 Fall George Koutsogiannakis.
COMS W1004 Introduction to Computer Science June 1, 2009.
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
If statements Chapter 3. Selection Want to be able to do a statement sometimes, but not others if it is raining, wear a raincoat. Start first with how.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Introduction to Java Java SE 8 for Programmers Paul Deitel Harvey Deitel Deitel Developer Series 2014.
CS0007: Introduction to Computer Programming Scope, Comments, Code Style, Keyboard Input.
From BlueJ to NetBeans SWC 2.semester.
Simple Programs from Chapter 2 Putting the Building Blocks All Together (corresponds with Chapter 2)
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
1 Introduction to Java Brief history of Java Sample Java Program Compiling & Executing Reading: => Section 1.1.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
Lecture 2: Classes and Objects, using Scanner and String.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Computer Programming 2 Lab(1) I.Fatimah Alzahrani.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Program Flow Program Flow follows the exact sequence of listed program statements, unless directed otherwise by a Java control structure.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
First Programs CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Can we talk?. In Hello World we already saw how to do Standard Output. You simply use the command line System.out.println(“text”); There are different.
CSci 111 – computer Science I Fall 2014 Cynthia Zickos WRITING A SIMPLE PROGRAM IN JAVA.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
More About Objects and Methods Chapter 5. Outline Programming with Methods Static Methods and Static Variables Designing Methods Overloading Constructors.
SE-1010 Dr. Mark L. Hornick 1 Java Programming Basics.
Anatomy.1 Anatomy of a Class & Terminology. Anatomy.2 The Plan Go over MoveTest.java from Big Java Basic coding conventions Review with GreeterTest.java.
Working With Objects Tonga Institute of Higher Education.
CS 46B: Introduction to Data Structures June 9 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak
Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Today: –Review declaration, implementation, simple class structure. –Add an exception class and show.
Announcements Quiz 1 Next Monday. int : Integer Range of Typically –2,147,483,648 to 2,147,483,647 (machine and compiler dependent) float : Real Number.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
CS12230 Introduction to Programming Lecture 6-2 –Errors and Exceptions 1.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
CS116 COMPILER ERRORS George Koutsogiannakis 1. How to work with compiler Errors The Compiler provide error messages to help you debug your code. The.
Martin T. Press.  Main Method and Class Name  Printing To Screen  Scanner.
COP 2551 Introduction to Object Oriented Programming with Java Topics –Introduction to the Java language –Code Commenting –Java Program Structure –Identifiers.
11 ITI 1120 Lab # 2 Contributors: G. Arbez, M. Eid, D. Inkpen, A. Williams, D. Amyot.
Jeopardy $100 VariablesErrorsLoops Classes and Objects Program Structure $200 $300 $400 $500 $400 $300 $200 $100 $500 $400 $300 $200 $100 $500 $400 $300.
Topics for today: 1.Comments 2.Data types 3.Variable declaration.
Eastside Robotics Alliance / Newport Robotics Group 1 T/Th, 6:30 – 8:30 PM Big Picture School Day 3 · 10/9/2014.
The Essentials of a Java Program JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,
Lecture 7 D&D Chapter 7 & 8 Composite Classes and enums Date.
Lecture 2 D&D Chapter 2 & Intro to Eclipse IDE Date.
Chapter 2 Basic Computation
Chapter 3 GC 101 Java Fundamentals.
Chapter 2 Basic Computation
Scope, Comments, Code Style, Keyboard Input
Chapter 3 Introduction to Classes, Objects Methods and Strings
Chapter 2 Edited by JJ Shepherd
Introduction to Classes and Methods
MSIS 655 Advanced Business Applications Programming
Documentation and Style
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
Object Oriented Programming in java
Unit 3: Variables in Java
Use a variable to store a value that you want to use at a later time
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

COMS W1004 Introduction to Computer Science June 3, 2009

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

Today Java review Programming environments –Reading: Big Java sections Common programming errors In-class programming assignment Homework #2

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

Programming Environments Eclipse: NetBeans: JEdit: JCreator:

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!

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.

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

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!

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.

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.

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!

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

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.

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

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! 