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 ...
随机推荐
- [Array]122. Best Time to Buy and Sell Stock II(obscure)
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- 【python之路41】web框架
一.web框架介绍 一共有两种web框架 1.既包含socket又能逻辑处理 tornado框架 2.只能处理逻辑 Django bottle flask 二.web框架的本质 众所周知,对于所有的 ...
- 【noip】跟着洛谷刷noip题
传送门 1.铺地毯 d1t1 模拟 //Twenty #include<cstdio> #include<cstdlib> #include<iostream> # ...
- mybatis深入理解(七)-----MyBatis缓存机制的设计与实现
缓存设计 MyBatis将数据缓存设计成两级结构,分为一级缓存.二级缓存: 一级缓存是Session会话级别的缓存,位于表示一次数据库会话的SqlSession对象之中,又被称之为本地缓存.一级缓存是 ...
- WebBrowser修改默认白色背景
背景:在使用Winform的WebBrowser显示网页的时候,在网页还未加载完成之前会显示白色,刚好网页内容呈现黑色,这样视觉效果上就十分差,想把这层白色的去掉. 试了很久之后发现根本去不掉,应 ...
- Socket与TcpClient的区别
原文:Socket与TcpClient的区别 Socket和TcpClient有什么区别 原文:http://wxwinter.spaces.live.com/blog/cns!C36588978AF ...
- P1460 健康的荷斯坦奶牛 Healthy Holsteins
P1460 健康的荷斯坦奶牛 Healthy Holsteins 题目描述 农民JOHN以拥有世界上最健康的奶牛为傲.他知道每种饲料中所包含的牛所需的最低的维他命量是多少.请你帮助农夫喂养他的牛,以保 ...
- c++的引用用法
一.引用简介 引用就是某一变量(目标)的一个别名,对引用的操作与对变量的直接操作完全一样. 引用的声明方法:类别标识符&引用名=目标变量名: 例1: int a; int &ra=a; ...
- eclipse中部署web项目
因为eclipse是免费的,所以很多企业都会选用eclipse作为开发工作,那么我们就需要熟练使用eclipse部署web项目. 第一步:选择window -> preferences ,选择s ...
- JZOJ 5459 购物
Description X 城的商场中,有着琳琅满目的各种商品.一日,小X 带着小Y 前来购物,小Y 一共看中了n件商品,每一件商品价格为Pi.小X 现在手中共有m个单位的现金,以及k 张优惠券.小X ...