Notes quiz (2)

Variable is to apply memory to store value.
In other words, when the variable is created, the
need to apply for space in memory.
By defining different types of variables,
you may be stored integer, decimal or character in memory.
Java's two data types:
Built-in data types --- basic data types.
Reference data types --- reference data types.
Built-in data types
Java language provides eight basic types.
Six kinds of digital type (four integer, two floating-point type),
int float
byte
minimum is -128 (-2 ^ 7);
the maximum value is 127 (2 ^ 7-1);
the default value is 0
Short;
minimum -32768 (-2 ^ 15);
the maximum value is 32767 (2 ^ 15--1);
The minimum value is -2,147,483,648 (-2 ^ 31);
the maximum value is 2,147,483,647 (2 ^ 31--1);
general default integer variable int type;
the default value is 0;
long
minimum is -9,223,372,036,854,775,808 (-2 ^ 63);
the maximum value is 9,223,372,036,854,775,807 (2 ^ 63-1);
this type is mainly used in the system requires a relatively large integer;
the default value is 0L;

A character type,
there is a Boolean.
float data type is single-precision, 32-bit, IEEE 754 compliant floating point standard;
float can save memory space when storing large floating groups;
the default value is 0.0f;
The same can not be represented by a double precision value, such as currency;
the default value is 0.0d;
examples: double d1 = 123.4.
Six digital type,
byte Long Short int;
float Double
boolean:
boolean data type represents one bit of information;
only two values: true and false;
these types are only recorded as a sign of
true / false case;
the default value is false;
examples: boolean one = true.
{} ; () ; [] --- empty. Non-empty.
"Hello there" " " ""
The minimum value is \ u0000 (that is, 0);
the maximum value is \ uFFFF (ie 65,535);
char data type can be stored any character;
examples: char letter = 'A' ;.
char 
''
 Objects, arrays are reference data types.
 The default for all reference types are null.
 A reference variable can be used to refer to any
 type of compatible.
 extends 
 implements
 例子:Site site = new Site("Runoob")。
 构造方法 。
变量  x = 10
x = 20
---x = 20
--------
pi  = 3.14
pi = 3.1415926
Java 常量。
常量在程序运行时是不能被修改的。
在 Java 中使用 final 关键字来修饰常量,
声明方式和变量类似:
final double  PI = 3.14;
MAX_VALUE
虽然常量名也可以用小写,
但为了便于识别,
通常使用大写字母表示常量。
在Java语言中,
所有的变量在使用前必须声明。
声明变量的基本格式如下:
type identifier [ = value][, identifier [= value] ...] ;
int money ;
int money = 1000;
int money = 1000, age = 18;
int money , age ;
Java语言提供了很多修饰符,
主要分为以下两类:
访问修饰符
非访问修饰符
修饰符用来定义类、
方法或者变量,通常放在语句的最前端。
我们通过下面的例子来说明:
default (即默认,什么也不写): 在同一包内可见,不使用任何修饰符。使用对象:类、接口、变量、方法。
private : 在同一类内可见。使用对象:变量、方法。 注意:不能修饰类(外部类)
public : 对所有类可见。使用对象:类、接口、变量、方法
protected : 对同一包内的类和所有子类可见。使用对象:变量、方法。

非访问修饰符
为了实现一些其他的功能,Java 也提供了许多非访问修饰符。
static 修饰符,用来修饰类方法和类变量。
final 修饰符,用来修饰类、方法和变量,
final 修饰的类不能够被继承,
修饰的方法不能被继承类重新定义,
修饰的变量为常量,是不可修改的。
abstract 修饰符,用来创建抽象类和抽象方法。
synchronized 和 volatile 修饰符,主要用于线程的编程。
Java 运算符
计算机的最基本用途之一就是执行数学运算,
作为一门计算机语言,
Java也提供了一套丰富的运算符来操纵变量。
我们可以把运算符分成以下几组:
算术运算符
关系运算符
位运算符
逻辑运算符
赋值运算符 =
其他运算符

A = 10
B = 20
A + B = 30
A - B = -10
A * B = 200
A / B = 0
A % B = 10 % 取余数 ,就是左边和右边做除法把余数当成
结果返回。

++
A ++ 对自身加 1
B --
2、前缀自增自减法(++a,--a): 先进行自增或者自减运算,再进行表达式运算。
3、后缀自增自减法(a++,a--): 先进行表达式运算,再进行自增或者自减运算 实例:
 
==
!=
! - --- not
!true --- > false
>
<
>=
<=
&& 称为逻辑与运算符。and
当且仅当两个操作数都为真,
条件才为真。
并且。
|| or 或者。
a = 5,b = 2,c = 3
a > b && b > c
a > b || b > c
= 简单的赋值运算符,
   将右操作数的值赋给左侧操作数
   C = A + B
   将把A + B得到的值赋给C
+=  加和赋值操作符,
它把左操作数和右操作数相加
赋值给左操作数 
C += A 等价于C = C + A
条件运算符( ? : )
条件运算符也被称为三元运算符。
该运算符有3个操作数,
并且需要判断布尔表达式的值。
该运算符的主要是决定哪个
值应该赋值给变量。
variable x = (expression) ? value if true : value if false
? 前面的 boolean 表达式 成立就返回 左边的。
 result = 5 > 2 ? 5 : 2 
 instanceof 运算符
该运算符用于操作对象实例,检查该对象是否是一个特定类型(类类型或接口类型)。
instanceof运算符使用格式如下:
( Object reference variable ) instanceof  (class/interface type)
instanceof
 stu instanceof Person -----> true .
 
如果运算符左侧变量所指的对象,
是操作符右侧类或接口(class/interface)的一个对象,
那么结果为真。
下面是一个例子:
Java运算符优先级
()
x + 5 - 5 * y
ava中有三种主要的循环结构:
循环
{} 代码块。
  
  {
   指令。print("nihaomaxiaojiejie")
  }
while 循环.
do…while 循环.
for 循环.
while 循环
while是最基本的循环,它的结构为:
boolean 类型 布尔类型。
while( 布尔表达式 ) {
  //循环内容
}
只要布尔表达式为 true,循环就会一直执行下去
print("nihaomaxiaojiejie")
i = 1
while( i <= 10 ) {
  //循环内容
 print("nihaomaxiaojiejie")
 i = i + 1
 i ++
 i += 1
}
do…while 循环
对于 while 语句而言,
如果不满足条件,则不能进入循环。
但有时候我们需要即使不满足条件,
也至少执行一次。
do…while 循环和 while
 循环相似,不同的是,
do…while 循环至少会执行一次。
do {
       循环内容。
}while(布尔表达式);
i = 1
do{
 print("nihaomaxiaojiejie");
 i ++
}while(i<=10)

Guess you like

Origin www.cnblogs.com/7920284109q/p/11307476.html