Java编程基础知识(一)

本文详细介绍了Java编程的基础知识,包括基本语法结构,如类的声明;注释的使用,包括单行、多行和文档注释;关键字与标识符的规则;接着讲解了常量和变量的概念及数据类型;深入探讨了算术、关系和赋值运算符的用法,并举例说明;最后提到了数据输入的相关概念。适合初学者入门学习。

目录

一.Java的基本语法

1.Java的基本语法格式

 2.Java中的注释

3.Java中的关键字

Java中的标识符

二.Java中的常量与变量

1.常量

2.变量

三.Java中的运算符

四.数据输入


一.Java的基本语法

1.Java的基本语法格式

        编写Java程序必须先声明一个类,然后再类中编写实现需求的业务代码,其语法格式如下:

​
[修饰符] class 类名{

    程序代码

}

​

 2.Java中的注释

        注释概述:

            注释是在程序指定位置添加说明性信息    

            注释不参与程序运行,仅起到说明作用         

        注释分类:

                

 

3.Java中的关键字

 

               

 

Java中的标识符

        

 

二.Java中的常量与变量

1.常量

        

 

2.变量

        

 

        数据类型:

                

 

        类型转换:

                

 

三.Java中的运算符

  • 算术运算符
    • 符号

      作用

      说明

      +

      参看小学一年级

      -

      参看小学一年级

      *

      参看小学二年级,与“×”相同

      /

      参看小学二年级,与“÷”相同

      %

      取余

      获取的是两个数据做除法的余数

    • 注意事项:

      /%的区别:两个数据做除法,/取结果的%取结果的余数

      整数操作只能得到整数,要想得到小数,必须有浮点数参与运算。

  • 关系运算符
    • 符号

      说明

      ==

      a==b,判断ab的值是否相等,成立为true,不成立为false

      !=

      a!=b,判断ab的值是否不相等,成立为true,不成立为false

      >

      a>b,判断a是否大于b,成立为true,不成立为false

      >=

      a>=b,判断a是否大于等于b,成立为true,不成立为false

      <

      a<b,判断a是否小于b,成立为true,不成立为false

      <=

      a<=b,判断a是否小于等于b,成立为true,不成立为false

    • 注意事项:

      关系运算符的结果都是boolean类型,要么是true,要么是false

      千万不要把“==”误写成“=”。

  • 赋值运算符
    • 符号

      作用

      说明

      =

      赋值

      a=10,将10赋值给变量a

      +=

      加后赋值

      a+=b,将a+b的值给a

      -=

      减后赋值

      a-=b,将a-b的值给a

      *=

      乘后赋值

      a*=b,将a×b的值给a

      /=

      除后赋值

      a/=b,将a÷b的商给a

      %=

      取余后赋值

      a%=b,将a÷b的余数给a

  • 自增自减运算符

 

  • 符号

    作用

    说明

    ++

    自增

    变量的值加1

    --

    自减

    变量的值减1

        逻辑运算符:

符号

作用

说明

&

逻辑与

a&bab都是true,结果为true,否则为false

|

逻辑或

a|bab都是false,结果为false,否则为true

^

逻辑异或

a^bab结果不同为true,相同为false

!

逻辑非

!a,结果和a的结果正好相反

短路逻辑运算符:

 

优先级比较

四.数据输入

 

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.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值