Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6: Transition to Java Programming with Alice and Java First Edition.

Slides:



Advertisements
Similar presentations
CMSC 132: Object-Oriented Programming II Nelson Padua-Perez William Pugh Department of Computer Science University of Maryland, College Park.
Advertisements

STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
L3:CSC © Dr. Basheer M. Nasef Lecture #3 By Dr. Basheer M. Nasef.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 4: Writing Classes Presentation slides for Java Software Solutions for AP* Computer Science.
Chapter 1: Computer Systems
Written by: Dr. JJ Shepherd
CSCI 1100/1202 April 3, Testing A program should be executed multiple times with various input in an attempt to find errors Debugging is the process.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 11 Object, Object- Relational, and XML: Concepts, Models, Languages,
Outline Java program structure Basic program elements
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Chapter 4: Writing Classes Presentation slides for Java Software Solutions Foundations of Program Design Third Edition by John Lewis and William Loftus.
CS102--Object Oriented Programming Review 1: Chapter 1 – Chapter 7 Copyright © 2008 Xiaoyan Li.
Chapter 1 Introduction. © 2004 Pearson Addison-Wesley. All rights reserved1-2 Outline Computer Processing Hardware Components Networks The Java Programming.
Chapter 1 Introduction.
Abstract Data Types and Encapsulation Concepts
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 Part 1 Conditionals and Loops.
Chapter 2 Object-Oriented Design. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 2-2 Chapter Objectives Review the core concepts underlying.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
Comp 248 Introduction to Programming Chapter 4 - Defining Classes Part A Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 4: Writing Classes Presentation slides for Java Software Solutions for AP* Computer Science.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley John Lewis, Peter DePasquale, and Joseph Chase Chapter 5: Writing Classes.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Appendix B: Object-Oriented Design Java Software Structures: Designing.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Writing Classes (Chapter 4)
1 Computer Systems -- Introduction  Chapter 1 focuses on:  the structure of a Java application  basic program elements  preparing and executing a program.
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Java The Java programming language was created by Sun Microsystems, Inc. It was introduced in 1995 and it's popularity has grown quickly since A programming.
Lecture 2 Software Concepts Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo CET 3640 © Copyright by Pearson Education, Inc. All Rights Reserved.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Methods and Data Programming with Alice and Java First Edition.
CSCI 1100/1202 April 1-3, Program Development The creation of software involves four basic activities: –establishing the requirements –creating.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
White Space Spaces, blank lines, and tabs are collectively called white space and are used to separate words and symbols in a program Extra white space.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
CET 3640 Instructor: Dr. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Classes, Interfaces and Packages
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Written by: Dr. JJ Shepherd
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
© 2004 Pearson Addison-Wesley. All rights reserved October 5, 2007 Arrays ComS 207: Programming I (in Java) Iowa State University, FALL 2007 Instructor:
Chapter 3: Decisions and Loops
Yanal Alahmad Java Workshop Yanal Alahmad
Yanal Alahmad Java Workshop Yanal Alahmad
Chapter 3 Assignment Statement
Chapter 4: Writing Classes
Chapter 3 Introduction to Classes, Objects Methods and Strings
Chapter 3 Introduction to Classes, Objects Methods and Strings
Java Programming Language
Chapter 1: Computer Systems
Sridhar Narayan Java Basics Sridhar Narayan
Java Programming with BlueJ Objectives
Fundamental Programming
Chapter 3 Introduction to Classes, Objects Methods and Strings
Presentation transcript:

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6: Transition to Java Programming with Alice and Java First Edition by John Lewis and Peter DePasquale

1-2 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-2 Objectives Compare the concepts you saw in Alice to their counterparts in Java Learn about program development environments for Java Access the Java API support library and its online documentation Explore several Java program examples Practice using various Java statements

1-3 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Features Java is a general-purpose programming language. Java has control statements for making decisions and repetition that are similar to the ones in Alice. Java classes are organized into packages, rather than galleries. Inheritance is used to derive new classes from existing classes. Objects are created dynamically during program execution. Methods and properties are defined in classes. Programs must be compiled before they can be executed. A Java compiler reports syntax errors. 6-3

1-4 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Program Development There are many development environments that can be used to test Java programs. Java development environments use text-based editing. Source code is translated into Java bytecode by a compiler. A program may contain syntax errors, which compilers catch, and logic errors, which it will not. Compile-time errors are issued if a program breaks the language’s syntax rules 6-4

1-5 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Classes and Objects An object in Java is created using a programming statement: A class constructor uses a new operator to create an object. The constructor has the same name as the class. Java classes are organized into packages. Java API (application programming interface) is a library of predefined classes. Child class can be derived from parent class, and it automatically inherits the methods and properties of the parent. 6-5

1-6 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Data Types in Java Each variable in Java must be declared before being used. Variable declaration establishes the particular data type. Eight primitive data types built into the language are: Objects are created from a class, which is another data type. 6-6 integers:  byte  short  int  long floating point numbers:  float  double character data type:  char Boolean data type:  boolean

1-7 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Operators in Java and Alice 6-7

1-8 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Statements The assignment statement: The print statement uses two methods, print and println: The if-else statement: A main method is the default starting point in every Java program. 6-8 total = total + 25; System.out.println(“The result is “ + total); if (height > 69) height = height / 2; else System.out.println(“Current height: “ + height);

1-9 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Classes and Objects Each circle is an object; The window frame is another object; Each object has properties: color, size, location; 6-9 class header method header When the program is executed, a main method is executed first and drives everything else; The DrawCircles class is the program driver. objects instantiation package that contains Jframe class methods

1-10 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The CirclePanel Class 1-10 Circle objects CiclePanel method Another method – constructor Visibility modifiers – private and public; Classes and methods are often declared public; Instance data is often private; Encapsulation – every object manages its own data.

1-11 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The Circle Class 1-11 Circle class constructor instance data

1-12 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The Circle Class - methods 1-12 Java coordinate system:

1-13 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The for Loop Example 6-13

1-14 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Program Example The CoinFlip program flips a virtual coin. Sample run: The CoinFlip class contains the main method of the program. The Scanner class allows you to read input from the keyboard. The Coin class represents a single coin that can be flipped. 6-14

1-15 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Program Example (continued) 6-15 The while loop performs input validation The for loop flips the coin as many times as was specified

1-16 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Summary You can use one of several development environments to create Java programs. Java code is compiled and translated into bytecode before it is executed. A program may contain syntax errors, which will be caught by compiler. Logic errors cannot be caught by a compiler. A constructor is used to set up a newly created object. The Java API is a library of classes that we can use in any Java program. Encapsulation: the concept that each object should manage its own data and prevent explicit external modifications. The toString method is called automatically when an object is printed. 6-16