day1_java basics

1. Outline

  1. Development history and environment construction
  2. Grammar and Basic Concepts
  3. object oriented
  4. new features
  5. Use of IDEA

2. Development history and environment construction

1 Overview

  • The computer can be turned on without an operating system. There is a bios (basic input output system), which is written in assembly language.
  • Java originally refers to Java Island, an island in Indonesia, which is rich in coffee.
  • Sun's business is too complicated, so Liangliang was acquired, IBM focuses on hardware, and Microsoft focuses on office software.
  • Java is good at server-side development and big data platform development.

2. Language features

  • Fully object-oriented: high coupling, low cohesion
  • Support distributed: provides a class library for network programming
  • Robustness: strong type mechanism, exception handling
  • Safety:
  • Cross-platform: The Java language is translated through the JVM (java virtual machine) in the JDK, so you only need to download the JDK corresponding to different machines.

3. JDK and Notepad

JDK1.7
notepad++ or EditPlus

3. Grammar and basic concepts

1. Keyword

Reserved words: const, goto
Special values: true, false, null

2. Identifier

  • Naming rules for identifiers:
  • Composed of numbers, lowercase letters, underscores _, and dollar signs $
  • cannot begin with a number
  • Cannot use keywords (reserved words, special values)
  • Strictly case sensitive

Note: Grammatically, you can use words other than English to name, but it is not recommended. There will be problems in encoding and it is not easy to read.

  • Naming convention for identifiers (recommended)
  • See the name and know the meaning, such as name, age, student
  • Class name, interface name: the first letter of each word is capitalized, with big camel case
  • Variable name, method name: the first letter of the first word is lowercase, the first letter of each subsequent word is capitalized, and the small hump
  • Package name: Thank you for each word, use '.' between words
  • Constant name: each letter is capitalized, and words are separated by _

– Exer:
insert image description here

Answer: 1, 5, 6
, and 7 options 6 and 7 have specific meanings in the code, but they are all legal identifiers.

3. Data type

Integer type: byte, short, int, long
Floating point type: float, double
Character type: char
Boolean type: boolean
Reference data type: class, interface, enum, @interface, array[ ]

4. Literal

A form of representation of values ​​of basic data types, String types, and null types in the source code.

string literal “hello”
integer literal 123, 034, 0x2A, 0
floating point literal 1.2f, 3.14159
boolean literal false, true
quoted literal null
character literal ‘A’, ‘c’
Integer literals in different bases example corresponding value
decimal 10 10
binary 0B10 2
Octal 010 8
hexadecimal 0x10 16

5. Generate random numbers

  1. Method 1: True Random Numbers
//生成[a, b]之间的随机数, 下次执行时随机数会变化
int num = (int) (a + Math.random() *(b-a+1));

2. Method 2: The pseudo-random number
Random class is located under the java.util package. The random algorithm implemented in the Random class is pseudo-random, that is, random with rules. When performing randomization, the origin number of the random algorithm is called the seed number (seed), and a certain transformation is performed on the basis of the seed number to generate the required random number.

Note : To use this method, you need to import java.util.Random first; R is capitalized.

// 方法二:nextInt(x)
// 返回一个伪随机数,[0, x)之间
Random r = new Random();
int num1 = r.nextInt(10)+1;
System.out.println(num1);

6. Hexadecimal conversion

Decimal to N-base: Divide by N and take the remainder, divide to 0, and get a series of remainders, the remainder of the integer part is arranged in reverse order; the remainder of the fractional part is arranged in positive order.
Conversion from other bases to decimal: Expansion by weight

Guess you like

Origin blog.csdn.net/qq_44273739/article/details/131779115