JAVA编程基础

1.基本的语法格式

[修饰符]class类名{

代码

}

2.单行注释以“//”表示,符号后面跟注释内容。

  多行注释,以“/*”开头,以*/结尾。

  列如 /* byte i = 1;

              int   x = i;*/ 

3.文档注释以符号/**开头,以*/结尾。

注:多行注释中可以嵌套使用单行注释,但多行注释中不能嵌套使用多行注释。

JAVA关键字

abstract    assert    boolean    break             byte

case         catch      char         class              const

continue   default    do            double            else  

enum       extends   final         finally              float

for            togo         if          implements        import

instanceof   int       interface    long               native

new          package   private     proteced        public

return       strictfp      short        static              super

switch      synchronized  this     throw            throws

transient   try            void          volatile           while

JAVA常用标识符

注:1.不能以数字开头

        2.也不能是JAVA中的关键字

       3.不能含空格特殊字符

JAVA中 变量与常量

1.变量定义 储存应用程序数据的内存单元称之为变量。

  定义的标识符就是变量名。

 内存单元中存储的数据就是变量的值。

变量类型 变量名 [=初始值]

变量的数据类型 

1.基本数据类型 数值型(整数类型(byte,short,int,long)浮点类型(folat,double)),字符型(char),布尔型(boolean)

引用数据类型

2.类(class),接口(interface),数组,枚举(enum),注解(Annotation)

byte           8位(1字节)

short         16位(2字节)

int              32位(4字节)

long           64位(8字节)

float           32位(4字节)

double       64位  (8字节) 

char           16位(2字节)

boolean 只有两个值,true和false

变量的类型转换

自动类型转换 把一个类型取值范围小的数值直接赋给另一个取值范围大的数据类型变量时,系统会进行自动类型的转换,否则就会进行强制类型转换。

强制类型转换也叫显示类型转换,指的是两种数据类型之间的转换需要显式声明。当目标类型的取值范围小于源类型,或两种类型彼此不兼容时,因系统无法进行自动转换,则需要进行强制类型的转换。

变量的作用域

变量需要在它的作用范围内使用,这个作用范围称为变量的作用域。

JAVA中的常量

1.整数常量

整数常量是整数类型的数据,分为二进制,八进制,十进制,十六进制这4种表现形式。

2.浮点数常量

分为float单精度浮点数和double双精度浮点数两种类型。单精度浮点数后面以F或f结尾,双精度浮点数则以D或d结尾。

3.字符常量

字符常量用于表示一个字符,一个字符常量要用一对 '  ' 引起来,可以是英文字母,数字,标点符号以及由转义序列来表示的特殊字符。

4.字符串常量

表示一串字符,一个字符串常量要用一对"  "引起来。

5.布尔常量

布尔常量即布尔类型的两个值true和false,该常量用于区分一个条件的真假。

6.null常量

null常量只有一个值null,表示对象的引用为空。

JAVA中的运算符

1.算数运算符

运算符                   运算                                范例                                     结果

  +                         正号                              a=3;+a;                                     3

  —                       负号                              b=4;—b;                                —4

 +                          加                                 5+5                                          10

—                          减                                  6—4                                         2

✳                          乘                                   3✳4                                        12

/                           除(取整)                     7/5                                            1

%                         取模                                 7%5                                         2

++                        自增(前 )                   a=2;b=++a;                             a=3;b=3;

++                        自增(后)                    a=2;b=a++;                             a=3;b=2;

— —                    自减(前)                    a=2;b=— —a;                         a=1;b=1;

— —                    自减(后)                    a=2;b=a— —;                       a=1;b=2;

赋值运算符

运算符                   运算                                范例                                     结果

=                           赋值                               a=2;b=1;                          a=2; b=1;

+=                       加等于                             a=2;b=1;a+=b;                      a=3; b=1;

—=                      减等于                             a=3;b=2;a—=b;                    a=1; b=2;

✳=                      乘等于                             a=3;b=2;a✳=b;                    a=6; b=2;

/=                        除等于                             a=3;b=2;a/=b;                       a=1;b=2;

%=                      模等于                             a=3;b=2;a%=b;                     a=1;b=2;

注:在赋值运算符号中,强制类型转换会自动执行。

本人新手小白,看书写的总结。如有不对,还望各位大佬指点!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Programming is an art. Although traditional art imitates life, programming simulates life. Every abstract concept in programming, and to a great extent in the fi eld of computer science, has its roots in our daily life. For example, humans and possibly all other living forms were multiprocessing long before the term entered into computer science lingo. Th erefore, any concept in programming can in fact be illustrated through examples from our dayto-day life. Such an approach not only enables the student to assimilate and internalize the concept presented in a programming situation but also provides a solid foundation for the very process of programming, namely, the simulation of the real world. Unfortunately, textbooks currently on the market do not exploit this fact through examples or meaningful discussions. Th us, for many students, an abstract concept remains abstract. Th is is especially true in the case of object-oriented programming. Th e “wow moment” one gets by seeing programming as a simulation of the real-world situation is never realized. Th is book on Java programming teaches object-oriented design and programming principles in a completely integrated and incremental fashion. Th is book allows the reader to experience the world we live in as object-oriented. From the very outset the reader will realize that everything in this world is an object. Every concept of object-oriented design is fi rst illustrated through real-life analogy. Corresponding Java language constructs are introduced in an integrated fashion to demonstrate the programming required to simulate the real-world situation. Instead of compartmentalizing all the object-oriented concepts into one chapter, this book takes an incremental approach. Th e pedagogy of this book mirrors the classroom style the author has developed over the years as a teacher of computer science. In particular, every programming concept is introduced through simple examples followed by short programming examples. Case studies at the end of each chapter illustrate various design issues as well as the usefulness of many new concepts encountered in that chapter. Java has emerged as the primary language for soft ware development. From a soft ware engineering perspective, object-oriented design has established itself as the industry standard. Th us, more and more teaching institutions are moving toward a CS1 course that teaches Java programming and object-oriented design principles. A common approach followed in many textbooks on the market is to introduce object-oriented concepts from the very beginning and ignore many traditional programming techniques completely. Th e objective of this book is to present object-oriented programming and design without compromising the training one needs on traditional programming constructs and structures.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值