Chapter 3 Introduction to Classes, Objects Methods and Strings

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
Chapter 3 Introduction to Classes, Objects, Methods, and Strings
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 Pearson Education, Inc. All rights reserved. 3 3 Introduction to Classes and Objects.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Programming Principles Data types and Variables. Data types Variables are nothing but reserved memory locations to store values. This means that when.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
 Pearson Education, Inc. All rights reserved Formatted Output.
Object Oriented Design: Identifying Objects
Object-Oriented Programming - Classes, Objects Methods, Strings 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
 2005 Pearson Education, Inc. All rights reserved. 1 Arrays Part 4.
Java How to Program, Late Objects Version, 8/e © by Pearson Education, Inc. All Rights Reserved.
Primitive Variables.
Sections © Copyright by Pearson Education, Inc. All Rights Reserved.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
 Character set is a set of valid characters that a language can recognise.  A character represents any letter, digit or any other sign  Java uses the.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Assignment An assignment statement changes the value of a variable The assignment operator is the = sign total = 55; Copyright © 2012 Pearson Education,
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo CET 3640 © Copyright by Pearson Education, Inc. All Rights Reserved.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Copyright Curt Hill Variables What are they? Why do we need them?
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
Developed at Sun Microsystems in 1991 James Gosling, initially named “OAK” Formally announced java in 1995 Object oriented and cant write procedural.
1.2 Primitive Data Types and Variables
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Chapter One Lesson Three DATA TYPES ©
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Fundamentals 2.
Chapter 3 Introduction to Classes, Objects Methods and Strings
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
3 Introduction to Classes and Objects.
Introduction to Classes and Objects
Yanal Alahmad Java Workshop Yanal Alahmad
Chapter 5 Control Statements: switch Statement
Multiple variables can be created in one declaration
Primitive Types Vs. Reference Types, Strings, Enumerations
Dr Shahriar Bijani Winter 2017
Chapter 5 – part 1 Control Statements: switch Statement
Escape Sequences What if we wanted to print the quote character?
Building Java Programs Chapter 2
Chapter 3 Introduction to Classes, Objects Methods and Strings
Chapter 3 Introduction to Classes, Objects Methods and Strings
Unit-2 Objects and Classes
Introduction to Abstract Data Types
Wrapper Classes The java.lang package contains wrapper classes that correspond to each primitive type: Primitive Type Wrapper Class byte Byte short Short.
Chapter 2: Java Fundamentals
Introduction to Classes and Objects
Data Types Imran Rashid CTO at ManiWeber Technologies.
Chapter 2: Java Fundamentals
Session 2: Introduction to Object Oriented Programming
Object Oriented Programming in java
(C) 2010 Pearson Education, Inc. All rights reserved.
Review of Java Fundamentals
Presentation transcript:

Chapter 3 Introduction to Classes, Objects Methods and Strings Java™ How to Program, 9/e © Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

3.2  Declaring a Class with a Method and Instantiating an Object of a Class (Cont.) Compiling an Application with Multiple Classes Compile the classes in Fig. 3.1 and Fig. 3.2 before executing. Type the command javac GradeBook.java GradeBookTest.java If the directory containing the application includes only this application’s files, you can compile all the classes in the directory with the command javac *.java © Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

3.4 Instance Variables, set Methods and get Methods (Cont.) Unlike local variables, which are not automatically initialized, every field has a default initial value—a value provided by Java when you do not specify the field’s initial value. Fields are not required to be explicitly initialized before they are used in a program—unless they must be initialized to values other than their default values. The default value for a field of type String is null © Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

3.5 Primitive Types vs. Reference Types Types are divided into primitive types and reference types. The primitive types are boolean, byte, char, short, int, long, float and double. All nonprimitive types are reference types. A primitive-type variable can store exactly one value of its declared type at a time. Primitive-type instance variables are initialized by default—variables of types byte, char, short, int, long, float and double are initialized to 0, and variables of type boolean are initialized to false. You can specify your own initial value for a primitive-type variable by assigning the variable a value in its declaration. © Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

3.7 Floating-Point Numbers and Type double A number with a decimal point, such as 7.33, 0.0975 or 1000.12345). float and double primitive types double variables can store numbers with larger magnitude and finer detail than float variables. float represents single-precision floating-point numbers up to seven significant digits. double represents double-precision floating-point numbers that require twice as much memory as float and provide 15 significant digits—approximately double the precision of float variables. © Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

3.7 Floating-Point Numbers and Type double (Cont.) Java treats all floating-point literals (such as 7.33 and 0.0975) as double values by default. Appendix D, Primitive Types shows the ranges of values for floats and doubles. © Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

© Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.