Learning java --- variables

A good developer, Dauth
weave the most important programming ideas, breaking the shackles, giving top priority to think things behind, thinking proliferation
system analyst (business analysis, system design)

1) how to achieve junit unit test?

a) Junit third-party development tools, only jdk (jre) can be used directly, you must import jar (eclipse well supported, if necessary, it can be imported directly import)
b) class in the class required to wear a hat, It is a comment @Test
Note: a class unit executes a plurality of test method, executed out of order, out of order. Because the test does not need to distinguish between the actual development of the order. All tests are normal on the line.

2) junit how to achieve three methods?

3) Junit how to run the specified method to achieve?
Double click to run the method name, right-click menu to run junit test, on the implementation of this method only.
Extended: How to run two methods?
Software is not a panacea, and some can not be achieved. Junit can not go to specify more than one method. Either all or a!

Write code things by the book, each word is knocked out.
Eclipse has a very rich shortcuts, quick completion code
1) main
A designation of the time) to create a class

b) main + Alt + / (auto completion Code)
2) syso the Alt + + /

Today tasks: java basis for the development of language, syntax
1) keyword in java customize many names have special meaning, each representing meaning, to be used in a fixed place. Called a keyword.
Eclipse supports highlighting, keywords are displayed in purple, java provides 50+

Learning methods: all contests in each place, not a good way to learn, learn to know the focus.
For example: the keyword, for example, 51 or 52? Experts norm, learning, primary school, which is 50 more than what, what each role is, I would use a few?
You must encounter. Willing. Does not mean that all grasp, we must grasp the core.

For the average developer, dumb English, as long as they remember, some use a lot, with more natural to remember (class), some very rare strictfp not used.

Thoughts: These keywords are java defined above, let us use, we can define your own names?
Obviously you can, java name to define such identifiers own
class name: HelloWorld, method name: aaa, hello ()

Identifier:

You can not start with a number, but the numbers may be the end aaa123
special characters can be used, and underscores & other special characters try not to use
these rules do not rote, so wrong, eclipse will be prompted, you can make changes

2) The variables and constants
a) variable, the amount of change in the code may be reassigned x = 10, x = 20, x is called a variable.

b) constant, can only be assigned once, after not set again, if the setting error, fixed-coded values in development, the inevitable: PI = 3.14.6.18 fixed value.
a float the PI = 3.14f Final;
of The Final (final type) local variable (local variable) PI can not be assigned (access).
It MUST BE A blank and the using Not Assignment Compound

package test;
public class World {
public static void main(String[] args) {
	//变量
	int x = 10;		//定义一次,定义类型为整形
	System.out.println(x);
	
	x = 20;				//再次赋值
	System.out.println(x);
	
	//常量,常量变量名全大小,多个单词之间用下划线连接
	final float PI = 3.14f;
	System.out.println(PI);
	
	//PI = 5;	常量不能再次赋值
}}

3) java how expression data, each data has its characteristics
are very poor in the computer, only binary 0 and 1 only
human idiomatic expressions below, the computer can only 0 and 1, the computer how to handle these cases following it?
Figures, 10, 20, 10 may be accumulated number 30 + 20 =
floating, 3.14
characters, the keyboard a, b, c
level development language in which to do the conversion, the daily diet of human expression data types, the computer can identify automatically converted into 0 and 1.

Various types of data expression in life it?
8 Java provides basic data types, all expression.

This space is byte length corresponding to the type is stored in the memory space.
Thoughts?
The fewer bytes of storage for the benefits? Take up memory space smaller
the more the benefits of bytes of storage? Take up memory space large (bad), the numerical range expressed greater
use of these types are, if they can save enough, use a large good? Or small is good?
As far as possible to the next, the memory is a fixed size, 4g / 8g / 16g Anyway memory is in short supply, limited resources, the less your account, and other programs can be multi-point memory usage.

Variable is created, all in memory, the memory is a physical medium.
Computer how to express human-defined data types?

