Java learning notes

Time and tide 2021-01-14 16:51:35
java learning notes


Java Basic grammar

Basic stage

  1. notes 、 identifier 、 keyword

    notes

    • Usually we write code , When the amount of code is small , We can also read what we write , But when the project structure gets complicated , We need to use annotations .

    • Annotations are not executed , It's for our code writers

    • It's a very good habit to write notes

    • We must pay attention to the standard when we write code

    • Java There are three types of comments in :

      a. Single-line comments ; Another line in the code Input "//" Annotate

      b. Multiline comment ;/* */

      c. Documentation Comments ;/** */

      identifier

      • keyword


      • Java All components need names . Class name 、 Variable names and method names are called identifiers .

      • Identifier considerations

        a. All identifiers should be in letters (A-Z perhaps a-z), Dollar symbol ($)、 Or underline (_) Start

        b. The first character can be followed by a letter (A-Z perhaps a-z), Dollar symbol ($)、 Or underline (_) Or any combination of characters

        c. Cannot use keyword as variable or method name .

        d. The identifier is case-sensitive

        e. Examples of legal identifiers :age、$salary、_value、__1_value

        f. Illegal identifier example :123abc、-sakary、#abc

        g.** It can be named in Chinese . But it is generally not recommended to use it in this way , Pinyin is not recommended . very Low

data type

  • Strong type language

    • It is required that the use of variables should strictly comply with the regulations , All variables must be defined before they can be used
  • Weak type language

  • Java There are two major types of data

    • Basic types (Primitive Type)
    • Reference type (Reference Type)


What are bytes

  • position (bit): It's the computer internal data The smallest unit of storage ,11001100 It's an eight bit binary number .

  • byte (byte): It's in the computer Data processing The basic unit of , It's customary to use capital letters B To express ,

  • 1B(byte, byte )=8bit( position ).

  • character : It refers to the letters used in computers 、 Numbers 、 Words and symbols

