Using Objects.

Slides:



Advertisements
Similar presentations
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
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.
Building Java Programs Interactive Programs w/ Scanner What is a class? What is an object? What is the difference between primitive and object variables?
Using Classes Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Not Glasses, Classes!!!
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 2 – Using Objects.
1 Chapter 8 Objects and Classes Lecture 2 Prepared by Muhanad Alkhalisy.
Fields, Constructors, Methods
Chapter 2: Using Objects Part 1. To learn about variables To understand the concepts of classes and objects To be able to call methods To learn about.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 8 Objects and Classes.
Chapter 2 Using Objects. These slides for CSE 110 Sections are based in part on the textbook-authors ’ slides, which are copyright 2003 by Cay Horstmann.
Chapter 2 storing numbers and creating objects Pages in Horstmann.
Datalogi A 2: 15/9. Java Slides based on Horstmann chapter 2&3 Objects and classes Import, methods, references Implementing a class.
Lecture 11. Today’s topic Conditional statement –Relational operators –if statement –if-else statement –If-elseif statement.
Chapter 2  Using Objects 1 Chapter 2 Using Objects.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
Java Concepts Chapter 2 – Graphical Applications Mr. Smith AP Computer Science A.
Week 3 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
CHAPTER 2 Using Objects. Basic Programming Terminology  Computer program process values.  Numbers (digits)  Words (Strings)  These values are different.
Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Chapter Two: Using Objects.
Chapter Two: Using Objects. To learn about variables To understand the concepts of classes and objects To be able to call methods To learn about parameters.
Chapter 2 – Using Objects Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 8 Objects and Classes.
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
ICOM 4015: Advanced Programming Lecture 2 Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Reading: Chapter Two: Using.
Chapter 2: Java Fundamentals
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. In order to display a drawing in a frame, define a class that extends.
Chapter 2 Using Objects. Chapter Goals To learn about variables To understand the concepts of classes and objects To be able to call methods To be able.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 7 Objects and Classes.
1.  At the end of this slide, student able to:  Object-Oriented Programming  Research on OOP features.  Do a code walkthrough to examine the implementation.
Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.
Assignment An assignment statement changes the value of a variable The assignment operator is the = sign total = 55; Copyright © 2012 Pearson Education,
Chapter 8 Objects and Classes Object Oriented programming Instructor: Dr. Essam H. Houssein.
Creating a GUI with JFC/Swing. What are the JFC and Swing? JFC –Java Foundation Classes –a group of features to help people build graphical user interfaces.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Chapter 2 – An Introduction to Objects and Classes Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 2 – Using Objects.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Objects and Classes.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 6 Objects and Classes.
Chapter 2 Using Objects. Chapter Goals To learn about variables To understand the concepts of classes and objects To be able to call methods To be able.
A data type in a programming language is a set of data with values having predefined characteristics.data The language usually specifies:  the range.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Lecture 10. Review (Char) Character is one of primitive data types of variable (such as integer and double) –Character variable contains one character.
Chapter 2 – An Introduction to Objects and Classes Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 2 – Using Objects.
Features of JAVA PLATFORM INDEPENDENT LANGUAGE JAVA RUNTIME ENVIRONMENT (JRE) JAVA VIRTUAL MACHINE (JVM) JAVA APP BYTE CODE JAVA RUNTIME ENVIRONMENT.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Break Time! Graphical User Interface (GUI) NO EXAM….ONLY PROJECT!
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
Chapter Goals To learn about variables
Chapter Goals To learn about variables
Chapter 2 Not Glasses, Classes!!! Using Classes
Chapter 7 Objects and Classes
Chapter 2 – Using Objects
Elementary Programming
Yanal Alahmad Java Workshop Yanal Alahmad
Basic Graphics Chapter 5 3/19/15 Thursday Section Only
FUNDAMENTALS OF JAVA.
Chapter 2 – Using Objects
Chapter 2.
Chapter 2 Using Objects.
Introduction to Java Programming
Chapter 8 Objects and Classes Part 1
Java’s Central Casting
Chapter 2: Java Fundamentals cont’d
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

Using Objects

Java Primitive Data Types integral boolean floating point byte char short int long float double Begin with lowercase letters

Java Reference Types Reference types: 1. String 2. Class name

String Methods int n = greeting.length(); String bigRiver = river.toUpperCase();

What is: Java Syntax??

Multiple variables can be created in variable name data type int total; int count, temp, result; Multiple variables can be created in one declaration

What Does a Variable Declaration Do? int ageOfDog; 4 bytes for ageOfDog

Variables initial value in the declaration int sum = 0; int base = 32, max = 149;

Assignment ageOfDog = 10;

Variable Declarations and Assignment of Values ASSIGNMENT STATEMENTS

Identifiers Rules for identifiers in Java?

package movetester; import java.awt.Rectangle; public class MoveTester { public static void main(String[] args) Rectangle box = new Rectangle(5, 10, 20, 30); // Move the rectangle where x becomes 20 and y becomes 35 box.translate(15, 25); // Print information about the moved rectangle System.out.println(box.getX()); System.out.print("y: "); System.out.println(box.getY()); System.out.println("Expected: 35"); } }

Packages package areatester;

We work with Objects A fundamental entity in Java. Objects are “things”

java.lang.Object: the root of java classes

Class Object Class encapsulates objects work together (behavior) Objects have properties:

HomeWork P2.1 - Programming Exercise

Graphical User Interfaces GUI Objects

Graphical User Interfaces (GUI): Demonstrates the object concep0t! frame Graphical User Interfaces (GUI): Demonstrates the object concep0t! Content pane used to display objects in a frame

Example: Frame Viewer 01: import javax.swing.JFrame; 02: 03: public class EmptyFrameViewer 04: { 05: public static void main(String[] args) 06: { 07: JFrame frame = new JFrame(); 08: 09: frame.setSize(300, 400); 10: frame.setTitle("An Empty Frame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 12: frame.setVisible(true); 14: } 15: } (page 56 of text) or section 2.11 Example: Frame Viewer

frame = new JFrame (name); Jframe frame Point to object frame = new JFrame (name); (creates a class instance)

See Sun site for greater detail Sun.java

Lab 2:Graphical Fun Using the example in your text book on page 64; Section 2.13: Create your own FaceViewer Class with a main method that will show a JComponent. Adjust your Frame to be square The frame title must contain your name. Using the FaceComponent example as a guide (page 64; Section 2.13): Create an Animal Viewer and draw an animal of your choice. Draw a string that describes the animal Set colors as desired

Upload to the appropriate dropbox Output Two classes - tested Upload to the appropriate dropbox Lab Completion

Object Lessons?