Article From:

***************************Chapter VI Categories and Objects********************************************


***************************Difference between process-oriented and object-oriented************************************************************************

I. Process-oriented


Concern is how to do, that is, concrete steps and details of implementation.

Demand: Refrigerate the elephant…

Step 1 Open the refrigerator door

Step 2: Install the elephant in the refrigerator

Step 3: Close the refrigerator door

II. Object-Oriented

What you care about is what users only need to care about what they do.

As for how to encapsulate it into a method, the designer of the class cares. The method itself is process-oriented.

1. First design a Person-like person

Behavior (Method): Refrigerate an elephant

2.create object

Person p = new Person();

3. Method of calling object

p.Refrigerate the elephant.

The benefits of object-oriented languages:

Strong readability and maintainability, able to cope with the needs of large-scale software to solve the software crisis

Software Crisis: With the growing of the project, the use of process-oriented language development programs is becoming more and more bloated and bulky.
It’s difficult to maintain, and it’s called the software crisis that causes the project to be delayed and even impossible to complete………………………………….

***************************Object-Oriented Design Idea************************************************************************

The advantage of simulating the real world is that it makes programming easier and easier to understand.

Object-oriented approach to human thinking.

Process-Oriented Thinking Closer to Computer

A program is a world!


***************************Concepts of Classes and Objects****************************************************************

Real World – Programming World

Specific Tree Objects

Specific Car Objects

Specific Puppy Dog Object

Specific students


Object: To simulate things in the real world…



Attribute number, name, sex, specialty of students.


Eating, studying, examinations…

Class: A collection of objects with the same attributes and operations…… Student class

A class can create multiple objects. Creating objects is also called instantiating an object.

Class is object (abstract), object (template), object is class (instance)


**********************UMLFigure ***************************************************

UML Unified Modeling Language facilitates programmer communication

I. class diagrams

UMLClass diagrams are represented by rectangles, which are divided into upper, middle and lower parts.

Upper: class name

Intermediate: Attributes

Below: Behavior

What’s the difference between an object graph and a class graph???

II. Object Graph

It consists of two parts.

1. Above

Object name: class name

There is an underscore under the name


Attribute = value


Note: Object diagrams have no behavior


*********************Object-Oriented Benefits (Story of Cao Cao in Movable Type Printing)*******************************************

Process Oriented: Engraving Printing

Object-Oriented: Movable Type Printing


Process-Oriented – —— – & gt; Object-Oriented

Engraving Printing————— gt; Movable Type Printing


1.Cao Cao (customer)

2.Minister (Project Manager)

3.Craftsman (Program Ape)



Demand 1: Drink and sing, life is really cool!

Needs 2: Song of wine, life is really cool!!

Needs 3: Singing to Wine, Geometry of Life uuuuuuuuuuu


Object-oriented advantages:

I. Reusability

Category: Every movable word (drink)

Object: Specific text printed on a book.

A class can create multiple objects

Code is reusable.

Class code is reusable and can be used to create multiple objects.

If there are no classes, create multiple objects, and each object’s code must be re-written….

The method also embodies reusability.

II. Maintainability

Easy maintenance, less modification

Movable-type printing requires only a few words to be changed, while block printing requires an entire reprogramming.

III. Extensibility

Movable-type printing can be added at will


4. Flexibility

Vertical typographic printing requires reprogramming, while movable type printing requires only adjusting the position of the text.


Readability is strong.





**********************Create objects using existing classes provided by the system **************************************************************


Class name object name = new class name ();

1. String s = new String(“aaa”);

2. Integer integerI = new Integer(10);

3. Object obj = new Object();// Object The parent class of all classes


4. Person p = new Person();


**********************Definition of Category I **************************************************


