java学习笔记(一) introduction

intermediate language 中间语言

中间语言就是把我们使用的编程语言和机器使用的machine language,进行相互转化的中间语言。

The programs are first translated into an intermediate language that is the same for all appliances (or all computers), and then a small, easy-to-write—and hence, inexpensive—program translates this intermediate language into the machine language
for a particular appliance or computer.

 

code 代码

程序的一部分   The word code is commonly used to mean a program or part of a program.

 

byte 字节

一个字节就是指存储器中的一个单元。电脑可读的信息就是存储在bytes中

A  byte is a small unit of storage (eight bits to be precise). Computer-readable information is typically organized into bytes.

 

byte-code

So the term byte-code suggests a program that is readable by a computer as opposed to a person.

 

object-oriented programming (OOP) 面向对象程序

OOP是把程序看做是由不同的对象和连接对象的行为组成

OOP is a programming methodology that views a program as similarly consisting of objects that interact with each other by means of actions

 

object(对象)

The objects are called, appropriately enough, objects.

 

method ( 方法)

 接对象的行为叫方法。 The actions that an object can take are called methods.

 

type & class ( 类型 / 类)

同样类型的对象,我们称为同一类

Objects of the same kind are said to have the same type or, more often, are said to be in the same class. 

 

模拟机场的系统中,所有的飞机都是一类,称为 Airplane class;所有的对象具有相同的方法,比如 taking off, flying a specific location, landing to ; 当我们给对象设置数据的时候,他们就是不同的角色,比如我们可以给这个类设置飞行速度和飞行高度两个参数

For example, in an airport simulation program, all the simulated airplanes might belong to the same class, probably called the  Airplane class. All objects within a class have the same methods. Thus, in a simulation program, all airplanes have the same methods (or possible actions), such as taking off, flying to a specific location, landing, and so forth. However, all simulated airplanes are not identical. They can have different characteristics, which are indicated in the program by associating different data (that is, some different information) with each particular airplane object. For example, the data associated with an airplane object might be two numbers for its speed and altitude

 

application program & main (主类)

运行Java程序时,运行时系统会自动调用名为main 的方法

As we will see, a Java application program is a class with a method named  "main" ; when you run the Java program, the run-time system automatically invokes the method named  "main"

 

Applets &  Application

Applets means a little Java application. Applets always use a windowing interface.

An application program may have a windowing interface or use simple console I/O.

Applets and applications are almost identical(相同的)

The difference is that applications are meant to be run on your computer like any other program, whereas an
applet is meant to be run from a Web browser, and so can be sent to another location on the Internet and run there

 

Applet Viewer (小程序查看器)

调试辅助工具,而不是作为允许用户运行小程序的最终环境

A debugging aid and not as the final environment to allow users to run applets

 

argument

the things inside the parentheses(括号) is called an argument,which provides information needed by the method to carry out its action

 

invoking(调用)

when an object performs an action using a method 

 

sending a message / Invoking a method

调用方法有时也被称为向对象发送消息。

Invoking a method is also sometimes called sending a message to the object.

 

assignment operator (赋值符号)

the equal sign is used as the assignment operator, which is an instruction to set the value of the variable on the left-hand side of the equal sign

 

high-level languages

Most modern programming languages are designed to be (relatively) easy for people to write and to understand.

 

machine language

The language that the computer can directly understand 

 

low-level language

Machine language or any language similar to machine language 

 

compiler 编译器 & compiling 

A compiler is a program that translates a high-level-language program, such as a Java program, into an equivalent low-level-language program.and the translation process is called compiling.

 

Byte-code 字节码

字节码不是任何特定计算机的机器语言;它是 一种虚拟计算机的机器语言,称为Java虚拟机(JVM)。

Byte-code is not the machine language for any particular computer; it is the machine language for a fictitious computer called the Java Virtual Machine (JVM).

 

interpreter 解释器 & Just-In-Time (JIT) compiler 实时(JIT)编译器

JVM有两种方法可以做到这一点转换:通过解释器和实时(JIT)编译器。

There are two ways the JVM can do this translation: through an interpreter and through a Just-In-Time (JIT) compiler.

 

1.2

identifier 标识符

The name of a variable (or other item you might define in a program) 

Java标识符不能以数字开头,但是只能由是字母、数字或下划线(_)符号组成

A Java identifier must not start with a digit, and all the characters must be letters, digits, or the underscore (_) symbol.

 

区分大小写,因此rate RATE Rate是三个不同的变量

Java is a case-sensitive language; that is, it distinguishes between upper- and lowercase letters in the spelling of identifiers. Hence, the following are three distinct identifiers and could be used to name three distinct variables:
     

declare 声明

变量必须被声明才可以被使用。声明一个变量就是明确这个定义这个变量的数据类型,比如int、long、string等

When you declare a variable, you are telling the compiler—and, ultimately, the computer—what kind of
data you will be storing in the variable

 声明的一个事例:
Type Variable_1, Variable_2,. . .;

int count, numberOfDragons, numberOfTrolls;
char answer;
double speed, distance;

 

primitive types 基本类型

Java has basic types for characters, different kinds of integers, and different kinds of floating-point numbers (numbers with a decimal point), as well as a type for the values true and  false . These basic types are known as primitive types

如下是常见的基本类型

                       

 

uninitialized 未初始化的

被声明但是没有被赋值的变量

A variable that has been declared but that has not yet been given a value by some means

未初始化的值会给一个默认的值,但是是一般情况

an uninitialized variable may be given some default value, but this is not true in all cases. 

                 

 

