与声明一个primitive variable不同,声明一个对象的时候,并不创建用来存储一个对象的内存空间,而是创建了一个存储该对象所在内存空间的地址。

在java里,new是一个操作符,它让系统分配一个特定类型的存储空间,并返回该内存空间的地址。

String str;

str = “Java Programing”;

String str = new String("Java Programing");

是有区别的,前者是把已经存在的“Java Programming”的存储地点赋值给str,而后在,需要先生存一个"Java Programing",然后再把它的地址赋值给str。

In reality, when the statement in Line 4 executes, it first looks if the program
has already created the string "Java Programming". If this is the case, then the
String variable str will point to that memory location. However, when the statement
in Line 5 executes, the system will allocate a memory space, store the string "Java
Programming" into that memory space, and then store the address of that memory
space into str. This is a key difference and plays an important role when strings and
String variables are compared, which we will explain in Chapter 4.

In Java, variables such as str are called reference variables. More formally, reference
variables are variables that store the address of a memory space. In Java, any variable
declared using a class (such as the variable str) is a reference variable. Because str is a
reference variable declared using the class String, we say that str is a reference
variable of the String type.

Primitive type variables store data directly into their own memory spaces. Reference
variables store the address of the object containing the data. An object is an instance of
a class and the operator new is used to instantiate an object. In some languages, such as
C++, reference variables are called pointers.
Before discussing the class String, we first discuss how to use predefined methods in a
program.

There are two types of methods in a class: static and non-static. A static
method can be used, that is, called, using the name of the class containing the method.
static修饰的method,可以直接用类名来调用它,比如Math.pow(2,3)。

129页,输入输出

Chapter 3 Introduction to Objects and Input/Output的更多相关文章

  1. TIJ——Chapter One:Introduction to Objects

    ///:~容我对这个系列美其名曰"读书笔记",其实shi在练习英文哈:-) Introduction to Objects Object-oriented programming( ...

  2. PRML Chapter 1. Introduction

    PRML Chapter 1. Introduction 为了防止忘记,要把每章的重要内容都记下来,从第一章开始 2012@3@28 今天又回去稍微翻了一下第一章内容,发现第一次看的时候没有看透,每次 ...

  3. PHP-FPM-failed to ptrace(PEEKDATA) pid 123: Input/output error

    If you're running PHP-FPM you can see these kind of errors in your PHP-FPM logs. $ tail -f php-fpm.l ...

  4. NFS挂载异常 mount.nfs: Input/output error

    [root@localhost ~]# vi /etc/exports #增加/nfs 192.168.10.132(rw,no_root_squash,no_all_squash,async) [r ...

  5. BIOS(Basic Input/Output System)是基本输入输出系统的简称

    BIOS(Basic Input/Output System)是基本输入输出系统的简称 介绍 操作系统老师说,平时面试学生或者毕业答辩的时候他都会问这个问题,可见这个问题对于计算机专业的学生来说是如此 ...

  6. read()、write()返回 Input/output error, Device or resource busy解决

    遇到的问题,通过I2C总线读.写(read.write)fs8816加密芯片,报错如下: read str failed,error= Input/output error! write str fa ...

  7. Angular 个人深究(三)【由Input&Output引起的】

    Angular 个人深究(三)[由Input&Output引起的] 注:最近项目在做别的事情,angular学习停滞了 1.Angular 中 @Input与@Output的使用 //test ...

  8. Docker 在转发端口时的这个错误Error starting userland proxy: mkdir /port/tcp:0.0.0.0:3306:tcp:172.17.0.2:3306: input/output error.

    from:https://www.v2ex.com/amp/t/463719 系统环境是 Windows 10 Pro,Docker 版本 18.03.1-ce,电脑开机之后第一次运行 docker ...

  9. dpdk EAL: Error reading from file descriptor 23: Input/output error

    执行test程序时输出: EAL: Error reading from file descriptor 23: Input/output error 原因: 在虚拟机添加的网卡,dpdk不支持导致的 ...

随机推荐

  1. Gym - 101350F Monkeying Around(线段树+树状数组)

    When the monkey professor leaves his class for a short time, all the monkeys go bananas. N monkeys a ...

  2. Git 分支 (二)合并

    分支的新建与合并 让我们来看一个简单的分支新建与分支合并的例子,实际工作中你可能会用到类似的工作流. 你将经历如下步骤:1. 开发某个网站.2. 为实现某个新的需求,创建一个分支.3. 在这个分支上开 ...

  3. dubbo和dubboX与微服务架构(dubbo一)

    一.传统三层架构模式的缺陷 三层架构(3-tier architecture) 通常意义上的三层架构就是将整个业务应用划分为:界面层(User Interface layer)web.业务逻辑层(Bu ...

  4. 13、 使用openpyxl存储周杰伦的歌曲信息

      import requests import openpyxl res = requests.get('https://c.y.qq.com/soso/fcgi-bin/client_search ...

  5. Moving Average

    移动平均算法Demo #!/usr/bin/python2.7 # Fetch data from BD and analyse. import json import urllib import t ...

  6. esnext:Function.prototype.toString 终于有规范了

    从 ES1 到 ES5 的这 14 年时间里,Function.prototype.toString 的规范一字未变: An implementation-dependent representati ...

  7. 使用OpenPop.dll开发读取POP3邮件程序

    1.设置邮件的pop3 以163网易邮箱为例: https://jingyan.baidu.com/article/adc81513804be9f722bf7350.html 2.下载OpenPop. ...

  8. 2.7 if应用:猜拳游戏

    应用:猜拳游戏 <1>运行效果: <2>参考代码: import random player = input('请输入:剪刀(0) 石头(1) 布(2):') player = ...

  9. python3 使用pip安装(命令行中)失败或 “not a supported wheel” 解决方案!

    原因1: 安装的不是对应python版本的库,下载的库名中cp36代表python3.6,其它同理. 原因2:(我遇到的情况----下载的是对应版本的库,然后仍然提示不支持当前平台) 百度了一下,说法 ...

  10. C# - 操作符

    操作符(Operator) C#的操作符是一种告诉编译器执行计算.逻辑判断的符号. default(x) 获取类型的默认值,x是类型.虽然可以为任意类型使用此操作符,但此操作符主要用于泛型,在不确定泛 ...