class Class name {

//1.Attributes (member variables)

//2.Behavior (Method)



Class names are specified in the Big Hump Code.

Demonstration code:


package com.chapter6;

* Author: zhangzy
* Company: Blue Bridge Software College
* Time: 11:07:24 a.m. on 30 June 2017
* Function: Demonstration class definition
public class Student {

int sno;//Student ID
String name;//Full name
int age;//Age
public void study(){
System.out.println(“I am + name +, I am learning.

public void exam(){
System.out.println(“Examination “”;

**********************II. Creating Objects *********************************************

Student s = new Student();

**********************III. Attributes of Accessing Objects and Methods of Calling Objects ***************

I. Access attributes

Object name. Attribute name

2. Call method

1.Static method

Class name. Method name ();

2.Example method

Class name object name = new class name ();

Object name. Method name ();

Demonstration code:

package com.chapter6;

public class TestStudent {

public static void main(String[] args) {

// 2.create object
// Class name object name = new class name ();
Student s1 = new Student();

// Access attribute
s1.sno = 1; = “Ding Zepeng;
s1.age = 20;

// Calling method;

// Create another student object
Student s2 = new Student();

// Access attribute
s2.sno = 2; = “Wang Yulong;
s2.age = 21;

// Calling method;


***************************Encapsulation (one of the three characteristics of object-oriented)*******************************************************

Three characteristics of object-oriented:




A language needs at least three features to be called an object-oriented language.



1. Encapsulation into classes

Putting attributes and methods into classes is called encapsulating them into a class.

2. Encapsulation method

Put several sentences of code into a method and encapsulate it into a method.


Good package

1.For attributes

Private is needed to modify attributes to ensure the security and concealment of information

private Privately owned only this class is accessible


It’s obviously unsafe for people to modify or access your attributes at will without privates, such as changing your name, age, or even your attributes at will.
It’s sex.

2.For methods

Use public to decorate

public Anyone publicly owned can use it.

Defining a method is usually for others to use. In order for others to use it, you need to use public to decorate it.



************************Four Relations between Objects (Categories)************************************************************

Objects are used to simulate things in the real world, which are inextricably linked with each other.

In order to simulate the relationship between things, there must be a relationship between objects.

I. Relevance

Used to simulate the most basic relationship between objects, it is a relationship that can be accessed each other.

Teachers – ——- students


1. Unidirectional Association

Teacher – ——— gt; Student

2. Bidirectional correlation

Teachers – ——- students


1:1 One-on-one

Person: Identity Card Student: Student: Student No. One Person: Wife

1:M One to many

School: Students

Company: Staff

Teacher: Students (Blue Bridge)

M:N Many to many

Student: Courses

Teacher: Students (in school)


************************Two special cases of association: combination and aggregation has a********************************************************

Overall has a part

Basketball team has a player


Common ground:

It’s the relationship between the whole and the part.



1. polymerization

Parts can belong to multiple whole, the relationship between parts and whole is not particularly close, and the life cycle of parts and whole is inconsistent.


A person can join both the basketball team and the football team.

Students belong not only to the class of Blue Bridge, but also to the class of their own school.


The hollow diamond indicates that the hollow diamond is holistic.


2. combination

Parts can only belong to one whole. Parts are closely related to the whole. Parts disappear and the whole disappears. Their life cycle is the same.


Limbs (Heart) and People, Engines and Automobiles


A solid diamond indicates that the position of the solid diamond is the whole.


************************II. Inheritance is a ***********************************

General and Special Relations

Implementing + Hollow Triangle Represents Inheritance Relation

************************3. Achieving Relations*************************************

Implementing a set of specifications…

Student specification

Teacher standard

Chefs specification

The implementation of this set of specifications can be called chef…

UMLImplementing Representation with Dotted Line+Hollow Triangle Representation


************************IV. Dependence*******************************************


Class A – – – – – – gt; Class B

When class B changes, class A also changes, called class A depends on class B.


Students – – – – – – gt; Parents

Laptop Work – – – – – – gt; Screen


Link of this Article: Java classes and objects

Leave a Reply

Your email address will not be published. Required fields are marked *