Introduce JAVA OOP(Object,Class,Method), Character strings, their use, concatenation and conversion

A small JAVA program

Methods (方法)

A method is a group of programming statements that is given a name.

即C语言中的的 function(函数)。

定义与调用:(与C语言一样, 但方法需定义在class里面)

 

Java is Object-Oriented Paradigm of Programming(OOP)

面向过程(procedure-oriented):当需要实现某一功能时,每个具体步骤都亲力亲为,详细处理每一个细节。

面向对象:当需要实现一个功能时,直接用已经具有的功能,而不用关心具体步骤。

对比

Three main concepts:

Encapsulation (封装) (object)
• provides security for data
• improves code maintenance
• code is easier to understand

Objects should be encapsulated: it protects and manages its own data
• Imagine if anyone could just go into your house and rearrange your furniture!
• Special methods are used to access and modify an object’s data
• They act as a lock – restricting access to the data stored within the object

• Inheritance (继承)(class)
• improve code sharing and re-usability
• hierarchical code organisation based on commonality
in your source code: same data and/or operations

Classes can be created from existing classes using inheritance
• This is software reuse, exploiting similarities among classes
• One class is used to derive several new classes – and those classes
can be used to derive even more classes
• In this way, we create a class hierarchy in which derived children
classes inherit attributes and methods from their parent classes
• Polymorphism means that you can write source code which computes
over multiple types of related objects.
• This leads to elegant and reusable solutions


• Polymorphism
• simplifies code understanding
• standardises method naming

类 class

一组相关属性和行为的集合。

属性:该事物的状态信息。

行为:该事物能做什么。

举例: 猫

属性:名字、体重、颜色等。

行为:跑、跳、叫。

 

对象 object

是类的一个实例(也具备该类事物的属性和行为)

类是抽象的描述,而对象是该类事物的实例

举例:

In the first example, we have printed out a string.

System is a class, and out is an obejct.

println is a method.

So..

Besides, we can also declare a string variable:

When we ouput the variables with string we should use the +.


The diference between the println & print: 

 

String concatenation

Concatenation vs addition operators

So when we want to output the variables with string or somthing, we should use the + .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值