Presentation is loading. Please wait.

Presentation is loading. Please wait.

Welcome to AP Computer Science JAVA Programming in.

Similar presentations


Presentation on theme: "Welcome to AP Computer Science JAVA Programming in."— Presentation transcript:

1 Welcome to AP Computer Science JAVA Programming in

2 Objective: To identify the components of an object-oriented program written in java.

3 What is JAVA? Java is a language designed for object-oriented programming, abbreviated OOP. Object-oriented programming is a programming methodology that views a program as a set of objects that interact with each other by means of actions.

4 What are Objects? An object is a program construction that has data associated with it and that can perform certain actions. For example, if we wanted to write a program to simulate brewing and selling coffee at a coffee shop. One object in our program could be for the different types of coffee that we are brewing and selling.

5 What other objects could our Coffee Shop program contain?

6 Each object has certain attributes. An object’s attributes are the information/data associated with it. For example, our coffee object would have attributes such as coffeeType, price, ingredients, temperature, etc. An object’s attributes are a major part of what makes each object unique.

7 Along with attributes, each object has a set of methods. Methods are the actions associated with the object. Our coffee object could have methods such as mixIngrediants(), brewCoffee(), checkTemperature().

8 Objects of the same type are said to be from the same Class. In JAVA, we create a class which is basically the definition of an object. The attributes and methods of each individual object are set up in a class. All objects in the same class have the same kind of attributes and methods. To create an object of a certain class, we say we create an instance of the class.

9 How do we set up a class? First, we must design our class. Class Name:Coffee Attributes (data): Methods (actions): coffee type price special ingredients mix ingredients brew coffee

10 Once we have finished designing our class, we can then start to code it. Class Name:Coffee Attributes (data): Methods (actions): coffee type price special ingredients mix ingredients brew coffee public class Coffee { private String sCoffeeType; private double dPrice; private String sSpecIngredients; public void mixIngredients( ) { // method definition here } public void brewCoffee( ) { // method definition here } }

11 In object-oriented programs, we first define classes, and while the program is running, we create objects from these classes to accomplish tasks. // Define Caffe Latte object of type class Coffee Coffee CaffèLatte = new Coffee( ); // Define Caffe Mocha object of type class Coffee Coffee CaffèMocha = new Cofee( );

12 Coffee CaffèLatte = new Coffee( ); Class Name Object Name Instantiates a new object Constructor ClassName ObjectName = new Constructor( ); Creating and Instantiating an Object

13 To perform methods (actions) on an object, we must call the object along with its method. //The method that mixes the ingredients is called for the CaffeLatte object (of type coffee). CaffèLatte.mixIngredients( ); //The method that mixes the ingredients is called for the CaffeMocha object (of type coffee). CaffèMocha.mixIngredients( );

14 CaffèLatte. mixIngredients( ); Object Name Method To have an object perform an action we must have the specific object call the method using the dot operator. Dot operator

15 Let’s write a simple program. HelloWorld


Download ppt "Welcome to AP Computer Science JAVA Programming in."

Similar presentations


Ads by Google