Chapter 3 Introduction to Objects and Input/Output
与声明一个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的更多相关文章
- TIJ——Chapter One:Introduction to Objects
///:~容我对这个系列美其名曰"读书笔记",其实shi在练习英文哈:-) Introduction to Objects Object-oriented programming( ...
- PRML Chapter 1. Introduction
PRML Chapter 1. Introduction 为了防止忘记,要把每章的重要内容都记下来,从第一章开始 2012@3@28 今天又回去稍微翻了一下第一章内容,发现第一次看的时候没有看透,每次 ...
- 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 ...
- 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 ...
- BIOS(Basic Input/Output System)是基本输入输出系统的简称
BIOS(Basic Input/Output System)是基本输入输出系统的简称 介绍 操作系统老师说,平时面试学生或者毕业答辩的时候他都会问这个问题,可见这个问题对于计算机专业的学生来说是如此 ...
- read()、write()返回 Input/output error, Device or resource busy解决
遇到的问题,通过I2C总线读.写(read.write)fs8816加密芯片,报错如下: read str failed,error= Input/output error! write str fa ...
- Angular 个人深究(三)【由Input&Output引起的】
Angular 个人深究(三)[由Input&Output引起的] 注:最近项目在做别的事情,angular学习停滞了 1.Angular 中 @Input与@Output的使用 //test ...
- 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 ...
- dpdk EAL: Error reading from file descriptor 23: Input/output error
执行test程序时输出: EAL: Error reading from file descriptor 23: Input/output error 原因: 在虚拟机添加的网卡,dpdk不支持导致的 ...
随机推荐
- Linux系统诊断必备技能之二:tcpdump抓包工具详解
一.简述 TcpDump可以将网络中传送的数据包完全截获下来提供分析.它支持针对网络层.协议.主机.网络或端口的过滤,并提供and.or.not等逻辑语句来帮助你去掉无用的信息. Linux作为网络服 ...
- docker系列(1)- 配置
参考自:https://www.jianshu.com/p/81bf5efff8e0
- C++回顾day02---<继承相关问题>
一:继承和组合混搭时,构造和析构调用原则 (一)先构造父类,再构造成员变量,最后构造自己 (二)先析构自己,再析构成员变量,最后父类析构(方向与构造相反) class A { public: int ...
- pip换源安装
pip install --index-url https://pypi.tuna.tsinghua.edu.cn/simple 要安装的 有些工具安装太慢, 换源安装一下, 速度一下子飞起
- I. Max answer(RMQ预处理前缀和)
题目链接: https://nanti.jisuanke.com/t/38228 题目大意:给你n个数,让你找出一个区间中f的最大值,具体的f计算方法,这段区间的和乘以这段区间的最小值. 具体思路:我 ...
- [Kubernetes]谈谈Kubernetes的本质
当下k8s算是比较火的一个内容,那么它到底是什么呢,它为什么会这么火呢,它解决的是什么问题呢.这篇文章就尝试着来讲讲,Kubernetes的本质. 当我们谈Kubernetes的时候,总是会想起来Do ...
- LaTeX技巧892: Ubuntu 安装新版本TeXLive并更新
原文地址:http://www.latexstudio.net/archives/9788.html 摘要: 本文比较系统地介绍了在Ubuntu下的TeXLive的安装与配置测试过程,建议使用Ubun ...
- Windows2016的 IIS中配置PHP7运行环境
Windows2016的 IIS中配置PHP7运行环境 在Windows 的IIS(8.0)中搭建PHP运行环境: 一:安装IIS服务器 .进入控制面板>>程序和功能>>打开或 ...
- iOS 新建xib文件时,最外层view的约束问题
今天用在利用xib实例化view 时, 生成的view的自动布局总是用问题.具体来说,宽和高都不能和父view正确变化.仔细检查,发现下图: 注意这里右上角的Autoresizing部分,并没有设置正 ...
- Kafka简单使用
前言 这几天在写 shell 脚本,学到不少,但是没啥心得之类的,有空可以写个总结(但是大概率不会发表) 现在不算很忙,想再学一点 消息队列相关知识 目前比较出名的也就 RabbitMQ 和 Kafk ...