Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programs and Classes A program is made up from classes

Similar presentations


Presentation on theme: "Programs and Classes A program is made up from classes"— Presentation transcript:

1 Programs and Classes A program is made up from classes
Classes may be grouped into packages A class has two parts static parts exist independently Non-static parts define what objects in the class look like. Every class is automatically in existence when the program runs. The two most important concepts in object-oriented programming are the class and the object. In the broadest term, an object is a thing, both tangible and intangible, which we can imagine. A program written in object-oriented style will consist of interacting objects. For a program to maintain bank accounts for a bank, we may have many Account, Customer, Transaction, and ATM objects. An object is comprised of data and operations that manipulate these data.

2 Classes and Objects An object is an instance of a class, and is created using the new operator. The non-static part of the class defines what each object looks like. Many instances (objects) can be created from a class … no limit except reality An object contains information and functionality of a “thing”, e.g., Account, Vehicle, Employee, etc. The two most important concepts in object-oriented programming are the class and the object. In the broadest term, an object is a thing, both tangible and intangible, which we can imagine. A program written in object-oriented style will consist of interacting objects. For a program to maintain bank accounts for a bank, we may have many Account, Customer, Transaction, and ATM objects. An object is comprised of data and operations that manipulate these data.

3 Classes’ and Objects’ Components
Classes (and thus also objects) are composed of methods and data values Data values store information Methods do things, and also have their own local data

4 Visibility Modifiers: public and private
The modifiers public and private designate the accessibility of objects’ and class’ data values and methods If a component is declared private, nothing outside the class can access it. If a component is declared public, anything outside the class can access it.

5 Primitive and Reference Data Values
byte short int double long float boolean String Applet MessageBox HiLo InputBox etc. char primitive reference Data Type A constant data value is represented graphically by a lock icon to convey the fact that the value is locked and cannot be changed. Primitive variables contain values Reference variables point at objects

6 Methods Methods have code (to do stuff) and local variables
To instruct a class or an object to do something, we a message to one of its methods Values passed to a method when sending a message are called arguments or parameters of the message. The (formal) parameters of a method are local variables that receive the message parameters Methods can return one data value to the calling method

7 Program Components A Java file is composed of comments,
import statements, and class declarations.

8 Files and Classes A Java program file ends with .java
There must be one public class per file It must have the same name as the file One public class (i.e., one file) must have the main method

9 Simple Java Programs Simple Java programs can be written in just the one file, containing One public class (with the main method) Other class methods and final data values as required Such programs do not create any objects, but simply run class methods (starting with the main method) and use primitive data.


Download ppt "Programs and Classes A program is made up from classes"

Similar presentations


Ads by Google