By the above expression, the human-defined type, can be converted to a computer can recognize 0 and 1, so that the computer can handle our data.
Computer unit: bit, 0 or 1 is
the eight basic types, usually in multiples of 2
A) byte, 1 byte = 8bit, 8 bit
B) short, 2 bytes 16bit =,
C) int,. 4 th byte
D) long, 8 bytes
E) float, 4 bytes
F) double, 8 bytes
G) char, 2 bytes
H) boolean, 1 byte
summarized: when using the basic 8 types , try to use less memory space type accounts

	package test;
	public class World {
	public static void main(String[] args) {
		//八种基本类型,字母都小写
		byte b = 125;
		short s = 100;
		int i = 10000;
		long l = 10000000;
		
		float f = 3.14f;
		double d = 3.14;		//写个带小数点的,默认是double
		
		char c = 'a';			//字母,字符类型使用单撇括起来
		//String s1 = "abc";	//字符串使用双引号括起来,字符串不是基本类型
		boolean n = true;		
		
	}}


> 看看基本类型最小值和最大值,也就是它的存储范围


	package test;
	public class World {
	public static void main(String[] args) {
		//八种基本类型,字母都小写
		byte b = 125;
		short s = 100;
		int i = 10000;
		long l = 10000000;
		
		float f = 3.14f;
		double d = 3.14;		//写个带小数点的,默认是double
		
		char c = 'a';			//字母,字符类型使用单撇括起来
		//String s1 = "abc";	//字符串使用双引号括起来,字符串不是基本类型
		boolean n = true;		
		
		//每种数据类型存储范围:
		System.out.println("字节byte类型:" + Byte.MIN_VALUE + "," + Byte.MAX_VALUE);
		System.out.println("短整型short类型:" + Short.MIN_VALUE + "," + Short.MAX_VALUE);
		System.out.println("整型int类型:" + Integer.MIN_VALUE + "," + Integer.MAX_VALUE);		//21亿,用的最多
		System.out.println("长整型long类型:" + Long.MIN_VALUE + "," +Long.MAX_VALUE);
		
		//一般开发使用不多,计算机计算整数更快
		System.out.println("单精度浮点数float类型:" + Float.MIN_VALUE + "," + Float.MAX_VALUE);
		System.out.println("双精度浮点数double类型:" + Double.MIN_VALUE +","+ Double.MAX_VALUE);
		
		//它们特殊,一般没有范围概念char:a~z,包括特殊字符:-_,%&
		System.out.println("字符char类型:" + Character.MIN_VALUE + "," + Character.MAX_VALUE);
		System.out.println("布尔boolean类型:"+ Boolean.FALSE + "," + Boolean.TRUE);
	}}

Question:
1) literal null, true, fasle
learning problems, in the end is the literal or keyword, do not go too seriously.
What are the most important to learn English? Exchange, and the exchange of people, rather than the tangled syntax.

If, as an expert, allusive, which it is supposed to tangle! ! ! But we are ordinary developers who want to do something out of what we should be doing! ! !

1) is not excellent training we want to do things, java employment, it is one one speaking. Five months before we talk about the third of the content. Learning Java training and excellent knowledge in the Internet architecture. Not java foundation.
2) You write these things behind tens of thousands of times, main teacher to write
more, write to understanding.

