© 2007 Lawrenceville Press Slide 1 Chapter 3 Classes and Objects 1. How is a class different from an object?

Slides:



Advertisements
Similar presentations
L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
Advertisements

Classes  All code in a Java program is part of a class  A class has two purposes  Provide functions to do work for the programmer  Represent data.
IT151: Introduction to Programming
© 2007 Lawrenceville Press Slide 1 Chapter 3 Classes and Objects.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
Your First Java Program: HelloWorld.java
 C++ programming facilitates a disciplined approach to program design. ◦ If you learn the correct way, you will be spared a lot of work and frustration.
Java Intro. A First Java Program //The Hello, World! program in Java public class Hello { public static void main(String[] args) { System.out.println("Hello,
 2003 Prentice Hall, Inc. All rights reserved. Customized by Sana Odeh for the use of this class. 1 Introduction to Computers and Programming in JAVA.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.3 The Class String.
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Java Applications & Program Design
2.2 Information on Program Appearance and Printing.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Android How to Program, 2/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Comments are for people Header comments supply basic information about the artifact.
C# B 1 CSC 298 Writing a C# application. C# B 2 A first C# application // Display Hello, world on the screen public class HelloWorld { public static void.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class.
Chapter 2: Java Fundamentals
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Output in Java Hello World!. Structure of a Java Program  All Java files in ICS3U1 have the following structure: class HelloWorld { }  Notice the open.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
ECE 122 Feb. 1, Introduction to Eclipse Java Statements Declaration Assignment Method calls.
Chapter 3 Introduction To Java. OBJECTIVES Packages & Libraries Statements Comments Bytecode, compiler, interpreter Outputting print() & println() Formatting.
Anatomy of a Java Program. AnotherQuote.java 1 /** A basic java program 2 * 3 Nancy Harris, James Madison University 4 V1 6/2010.
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,
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Strings See Chapter 2 u Review constants u Strings, concatenation and repetition 1.
Java FilesOops - Mistake Java lingoSyntax
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
Chapter 2 print / println String Literals Escape Characters Variables / data types.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
Introducing Java Chapter 3 Review. Why Program in Java? Java, is an object-oriented programming language. OOP languages evolved out of the need to better.
1 CSE1340 Class 4. 2 Objectives Write a simple computer program in Java Use simple Output statements Understand the different types and uses of comments.
CSC 110 – Intro to Computing - Programming
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Elementary Programming.
Chapter 2 1.What is the difference between print / println 2.What are String Literals 3.What are the Escape Characters for backslash, double quotataions,
1 Structure of Simple C++ Program Chapter 1 09/09/13.
Chapter 3 Introducing Java. Objectives and Goals 1. Define terminology associated with object- oriented programming. 2. Explain why Java is a widely used.
SUMMARY OF CHAPTER 2: JAVA FUNDAMENTS STARTING OUT WITH JAVA: OBJECTS Parts of a Java Program.
© 2006 Lawrenceville Press Slide 1 Chapter 4 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Introducing Java Chapter 3. Why Program in Java? 0 Java was developed by Sun Microsystems. It is a widely used high-level programming language. 0 One.
Lecture 4 – Scanner & Style
Computer Programming Your First Java Program: HelloWorld.java.
Chapter 1.2 Introduction to C++ Programming
Chapter 1 Introduction to Computers, Programs, and Java
Chapter 2, Part I Introduction to C Programming
Chapter 7 Top-Down Development
Introduction to Scripting
Intro to Java.
Introduction Java Chapter 3.
Statements, Comments & Simple Arithmetic
Programming Vocabulary.
Chapter 3 Classes and Objects
MSIS 655 Advanced Business Applications Programming
Chapter 2: Java Fundamentals
Java Intro.
Chapter 2 Create a Chapter 2 Workspace Create a Project called Notes
Anatomy of a Java Program
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
Introduction to Java Applications
Java How to Program, 11/e Questions?
© A+ Computer Science - Basic Java © A+ Computer Science -
Presentation transcript:

© 2007 Lawrenceville Press Slide 1 Chapter 3 Classes and Objects 1. How is a class different from an object?

© 2007 Lawrenceville Press Slide 2 Chapter 3 A Java Application /** * The Greeting class displays a greeting */ public class Greeting { public static void main(String[] args) { System.out.println("Hello,world!"); } comment class declaration method statement

© 2007 Lawrenceville Press Slide 3 2. Write the class declaration for a class named Farewell with a method named sayGoodbye with a statement that prints the word “bye” with a comment that contains your name

© 2007 Lawrenceville Press Slide 4 Chapter 3 Executing a Java Application public class Greeting public static void System.out.printl } source code 03 3b ff f abytecode... c cilbup Hello,world! b3 30 compiler JVM

© 2007 Lawrenceville Press Slide 5 Chapter 3 Escape Sequences An escape sequence is a backslash ( \ ) followed by a symbol that together represent a character. Commonly used escape sequences: \n newline \t tab (8 spaces) \\ backslash \" double quotation mark

© 2007 Lawrenceville Press Slide 6 Chapter 3 The format() Method  A method in the System class  Used to control the way output is displayed  Requires a format string and an argument list  The format string specifier takes the form: %[alignment][width]s  For example System.out.format("%-6s %4s", "Test1", "90"); displays: Test1 90

© 2007 Lawrenceville Press Slide 7 Chapter 3 Code Conventions  An introductory comment should begin a program.  Package names should begin with a lowercase letter and then an uppercase letter should begin each word within the name.  Class names should be nouns and begin with an uppercase letter and an uppercase letter should begin each word within the name.  A comment block should be included before each class.

© 2007 Lawrenceville Press Slide 8 Chapter 3 Code Conventions (con't)  Comments should not reiterate what is clear from the code.  Statements in a method should be indented.  An open curly brace ( { ) should be placed on the same line as the class or method declaration, and the closing curly brace ( } ) should be on a separate line and aligned with the class or method declaration.

© 2007 Lawrenceville Press Slide 9 Chapter 3 Flowchart Symbols input/output start/end

© 2007 Lawrenceville Press Slide 10 Chapter 3 The Triangle Flowchart