Chapter 3 Introduction To Java. OBJECTIVES Packages & Libraries Statements Comments Bytecode, compiler, interpreter Outputting print() & println() Formatting.

Slides:



Advertisements
Similar presentations
IT151: Introduction to Programming
Advertisements

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.
 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
Introduction To Computers and Programming Lecture 2: Your first program Professor: Evan Korth New York University.
ECE122 L2: Program Development February 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 2 Program Development.
 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.
C# Programming: From Problem Analysis to Program Design1 2 Your First C# Program.
1 Character Strings and Variables Character Strings Variables, Initialization, and Assignment Reading for this class: L&L,
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.
Java Programming, Second Edition Chapter Four Advanced Object Concepts.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
1 Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class:
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
Java Programming, 3e Concepts and Techniques Chapter 2 - Part 2 Creating a Java Application and Applet.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
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()
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
CSC204 – Programming I Lecture 4 August 28, 2002.
Program Statements Primitive Data Types and Strings.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
1 The String Class Every character string is an object in Java, defined by the String class Every string literal, delimited by double quotation marks,
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Chapter 2: Java Fundamentals
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.
 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.
CSC 1051 – Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
© 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.
Anatomy of a Java Program. AnotherQuote.java 1 /** A basic java program 2 * 3 Nancy Harris, James Madison University 4 V1 6/2010.
Lecture 4 – Scanner & Style. Console Output The console that starts a Java application is typically known as the standard output device. The standard.
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
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
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.
CSCI 1100/1202 January 14, Abstraction An abstraction hides (or ignores) the right details at the right time An object is abstract in that we don't.
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
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
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.
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
Topic Pre-processor cout To output a message.
Chapter 1 Introduction to Computers, Programs, and Java
Console Output, Variables, Literals, and Introduction to Type
Chapter 2, Part I Introduction to C Programming
Introduction Java Chapter 3.
Statements, Comments & Simple Arithmetic
C# Programming: From Problem Analysis to Program Design
Programming Vocabulary.
Chapter 3 Classes and Objects
Chapter 2 Create a Chapter 2 Workspace Create a Project called Notes
Anatomy of a Java Program
Computer Programming-1 CSC 111
CSC 1051 – Data Structures and Algorithms I
Instructor: Alexander Stoytchev
Presentation transcript:

Chapter 3 Introduction To Java

OBJECTIVES Packages & Libraries Statements Comments Bytecode, compiler, interpreter Outputting print() & println() Formatting Output Style Algorithms

Classes and Objects

Class Libraries Class Library – is a set of classes that supports the development of programs. The Java standard class Library is a useful set of classes that anyone can use when writing Java programs. Java APIs – Application Programmer Interfaces. Class library made up of several sets of related classes.

Packages Group of related classes by one name. Eamples: java.lang – java.util

Import Declaration import – keyword used to identify packages and classes that will be used by the program. import java.util.Random; –Gains access to the Random Class import java.util.*; –Gains access to the package that contains class Random

java.lang.*; Automatically imported Classes in java.lang package –String –System –Double –Integer –Comparable –Math –Object –Etc.

java.util.*; Random ArrayList HashMap HashSet Iterator LinkedList List ListIterator Map Set TreeMap TreeSet

Package 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. (Refer to page 60 in the text.)

Application Package 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. (Refer to page 60 in the text).

A Java Application package firstApplication /** * The Greeting class displays a greeting */ public class Greeting { public static void main(String[] args) { System.out.println("Hello,world!"); } package name comment class declaration method statement

Comments Provides information about the program to the reader of the code. Comments have no affect on the program. Allows a reader to understand the logic behind the code. Ambiguous statements Can be used to debug a program

Three Types of Comments //  Single line comment /*…*/  Multiline comments /** */  used for documentation. –Javadoc tools copies documentation comments into a separate HTML document to create an instructional manual or external documentation. Used for classes and methods.

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

println() & print() Output stream sends data to an output device. System.out class and method to display data to the standard output stream. print() method – displays data and leaves the insertion point at the end of the output. println() method – moves the insertion point to the next line after displaying output.

The println Method In the Lincoln program from Chapter 1, we invoked the println method to print a character string The System.out object represents a destination (the monitor screen) to which we can send output System.out.println ("Whatever you are, be a good one."); object method name information provided to the method (parameters)

Escape Sequences What if we wanted to print a the quote character? The following line would confuse the compiler because it would interpret the second quote as the end of the string System.out.println ("I said "Hello" to you."); An escape sequence is a series of characters that represents a special character An escape sequence begins with a backslash character ( \ ) System.out.println ("I said \" Hello \” to you."); escape characters

Escape Sequences An escape sequence is a backslash ( \ ) followed by a symbol that together represent a character. Located in double quotes. Commonly used escape sequences: \n newline (AP EXAM) \t tab (8 spaces) (AP EXAM) \\ backslash (AP EXAM) \" double quotation mark (AP EXAM) \b  backspace \r  carriage return \’  single quote

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  NOT ON AP EXAM

Code Conventions or Style  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.

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.

Flowchart Symbols input/output start/end

The Triangle Flowchart