My first day of learning Java at LeByte

1. First, I made a study plan for myself, including five parts.
2. Start the learning of the first part of Java basic theory today. (In order to keep your memory deep and keep your knowledge in mind, it is recommended to record your daily learning)

Knowledge point
1. Identifier: The identifier of the Java language is composed of letters, underscores, dollar signs (can be first letters), and numbers. The first character cannot be a number. The letter means the characters of various countries including Chinese characters. Keywords cannot be identifiers, Boolean constants cannot be identifiers (true, false), null cannot be constants , identifiers are case sensitive

2. Keywords: Symbols with special meanings. To put it bluntly, they are fixed phrases that appear in Java code. Common: When choosing judgment—if, else, switch, case, while, default, when modifying variables—private, protected, public, static, when modifying constants (the expression may be inaccurate here)—int, short, byte, long, Double, float, char, -this, super, implements (interface), extends (inheritance), throwing exceptions -throw, throws, finally, try, catch in the parent class and subclass ... are common when listed here. The meaning of the keyword is that the developer who made the Java language is regarded as an official special purpose, and ordinary developers cannot define it as their own method.

3. A question will arise in the written test: What are the basic data types of the Java language? byte short int long double float char boolean 8 basic data types.

4. The size of basic data types: Default value (initial value)

byte: 1 byte, -128~127 0
short: 2 bytes 0
int: 4 bytes 0
long: 8 bytes 0L
float: 4 bytes 0.0f
double: 8 bytes 0.0d
char : 2 bytes 0
boolean: Unable to determine the size false
5. A question will arise in the written test: Why can't the long type be converted to the int type? First, you need to know the byte size of each basic type. Long is 8 bytes, and int is 4 bytes, which will overflow during conversion. This situation also occurs in actual operation.

6. Packaging class: The basic types in Java are not object-oriented, for example: int a=5; the object refers to User user=new User(); back to the topic, the packaging class can make the value default to null, the packaging class Except for Integer-int and Character-char, all the first letters are capitalized: byte-Byte, double-Double, boolean-Boolean. (Auto-boxing and auto-unboxing-conversion between basic data types and packaging types)
When to use packaging types and when to use basic types, it depends on the basic business: this field allows null values, if allowed For null values, wrapper classes must be used, otherwise the value type is fine. For example, if generics and reflection call functions are used, wrapper classes are needed!

7. Constants and variables:
constants : the constants in the Java language include integer constants (common binary and decimal), floating-point constants (123., 98f, 123e+3), Boolean constants, character constants, String constant ("hello world"), null constant.
Variables: Java variables determine their type at compile time. Usually divided into two types:
1. Common data type variables
2. Reference data type variables. Class, interface, array

8. Variables in detail:

Variable types: (1) Class variables: including class variables and interface variables. When defining class variables, use the modifier static, and interface variables may not use the modifier static. When a class or interface is created, the variables are initialized according to default values; when the class or interface is unloaded, the variables disappear. (In my own understanding, class variables can also be called static variables. They are variables in the class independent of the method body. They need to be modified with static. Static means global and static. Static code blocks will be executed when the jvm loads the class. Each code block is executed only once, and executed in order. The static variable does not even need to be accessed through the object. It can be accessed directly by "class name. variable name".)
package JavaTest;<br/>public class LearnStatic {<br/>static int i=1;<br/>static {<br/>System.out.println("静态模块被调用");<br/>i++;<br/>}<br/>public LearnStatic(){<br/>System.out.println("b的值为");<br/>i++;<br/>}<br/>public static void main(String[] args) {<br/>LearnStatic l1=new LearnStatic();//采用了对象名来访问<br/>System.out.println(l1.i);<br/>LearnStatic l2=new LearnStatic();<br/>System.out.println(l2.i);<br/>}<br/>}<br/>输出结果:<br/>静态模块被调用<br/>b的值为<br/>3<br/>b的值为<br/>4

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

Instance variables: class variables that do not use the modifier static.
Local variables: Variables declared in constructors, methods, or program blocks are only valid within the scope of their internal declarations.
---------------------------------------Java variable type-------- ----------------------------------------
! Through this link, there is a misunderstanding. First of all, it is independent of the method. The method is the construction method, but it will exist in the class.
Final variable: The variable that uses the modifier final can only be assigned once, and its value will not change during the execution of the program. (Forever unchanged, does not change with the environment) public static final double PI=3.1415926
9. Operators and expressions

Arithmetic operators: The rule is to multiply and divide first and then add and subtract. Parentheses and monocular operations take precedence. You can change the calculation order of expressions through parentheses. Common operators: ++, -, (note the order of increment and decrement, for example: a++, first increment and then increment, ++a first increment and then decrement), do more questions.
Relational operator: compares two numeric data, the result of the operation is Boolean. Common relational operators: >,<,>=,<=,==,!=
(Note that =: is an assignment, and == represents an equal sign)
Logical operators: constituted by logical operators The calculation result of logical expression is also Boolean. Divided into standard logical operators (&, |,!) and conditional logical operators (&&, ||), there will be interview questions! !
Important: Standard logical operators need to evaluate all sub-expressions before they can get results. When using "&", it clearly indicates that multiple conditions are judged. If there are conditions in multiple expressions that return false, the remaining conditions must also be judged; conditional logic operator: && (short-circuit AND): When used "&&", as long as there are conditions to return false, the remaining conditions are no longer judged, and false.
Conditional operator: ternary operator: <expression1>?<expression2>:<expression3>*x>y? x:y If x is greater than y, the result is x, otherwise it is y.

Guess you like

Origin blog.51cto.com/14966610/2542498