Review:
1) the Java keyword Again, where you learn to focus on? Not to tangle it is literal or keyword, null doing? true, false doing? Especially as a beginner focus on the application. You can not use these names in development. Including: java can not be used, main can not be used. Can cause errors.
2) identifier, developers define their own name, just starting, there are certain rules, can not begin with a number. Eclipse you write, if you do not meet specifications, error. Not rote knowledge, knowledge is now too large. We have in mind not remember. To find the core of things by rote.
3) variable (change in volume can be reassigned), constant (for the first time can not be reassigned after the assignment). These things do not have to memorize, write more naturally find standard. When you do not know how to write, copy the teacher.
4) eight basic variable types
a) byte, byte, 1 byte = 8bit bits, bits: 0 or. 1
B) Short, short integer, 127 -128 ~
C) int, shaping, 3W -3W ~
D) long, long integer, -21 billion to $ 2.1 billion
e) float, single-precision floating point number with decimals, 3.14,6.18
F) double, double precision floating point,
G) char, character 'a', 'b'; a ~ z is not a range, all printing is something, but we can not see
h) boolean, boolean type: true true, false false
minimum 5) basic types of space, which as far as possible in the shortest possible to use data types, do not waste memory
6) char Max Min is a special character, can not show
char c1 = 'b'; // b character, it is stored in memory ascii code
System.out.println (c1);
char c2 = 98; // 98 b is ascii code string
System.out.println (C2);
char C3 = 0; // ascii code 0
System.out.println ( "="+c3+"= ");
. 7) provides the Java eight basic types, it is not object-oriented, not an object
.. Java is an object-oriented language, it will give a lot of extra benefits of these objects have no basic variables of
Java on the launch of each corresponding to a package type (object)
the Java data types in the event there are two types: basic data types, reference type
wrapper class is a reference type
A) byte, byte
B) Short, Shrot
C) int, Integer
D) Long, Long
E) float, float
f) Double, Double
G) char, Character
H) boolean, Boolean
8) basic variables and packaging type variables any different?
underlying variables, small take up memory space. there's nothing extra features.
package type (reference types) , take up storage space, a lot of tools to provide additional conversion method and so on, these are the basic variables do not have. development easier.

Boxing and unboxing

Summary:
1) boxes, that is, the basic types of encapsulated package type
2) unpacking, it is to obtain the value of the type of package base type of
these two processes are java itself automatically. We only know that we exist to this concept.
Because the basic types of fast computing speed, reference type (package type) it has more ways to help us to develop more, the idea, the formation of such a variable objects, java called object-oriented development language, and relevant knowledge on the back of unity

He stressed: packing, unpacking concept difficult to understand, whether he knew on the line. Why can write the actual development, to know the reason.

Type Conversion:
Conversion between different types

Automatic conversion: from small cast into large type. For example: byte int data type conversion, automatic conversion
cast: the type of transition from the large to the small type. For example: int type data into a byte, must force

package test;
public class Trans {
public static void main(String[] args) {
	//小转大,自动
	byte b1 = 100;
	int i1 = b1;//i1整数,b1是字节,自动从字节类型转换整数类型,java自动		 
	System.out.println(b1);
	System.out.println(i1);
	
	//大转小,强制
	int i2 = 100;			
	//byte b2 = i2;	//报错,Type mismatch 类型不匹配: cannot convert from int to byte 不能转换int类型到byte类型

	//提示有风险,但是开发者知道,byte中可以存下100值
	//强制转换
	byte b2 = (byte)i2;		//(类型)强制把i2转成byte类型
	
	System.out.println(i2);
	System.out.println(b2);
}}

Remember: the wording is enough to cast a
byte b = (byte) i2

Operators providing java

1)%, Remainder, even and odd, redis distributed underlying principle of consistency hash algorithms, take the remainder

package test;

public class TestArea {
	public static void main(String[] args) {
		//凭什么说它是一个偶数=2的倍数,整除没有余数就是偶数,如果有余数就是奇数
		

	//取余
	int i = 11;		
	if(i % 2 == 0) {			//判断语句if(条件),分支语句
		//条件真,执行这里的代码
		System.out.println(i+"是偶数");
	}else {
		//条件假,执行这里的代码
		System.out.println(i+"是奇数");
	}
	}
}

2)++自加,--自减,java特色

