当前位置:文档之家› java语言基础教程

java语言基础教程

java语言基础教程
java语言基础教程

一、标识符及字符集

Java语言规定标识符是以字母、下划线"_"或美元符号"$"开始,随后可跟数字、字母、下划线或美元符号的字符序列。Java标识符大小写敏感,没有长度限制,可以为标识符取任意长度的名字,但关键字不能作为标识符。为增强程序可读性,Java作如下的约定:

1.类、接口:通常使用名词,且每个单词的首字母要大写

2.方法:通常使用动词,首字母小写,其后用大写字母分隔每个单词

3.常量:全部大写,单词之间用下划线分隔

4.变量:通常使用名词,首字母小写,其后大写字母分隔每个单词,避免使用$符号。

Java语言使用国际字符集(Unicode)。Unicode字符集定义了一套国际标准字符集。通常的ASCII码是8位的,而Unicode字符集中的每个字符占16位,即2个字节,整个字符集共包括65336个字符,兼容ASCII,排在Unicode字符集最前面的256个字符就是ASCII码。Unicode除了可以表示256个ASCII码外,还可以表示汉字、拉丁语、希腊字母、朝鲜语等。

Java标识符总结:1.由字母、数字、_或$组成,不能以数字开头;2.严格区分大小写;3.长度不限

二、关键字

Java常用关键字列表如下:

分类如下:

1.访问控制:private 私有的 protected 受保护的 public 公共的

2.类、方法和变量修饰符abstract 声明抽象 class 类 extends 扩允,继承final 终极,不可改变的implements实现 interface 接口 native 本地 new 新,创建 static 静态 strictfp 严格,精准synchronized 线程,同步 transient 短暂 volatile 易失

3.程序控制语句 break 跳出循环 continue 继续 return 返回 do 运行while 循环 if 如果 else 反之 for 循 instanceof 实例 switch 开关 case 返回开关里的结果 default 默认

4.错误处理 catch 处理异常 finally 有没有异常都执行 throw 抛出一个异常对象

throws 声明一个异常可能被抛出 try 捕获异常

5.包相关import 引入 package 包

6.基本类型 boolean 布尔型 byte 字节型 char 字符型 double 双精度float 浮点 int 整型 long 长整型 short 短整型 null 空 true 真 false 假

7.变量引用 super 父类,超类 this 本类 void 无返回值

注意:1、所有的java关键字都是小写的 2、goto 和const 是保留关键字,在java 中没使用3、strictfp 和volatile 不常用; sizeof 、then 不是关键字。

4 、true,false,null 不是严格意义上的关键字,而是literals 。

面向对象的基本概念

3.1对象

万物皆对象,一辆汽车是一个对象,一个人是一个对象。

3.2类

类就是对象的模板,就像是一辆汽车的图纸,有了图纸才能造车

3.3接口

接口就像是一个更简单的图纸,它画出了汽车都有那些基本的构造和功能,而怎么去实现这些功能要有更详细的图纸(前面所谓的“类”)

3.4包

就是分类封装我们的图纸(类)的“工具”。

3.5 附加练习题:

1.Real-world objects contain state and behavior.

2.A software object's state is stored in fields.

3.A software object's behavior is exposed through methods.

4.Hiding internal data from the outside world, and accessing it only through publicly exposed methods is known as dataencapsulation.

5.A blueprint for a software object is called a class.

https://www.doczj.com/doc/4b11141661.html,mon behavior can be defined in a superclass and inherited into a subclass using the extends keyword.

7.A collection of methods with no implementation is called

an interface.

8.A namespace that organizes classes and interfaces by

functionality is called a package.

9.The term API stands for Application Programming Interface。

4 java语言基础

4.1 变量的命名方法:

变量名只能包含:字母、数字、下划线以及美元符号(“$”),开头不能是数字,命名采用驼峰式命名法。

4.2 java的基本数据类型有8种:

int、byte、short、char、long、double、boolean、float.

4.3 java支持的数据类型以及默认值

4.4 习题与答案

1. The term "instance variable" is another name for non-static field.

2. The term "class variable" is another name for static field.

3.A local variable stores temporary state; it is declared inside a method.

4. A variable declared within the opening and closing parenthesis of a method is called a parameter.

5. What are the eight primitive data types supported by the Java programming language? byte, short, int, long, float, double, boolean, char

6. Character strings are represented by the class https://www.doczj.com/doc/4b11141661.html,ng.String.

7. An array is a container object that holds a fixed number of values of a single type.

4.5 运算符

相关主题
文本预览
相关文档 最新文档