TIJ——Chapter Four:Controlling Execution
同上一章,本章依然比较简单、基础,因此只是做一些总结性的笔记。
1、 不像C和C++那样(0是假,非零为真),Java不允许用一个数字作为boolean值。
2、 C中,为了给变量分配空间,所有变量的定义必须在代码块前面。而C++和Java中没有这个限制,它允许更加自然的代码
风格,而且使得代码更容易理解。
3、 使用Foreach语法,我们不必创建一个用来遍历各个项的整型值,foreach自动的为我们提供每一个项。
4、 如果在返回值为void的方法中没有return语句,那么它隐式地在方法的结尾处返回,因此return语句并不总是必须的。然
而,如果方法声明返回任何非void类型,我们必须保证代码的每个执行路径返回恰当的值。
5、 Java允许在循环体之前设置标签,并且循环体和标签之间不能有任何语句,它的主要作用是可以跳出多层循环,而break和
continue只能打断当前的循环。
6、 The switch statement is a clean way to implement multiway selection(i.e., selecting from among a
number of different execution paths), but it requires a selector that evaluates to an integral value, such
as int or char. If you want to use, for example, a string or a floating point number as a selector, it won’t
work in a switch statement. For non-integral types, you must use a series of if statements. BTW, Java
SE5’s new enum feature helps ease this restriction, as enums are designed to work nicely with switch.
TIJ——Chapter Four:Controlling Execution的更多相关文章
- TIJ——Chapter Twelve:Error Handling with Exception
Exception guidelines Use exceptions to: Handle problems at the appropriate level.(Avoid catching exc ...
- Thinking in Java,Fourth Edition(Java 编程思想,第四版)学习笔记(五)之Controlling Execution
In Java, the keywords include if-else,while,do-while,for,return,break, and a selection statement cal ...
- TIJ——Chapter Two:Everything Is an Object
If we spoke a different language, we would perceive a somewhat different world. Ludwig Wittgenstein( ...
- TIJ——Chapter One:Introduction to Objects
///:~容我对这个系列美其名曰"读书笔记",其实shi在练习英文哈:-) Introduction to Objects Object-oriented programming( ...
- TIJ——Chapter Eleven:Holding Your Objects
Java Provides a number of ways to hold objects: An array associates numerical indexes to objects. It ...
- TIJ——Chapter Eight:Polymorphism
The twist |_Method-call binding Connecting a method call to a method body is called binding. When bi ...
- TIJ——Chapter Seven:Reusing Classes
Reusing Classes 有两种常用方式实现类的重用,组件(在新类中创建存在类的对象)和继承. Composition syntax Every non-primitive object has ...
- TIJ——Chapter Five:Initialization & Cleanup
Method overloading |_Distinguishing overloaded methods If the methods hava the same name, how can Ja ...
- TIJ——Chapter Fourteen:Type Information
Runtime type information(RTTI) allows you to discover and use type information while a program is ru ...
随机推荐
- 跟我一起了解koa(一)
安装koa2 1.初始化package.json npm init 2.新建app.js,并且安装koa cnpm install --save koa //app.js const koa = re ...
- 读取复杂结构的yml配置项
1.yml配置项示例:(List的集合在第一项前面加 “-”) rabbitmqsetting: exchangeList: - name: e1 type: topic bindingList: - ...
- 移动端canvas刮刮乐
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta cont ...
- [转]js的键盘事件
类型 键盘事件用来描述键盘行为,主要有keydown.keypress.keyup三个事件 keydown 当用户按下键盘上的任意键时触发,如果按住不放的话,会重复触发该事件 <div id=& ...
- Hibernate中的Query
//1:创建query对象,方法里面写hql语句 Query query = session.createQuery("from User"); //2:利用query对象中的方法 ...
- FreeMarker 对null值的处理技巧
以下引用官方描述: ? The FreeMarker template language doesn't know the Java language null at all. It doesn't ...
- mysql创建数据库指定utf8编码
CREATE DATABASE IF NOT EXISTS dbname DEFAULT CHARSET utf8;
- 荷畔微风 - 在函数计算FunctionCompute中使用WebAssembly
WebAssembly 是一种新的W3C规范,无需插件可以在所有现代浏览器中实现近乎原生代码的性能.同时由于 WebAssembly 运行在轻量级的沙箱虚拟机上,在安全.可移植性上比原生进程更加具备优 ...
- Data Lake Analytics IP白名单设置攻略
当我们成功开通了 DLA 服务之后,第一个最想要做的事情就是登录 DLA 数据库.而登录数据库就需要一个连接串.下面这个页面是我们首次开通 DLA 之后的界面,在这里我们要创建一个服务访问点. 在上面 ...
- 【CS Round #44 (Div. 2 only) B】Square Cover
[链接]点击打开链接 [题意] 给你一个n*m的矩形,让你在其中圈出若干个子正方形,使得这些子正方形里面的所有数字都是一样的. 且一样的数字,都是在同一个正方形里面.问你有没有方案. [题解] 相同的 ...