```java
package test;

public class TestArea {
	public static void main(String[] args) {
		int i = 10;
		int j = i -1;
		System.out.println(j);
		
		int x = 10;
		x = x - 1;
		int y = x;
		System.out.println(y);
		
		int a = 10;
		a--;		//a = a-1;  a--就是这句话缩写
		System.out.println(a);
		
		a++;	//a = a+1; 	a++就是这句话缩写
		System.out.println(a);
		
	}
}
package test;

public class TestArea {
	public static void main(String[] args) {
		int count = 5;
		System.out.println(++count);	//6,当前值:5+1=6, count=6,print 6
		System.out.println(count++);	//6,当前值:6,print 6,6+1=count=7  
		
		System.out.println(--count);		//6,当前值:7,7-1=6,count=6,print 6
		System.out.println(count--);		//6,当前值:6,print 6,count=6-1,当前count=5
		
		System.out.println(count);
		
		//++x 在先执行++操作,在打印
		//x++,先打印,后执行++操作		
	}
}

This procedure is relatively burning brain, not the program you will be able to immediately understand the teacher, after class to go step by step analysis solution, the process every step of the deduction over again. Deductive process verified by printing results.
If the deduction wrong, chaos, deduction from scratch.

Repeated practice after school

3) ternary operator
Java only a ternary operator
z = x + y two mesh calculation, first object x, the second mesh Y
Z = (X> Y) X:? Y Note that the syntax

1) Analyzing the parentheses conditions (determination expression: true / fase, Boolean result)
2) If the determination result is true, execution of the second program content, returns X
. 3) If the determination result is false, execution of the third program content, returns y
simple and quick, if the expression is determined word statement, instead of 5 rows if statements, abbreviated.

Summary:
1) type of packaging, has a corresponding basic types
a) Byte byte (byte), Short short integer (short), Integer Integer (int), Long Long (Long)
B) Single float the Float (float), double double precision floating point (double)
c) character character (char), Boolean Boolean (boolean)
2) when using the basic type, when to use the type of packaging (remember the first principle)
A) as far as possible in the method use basic types
b) when an object passes, pojo
I do not know where to use it? Others see the code. Teacher Case.
3) packing, unpacking
a) packing, Integer i = 10 ;, the integer (write a default number) is automatically put into the package type, the process is called packing. I = new new Integer Integer (10);
B) unpacking, int j = i ;, i is an Integer the type of packaging, a method of using an additional type of packaging intValue (), acquired real objects i the integer value 10, 10 to the j integer type variable.
c) packing, which converts between the base and the type of packaging type unpacking, automatically. Developers do not need to write code, develop them more concise.
4) Conversion between types
a) byte b = 120; int i = b;, 120 is a type byte, i is an integer type, automatic conversion (small can into a large container: Small Large turn)

b) int i =100; byte b= (byte)i;

SUMMARY cast put the first three bytes of the cut, leaving the last byte of the content, so that you can put into a variable byte type. (Big turn a small, cast)
problem: large turn hours, you might lose data. Developers must be clear, if you can lose! ! , Remember! ! !
5) operator. Other simple operator after development will encounter,
A) modulo%
. 5 = 2. 1%
2% 2 = 0
B) from plus +, decrement - (burning brain, multi-calculus, deduction, see the operation result to verify thinking is correct, more difficult) is programmed using a lot of late, with more very familiar with
i ++, the first execution i, i + 1 in i =
I-, the first execution i, the i-1 i =
++ i, the first i = i + 1, the execution result
-i, to i = i-1, the result of execution
c) ternary operator, java a unique, very special fixing structure :( determination condition) results 1:? 2 results, similar to a if the judge sentences
? int r = (x> y ) x: y , if x> y is true, the result really true, return r = x; if x> y is not true, false false results, return r = y.

problem:

"String" directly displayed in the console
+ connector called a string, plus the contents of both sides are connected
q is a variable, it will be translated into current value

a is a variable, it will be translated into a current value, a = 10, 10 results
console: q = 10, a = 10

ASCII, U.S. predetermined computer 26 English letters, a ~ z, there are special symbols, # $% ^, and tabs, tab key. . Invisible characters. In the table, ascii code table.
Computer only 0 and 1, ASCII code table can occur keyboard characters, corresponding to a decimal integer, an integer of 1 and 0 can be translated into a string of numbers, which translates the computer can recognize.
As I now keyboarding letters will be translated in the text. It is the same reason.
Baidu.

I press a lowercase keyboard, the operating system receives a keyboard, a query ascii code table, the integer 97, the query binary
0110001, the computer can recognize the binary, stored in memory. Memory (only 0 and 1)

Published 36 original articles · won praise 13 · views 1082

Guess you like

Origin blog.csdn.net/weixin_44598691/article/details/104702463