An Introduction to Java – Part II

Slides:



Advertisements
Similar presentations
Looking inside classes Fields, Constructors & Methods Week 3.
Advertisements

Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Written by: Dr. JJ Shepherd
Constructors & An Introduction to Methods. Defining Constructor – Car Example Public class car { String Model; double speed; String colour; { Public Car.
Syntax & terminology review While the following slides are not exactly what we did on the board (object diagrams are not shown here) they cover most of.
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
1. 2 Introduction to Methods  Method Calls  Parameters  Return Type  Method Overloading  Accessor & Mutator Methods  Student Class: Revisited.
Understanding class definitions Looking inside classes 3.0.
Chapter 3 Using Classes and Objects. 2 Creating Objects  A variable holds either a primitive type or a reference to an object  A class name can be used.
Objects & Object-Oriented Programming (OOP) CSC 1401: Introduction to Programming with Java Week 15 – Lecture 1 Wanda M. Kunkle.
What is a class? a class definition is a blueprint to build objects its like you use the blueprint for a house to build many houses in the same way you.
Introduction to Computers and Programming Strings Professor: Evan Korth New York University.
Understanding class definitions – Part II –. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Main.
Constructors A constructor is a method that creates an object in Java. It does not return anything and it is not void. It’s only purpose is to create an.
More C++ Bryce Boe 2013/07/18 CS24, Summer 2013 C.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Java Classes Appendix C © 2015 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Object-Oriented Programming (OOP). Implementing an OOD in Java Each class is stored in a separate file. All files must be stored in the same package.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
Introducing Objects. Structure  Objects have two parts: Instance Variables (attributes, adjectives) Instance Variables (attributes, adjectives) private.
CH 8 : Enhancing Classes - Review QUICK REVIEW : A Class defines an entity’s (Object’s) data and the actions or behaviors (Methods) associated with that.
Review of ICS 102. Lecture Objectives To review the major topics covered in ICS 102 course Refresh the memory and get ready for the new adventure of ICS.
10-Nov-15 Java Object Oriented Programming What is it?
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
CSC 142 Computer Science II Zhen Jiang West Chester University
Understanding class definitions
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
Looking inside classes Conditional Statements Week 4.
Object Oriented Programming and Data Abstraction Rowan University Earl Huff.
CSC 142 F 1 CSC 142 References and Primitives. CSC 142 F 2 Review: references and primitives  Reference: the name of an object. The type of the object.
AP Java Ch. 4 Review Question 1  Java methods can return only primitive types (int, double, boolean, etc).
CPSC 233 Tutorial 5 February 9 th /10 th, Java Classes Each Java class contains a set of instance variables and methods Instance Variables: Type.
Lecture 3: More on Classes Textbook: Chapter 2 Recap: –Classes vs. Objects –Q: What comes first a class or an object? –Q: Do we need a class to create.
INTRODUCTION TO CLASSES & OBJECTS CREATING CLASSES USING C#
CLASSES IN JAVA Primitive Types Example of a Class Allocating Objects of a Class Protecting Class data Constructors Static data and Static Methods.
Staples are our staple Building upon our solution.
Java 5 Class Anatomy. User Defined Classes To this point we’ve been using classes that have been defined in the Java standard class library. Creating.
Andrew(amwallis) Classes!
OBJECT ORIENTED PROGRAMMING
Re-Intro to Object Oriented Programming
3 Introduction to Classes and Objects.
Objects as a programming concept
Intro To Classes Review
Methods The real power of an object-oriented programming language takes place when you start to manipulate objects. A method defines an action that allows.
More Object Oriented Programming
Instance Method Review - CIS 1068 Program Design and Abstraction
Initializing Arrays char [] cArray3 = {'a', 'b', 'c'};
Java Programming with BlueJ
Understanding class definitions
Class Inheritance (Cont.)
Chapter 3 Introduction to Classes, Objects Methods and Strings
Interface.
Creating Objects in a Few Simple Steps
Classes & Objects: Examples
String Methods: length substring
Implementing Classes Chapter 3.
CS2011 Introduction to Programming I Objects and Classes
CS2011 Introduction to Programming I Arrays (II)
Class Everything if Java is in a class. The class has a constructor that creates the object. public class ClassName private Field data (instance variables)
Understanding class definitions
JAVA An Introduction to Java OOP Basics
JAVA CLASSES.
Object-Oriented Programming
Instance Method – CSC142 Computer Science II
Unit-1 Introduction to Java
Unit-2 Objects and Classes
Presentation transcript:

An Introduction to Java – Part II Ben Lerner An Introduction to Java – Part II

Class Definitions Classes consist of constructors, methods, and fields <modifier> class Person { constructors fields methods }

Constructors and Objects Constructors initialize objects, same name as the class public Person (string name, int age) { … } Objects created using new keyword and the constructor, store reference Person P = new Person(“Michael”, 21);

Fields Fields are the variables that define the attributes of a class string name_; int age_; Constructors initialize an object’s fields public Person (string name, int age) { name_ = name; age_ = age; }

Methods Mutator methods change fields void setAge(int a) { age_ = a; } Inspector methods access fields string getName() { return name;} Constructors are also methods

Parameters Both primitive variables and objects can be passed to methods Parameters are always passed by value Remember that objects in Java are just references to the objects