运算符号

 + (addition),  − (subtraction)   * (multiplication)  / (division)    % (modulo, remainder).

运算的结果取决于运算两个数字的结果,如果两个都是int,那么结果就是int。如果一个double一个int,那么结果就是double

If  both operands (that is, both numbers) are of type  int , then the result of combining them with an arithmetic operator is of type  int . If one, or both, of the operands is of type  double , then the result is of type  double 

double a = 5 (正确);int b = 5.0 (错误);向上转可以,向下不可。

              

运算的优先级(没有括号的时候,有括号先算括号)

                    

 

integer and floating-point division 整数和浮点数除法

两个int的division运算完还是int,同时不会四舍五入;

比如:10/3 is  3 (not  3.3333 …),  5/2 is 2 (not  2.5 ), and  11/3 is  3 (not  3.6666 …).

%符号可以得到通过int除法而丢失的数据。其实就是一个得到余数的过程;可以通过%运算判断是否为奇偶数;

The operator  % can be used with operands of type  int to recover the information lost when you use  / to do division with numbers of type  int 

例如:System.out.println("14 divided by 3 is " + (14 / 3));    System.out.println("with a remainder of " + (14 % 3));

          14 divided by 3 is 4                                                     with a remainder of 2

                    

浮点数进行division运算得到的结果也是大约的过程,比如: 1.0/3.0 is equal to 0.3333333...但是,根据数字存储的位数,当存储10 digits的时候,结果就是 1.0/3.0 is stored as  0.3333333333

 Some floating-point numbers lose accuracy when they are stored in the computer.

 

Type casting

类型转换采用一种类型的值,并转换成另一种类型的值

A type cast takes a value of one type and produces a value of another type that is Java’s best guess of an equivalent value.      

(double)m is a type cast

当int转换成double(像上句所示)时,是可以正常转换不会改变值的。我们一般称上句那种转换为强制转换。 type coercion.

但是如果是float 变成int, 强制转换也是可以的,但是会丢失全部的小数,比如::  (int)2.9 is  2 ; it is not  3

Note that when type casting from a floating-point type to an integer type, the number is truncated, not rounded。

 

Increment and decrement operators

The increment operator ++ adds one to the value of a variable.

The decrement operator −− subtracts one from the value of a variable.

n++ 和 ++n 的 区别:(n-- 和  --n同理)

a = n++ ; n = 1 --> n =2 ; a = 1;

a = ++n; n = 1 --> n = 2; a = 2;

Notice the expression  2*(n++) . When Java evaluates this expression, it uses the value that  number has before it is incremented, not the value that it has after it is incremented.

int n = 2;
int valueProduced = 2*(n++);
System.out.println(valueProduced);
System.out.println(n);

--> n = 3; valueProduced = 4;

 

The expression  ++n also increments the value of the variable  n by one, but it evaluates to the value  n has after it is increased.

int n = 2;
int valueProduced = 2*(++n);
System.out.println(valueProduced);
System.out.println(n);

--> n =3 ; valueProduced  = 6;

 

1.3 The Class String 

strings不是一个基本类型而是一个类

There is no primitive type for strings in Java. However, there is a class called  String that can be used to store and process strings of characters.

           

 

concatenation of Strings(字符串的连接)

使用 “ + ” 就是把两个字符串连接起来,但是不会自动添加空格等,就是紧密的连接,

When you use the + operator on two strings, the result is the string obtained by connecting the two strings to get a longer string.

String noun = "Strings";
String sentence;
sentence = noun + "are cool.";
System.out.println(sentence);

--> sentence = Stringsare cool;

如果想要有空格:sentence = noun + " are cool."; 

            

String 的方法

             

 

             

             

              

              

                 

字符串中字符的位置是从0开始计数的,空格也同样计入index中

Positions are counted starting with 0, not with 1. So, in the string  "Surf time" ,  'S' is in position  0 ,  'u' is in position  1 , and so forth. 描述是: 'S' is at index  0 ,  'u' is at index  1 , and so on.

     

 

escape sequences 反义

\ 反斜杠后的内容失去了其原有的含义。一般\就是转义的意思。比如想打印出(“ ”)这个符号,如果按照想句号(。)这种形式打印是不可的,比如通过转义符号,因为(“)在java中有特殊的含义。

A backslash,  \ , preceding a character tells the compiler that the character following the  \ does not have its usual meaning. Such a sequence is called an escape sequence or an escape character.

比如:abc\\def 表示的是 abc\def

              

 

 

 immutable object  不可变对象

比如String就是一个不可变的对象

In Java, an object of type  String is an immutable object, meaning that the characters
in the  String object cannot be changed. 

 

1.4 Program Style

Naming Constants 定义常量

初始化的时候做一定的处理,可以设置常量,而这些量在接下来的使用过程中不可以改变、该中变量必须在main方法之外定义,

Java provides a way of marking an initialized variable so that it cannot be changed.

    

 

comments 注释

// 注释一行。如果要注释多行,要把每行都写上// ( line comments or inline comments.)

/*   */ 其中的内容都会注释掉,可多行。(block comments)

Java附带了一个名为JavaDoc的程序,它将自动从您定义的类中提取文档。JavaDoc程序的工作方式决定了您通常使用每种注释的时间。

Java comes with a program called  javadoc that will automatically extract documentation from the classes you define. The workings of the  javadoc program dictate when you normally use each kind of comment.

javadoc程序将在某些情况下提取/**/注释,但不会提取//注释。

The  javadoc program will extract a  /* */ comment in certain situations, but it will not extract a  // comment

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值