public class Demo03 {
public static void main(String[] args) {
// Integer expansion : Base number Binary system 0B Decimal system octal 0 Hexadecimal 0x
int i = 10;
int i1 = 010;
int i2 = 0x11;
System.out.println(i);
System.out.println(i1);
System.out.println(i2);
System.out.println("==================================================================");
// Floating point expansion What does banking business mean ? money
// Use Bigdecimal To express Mathematical tools
//float Co., LTD. discrete Rounding error about Close to but not equal to
//double
// It's best to avoid using floating-point numbers for comparison
// It's best to avoid using floating-point numbers for comparison
// It's best to avoid using floating-point numbers for comparison
float f = 0.1f; //0.1
double d= 1.0/10; //0.1
System.out.println(f==d); //false
float d1 = 232323232323f;
float d2 = d1 + 1;
System.out.println(d1==d2); //ture
System.out.println("==================================================================");
// The expansion of character class
char c1 = 'a';
char c2 = ' in ';
System.out.println(c1);
System.out.println((int)c1); // Forced line wrap
System.out.println(c2);
System.out.println((int)c2); // Forced line wrap
// All characters are numbers in nature
// code Unicode The system can have a watch (97 = a 65 = A) 2 byte 0 - 65536 Excel 2 Of 16 Power =65536
// U0000 UFFFF
char c3 = '\u0061';
System.out.println(c3); //a
System.out.println("==================================================================");
// Escape character
// \t ( tabs Tab Space )
// \n ( Line break )
// .....( There are still a lot of it )
System.out.println("Hello\tWorld");
System.out.println("Hello\nWorld");
System.out.println("==================================================================");
String sa = new String("Hello World");
String sb = new String("Hello World");
System.out.println(sa==sb);
String sc = "Hello World";
String sd = "Hello World";
System.out.println(sc==sd);
// object From memory analysis
System.out.println("==================================================================");
// Boolean extension
boolean flag = true;
if (flag==true){} // Novice
if (flag){} // an old hand
//java Code principles Less is More! The code should be concise and easy to read !

Type conversion

  • because Java It's a strongly typed language , So when we have to do some operations , Type conversion is needed .

    low ---------------------------------------------------------> high

    byte,short,char--> int -->long -->float -->double

  • Operation , Data of different types are converted to the same type first , And then you do the math .

  • Cast

  • Automatic type conversion

public class Dome04 {
public static void main(String[] args) {
// Coercive transformation ( type ) Variable name high --> low
int i = 128 ;
byte b =(byte)i; // out of memory
System.out.println(i);
System.out.println(b);
// Automatic conversion low --> high
int i1 = 128 ;
double c = i1 ;
System.out.println(i1);
System.out.println(c);
/* Be careful :
1. Cannot convert Boolean values
2. You cannot convert an object type to an unrelated type
3. When converting high capacity to low capacity , Coercive transformation
4. There may be memory overflow during conversion , Or accuracy issues !
*/
System.out.println("=============================================");
System.out.println((int) 23.7); // Precision problem
System.out.println((int)-45.89f); // Precision problem
System.out.println("=============================================");
char c1 ='a';
int d = c1+1;
System.out.println(d);
System.out.println((char)d);
}
}
public class Dome05 {
public static void main(String[] args) {
// When operating large numbers , Pay attention to overflow problem
//JDK7 New characteristics , Numbers can be separated by underscores
int money = 10_0000_0000;
int years = 20;
int total =money*years; //-1474836480, The calculation overflowed
long total2 =money*years; // The default is int, There was a problem before the conversion
long total3 =money*((long)years); // First, convert a number to long
System.out.println(total);
System.out.println(total2);
System.out.println(total3); // Operate correctly
// Capitalization L, A lowercase letter l Attention and numbers 1 The distinction between
}
}

~~ Continuous updating ·····

版权声明
本文为[Time and tide]所创,转载请带上原文链接,感谢
https://javamana.com/2021/01/20210114164753302B.html

  1. Rocketmq CPP client visual studio 2019 compilation
  2. Usage of data custom attribute in jquery
  3. Common decompression in Linux
  4. Upload large files in Java
  5. Sentry (v20.12.1) k8s cloud native architecture exploration, sentry for JavaScript manual capture event basic usage
  6. Sentry (v20.12.1) k8s cloud native architecture exploration, sentry for JavaScript manual capture event basic usage
  7. Docker + MySQL Cluster + read / write separation + MYCAT Management + vertical sub database + load balancing
  8. Docker + MySQL Cluster + read / write separation + MYCAT Management + vertical sub database + load balancing
  9. Java use interceptor infinite forwarding / redirection infinite loop / redirection times too many error (stack overflow error) solution
  10. Java use interceptor infinite forwarding / redirection infinite loop / redirection times too many error (stack overflow error) solution
  11. 010_ MySQL
  12. 010_ MySQL
  13. Fast integration of imsdk and Huawei offline push
  14. 消息队列之RabbitMQ
  15. Rabbitmq of message queue
  16. 初学java进制转换方面补充学习
  17. Learn java base conversion supplementary learning
  18. 了解一下RPC,为何诞生RPC,和HTTP有什么不同?
  19. 了解一下RPC,为何诞生RPC,和HTTP有什么不同?
  20. 初学java进制转换方面补充学习
  21. Learn about RPC, why RPC was born, and what's the difference between RPC and HTTP?
  22. Learn about RPC, why RPC was born, and what's the difference between RPC and HTTP?
  23. Learn java base conversion supplementary learning
  24. JDBC测试连接数据库
  25. JDBC test connection database
  26. 大厂面试官竟然这么爱问Kafka,一连八个Kafka问题把我问蒙了?
  27. The interviewers of big factories love to ask Kafka so much. I'm blinded by eight Kafka questions in a row?
  28. 安卓开发和java开发有什么区别!2021年BATJ30套大厂Android经典高频面试题,面试必问
  29. Spring Security OAuth2.0認證授權四:分散式系統認證授權
  30. What's the difference between Android development and java development! 2021 batj30 Android classic high frequency interview questions
  31. Spring security oauth2.0 authentication and authorization 4: distributed system authentication and authorization
  32. Java微服务 vs Go微服务,究竟谁更强!?
  33. 大厂面试官竟然这么爱问Kafka,一连八个Kafka问题把我问蒙了?
  34. Who is stronger, Java microservice vs go microservice!?
  35. Java微服务 vs Go微服务,究竟谁更强!?
  36. The interviewers of big factories love to ask Kafka so much. I'm blinded by eight Kafka questions in a row?
  37. Who is stronger, Java microservice vs go microservice!?
  38. springboot异常处理之404
  39. Spring boot exception handling 404
  40. Spring Boot Security 国际化 多语言 i18n 趟过巨坑
  41. springboot异常处理之404
  42. Spring boot security international multilingual I18N
  43. Spring boot exception handling 404
  44. Netty系列化之Google Protobuf编解码
  45. Netty之编解码
  46. Java编解码
  47. Netty解码器
  48. Netty与TCP粘包拆包
  49. Netty开发入门
  50. Java集合遍历时遇到的坑
  51. Spring IOC 源码解析(下)
  52. Spring IoC源码解析(上)
  53. Google protobuf codec of netty serialization
  54. Encoding and decoding of netty
  55. Java codec
  56. Netty decoder
  57. Netty and TCP packet sticking and unpacking
  58. Introduction to netty development
  59. Problems encountered in Java collection traversal
  60. Spring IOC source code analysis (2)