Chapter 3 Classes and Objects

Slides:



Advertisements
Similar presentations
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 2 Getting Started with Java.
Advertisements

IT151: Introduction to Programming
University of Palestine software engineering department Introduction to data structures Introduction to java application instructor: Tasneem Darwish.
JAVA BASICS SYNTAX, ERRORS, AND DEBUGGING. GCOC – A.P. Computer Science A College Board Computer Science A Topics Covered Program Design - Read and understand.
© 2007 Lawrenceville Press Slide 1 Chapter 3 Classes and Objects.
Chapter 1 Introduction to JAVA. Why Learn JAVA? Java is one of the fastest growing programming language in the world. Java is one of the fastest growing.
 2005 Pearson Education, Inc. All rights reserved Introduction.
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
 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.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
Java Applications & Program Design
2.2 Information on Program Appearance and Printing.
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.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Week 1 - Friday.  What did we talk about last time?  Our first Java program.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
 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.
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
Chapter 2 part #1 C++ Program Structure
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.
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[]
By Mr. Muhammad Pervez Akhtar
Creating a Java Application and Applet
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 – Introduction to C# Programming Outline 3.1 Introduction 3.2 Simple Program: Printing a Line.
1 Data and Expressions Chapter 2 In PowerPoint, click on the speaker icon then the “play” button to hear audio narration.
© 2007 Lawrenceville Press Slide 1 Chapter 3 Classes and Objects 1. How is a class different from an object?
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.
CS 106 Introduction to Computer Science I 01 / 24 / 2007 Instructor: Michael Eckmann.
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.
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.
Introduction to Algorithm. What is Algorithm? an algorithm is any well-defined computational procedure that takes some value, or set of values, as input.
Lecture 4 – Scanner & Style
Computer Programming Your First Java Program: HelloWorld.java.
A variable is a name for a value stored in memory.
Chapter 6 JavaScript: Introduction to Scripting
Chapter 4 Assignment Statement
Chapter 1 Introduction to Computers, Programs, and Java
GC101 Introduction to computer and program
Chapter 3 GC 101 Java Fundamentals.
Console Output, Variables, Literals, and Introduction to Type
Yanal Alahmad Java Workshop Yanal Alahmad
Chapter 2, Part I Introduction to C Programming
Chapter 2 Introduction to Java Applications
Chapter 7 Top-Down Development
Introduction to Scripting
CompSci 230 Software Construction
Introduction Java Chapter 3.
Can perform actions and provide communication
C# Programming: From Problem Analysis to Program Design
Programming Vocabulary.
Can perform actions and provide communication
Chapter 1: Computer Systems
Java Intro.
Can perform actions and provide communication
Chapter 3 – Introduction to C# Programming
elementary programming
Anatomy of a Java Program
Java How to Program, 11/e Questions?
Getting Started with Java
Computer Programming-1 CSC 111
© A+ Computer Science - Basic Java © A+ Computer Science -
Chapter 2 part #1 C++ Program Structure
Presentation transcript:

Chapter 3 Classes and Objects 11/29/2018 5:59 AM Chapter 3 Classes and Objects Refer to page 60 in the text. Emphasize that a class is similar to a blueprint. The class defines how each object created from the “blueprint” will look and behave, but a class is not the object itself. © 2007 Lawrenceville Press

Chapter 3 Package Refer to page 60 in the text. 11/29/2018 5:59 AM Chapter 3 Package Refer to page 60 in the text. A package contains related classes. It is convenient for a programmer when a single package contains multiple classes for use in an application. Packages allow code (classes) to be reused over and over again. © 2007 Lawrenceville Press

Chapter 3 Application Package 11/29/2018 5:59 AM Chapter 3 Application Package Refer to page 60 in the text. An application is contained in a package. A package must contain a controlling class (with a main() method) in order to be an application. The application package can contain additional classes as well. © 2007 Lawrenceville Press

Chapter 3 A Java Application 11/29/2018 5:59 AM Chapter 3 A Java Application package name package firstApplication /** * 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 Note: This slide contains animations. Press the space bar or click the mouse button to display each animation. This slide contains five (5) animations. Refer to page 61 in the text. <press space bar> A package name is declared with a package statement. <press space bar> The comment describes the purpose of the application. <press space bar> The class declaration creates a new class named Greeting. <press space bar> The main() method indicates that the class is a controlling class. The main() method will be run automatically when the application is executed. <press space bar> Statements are instructions. The println() statement will display output to the screen when the application is run. © 2007 Lawrenceville Press

Chapter 3 Executing a Java Application 11/29/2018 5:59 AM Chapter 3 Executing a Java Application public class Greeting public static void System.out.printl } source code 03 3b 84 01 ff f9 68 05 1a bytecode compiler JVM ...c cilbup ...48 b3 30 Hello,world! Refer to page 62 in the text. In order to execute a Java application, the source code must be compiled to code that the computer understands. In Java, the source code is converted to bytecode with a compiler. Next, the bytecode is interpreted by the Java Virtual Machine (JVM) to execute the application and produce output. Note that the bytecode, not source code, is what must be run from a computer that has a JVM. © 2007 Lawrenceville Press

Chapter 3 Escape Sequences 11/29/2018 5:59 AM 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 Refer to pages 63 in the text. An escape sequence is a backslash (\) followed by a symbol that together represent a character. © 2007 Lawrenceville Press

Chapter 3 The format() Method 11/29/2018 5:59 AM 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 Refer to page 64 in the text. The format() method can be used in place of the print() or println() methods to control the way output is displayed. © 2007 Lawrenceville Press

Chapter 3 Code Conventions 11/29/2018 5:59 AM 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. Refer to page 65 in the text. Code conventions are a set of guidelines for writing an application. Code conventions can make modifying and maintaining code faster, easier, and less expensive. © 2007 Lawrenceville Press

Chapter 3 Code Conventions (con't) 11/29/2018 5:59 AM 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. Refer to page 65 in the text. © 2007 Lawrenceville Press

Chapter 3 Flowchart Symbols 11/29/2018 5:59 AM Chapter 3 Flowchart Symbols start/end input/output Refer to pages 66 and 67 in the text. The oval flowchart symbol indicates start or end. The parallelogram flowchart symbol indicates input or output. © 2007 Lawrenceville Press

Chapter 3 The Triangle Flowchart 11/29/2018 5:59 AM Chapter 3 The Triangle Flowchart Refer to page 66 in the text. The Triangle flowchart illustrates the application solution. Solution steps include: 1. displaying one asterisk 2. displaying two asterisks on the next line 3. displaying asterisk space asterisk on the next line 4. displaying asterisk asterisk asterisk asterisk on the last line © 2007 Lawrenceville Press