Java Basics

Posted by xeonman13 on Fri, 24 Dec 2021 16:49:23 +0100

Common dos commands

Serial numbercommandexplainExtended
1dirView all sub files and subdirectories in the specified directorydirectory
2mkdirnew directorymd
3rmdirDelete directorySmart and computer completely removed, irrevocablerd – the directory to be deleted must be empty
4delDelete files. If a folder is followed, all files in the entire folder will be deleted
5clsClear screenclear screen
6exitExit the command prompt
7notepadOpen Notepad
8calcOpen calculator
9mspaintOpen drawing
10cd...Return to the previous directory
11cd/Jump directly to the root directory
12echo data > file nameCreate a file and specify the data to be written
13typeFile name view the contents of the specified file
14*Wildcards can match any file name
15tab keyContent supplement
16Up and down buttonsRetrieve the last command written

java origin

sun launched in 1995
Oak James Gosling Java JAVABean NetBean
1.0 - > 1.1 - > 1.2 (GUI) – 1.3 – 1.4 – 1.5 / 5.0-6 --- 7.0-1.8 (top ten features) - 1.9-10 (18.3) - 18.9-19.3 update every six months
J2SE / Java - Standard Edition - Standard Edition / Basic Edition - provides solutions for some desktop programs and applications, which is the basis of the latter two structures
J2EE/JAVAEE - Enterprise Edition - Enterprise Edition / Business Edition - provides solutions for enterprise development
J2ME / Java - Micro Edition - Micro Edition / Mobile Edition - provides solutions for embedding some small electronic devices
----Android—Kotlin

Characteristics of java

1. Cross platform

JVM(Java Virtual Machine) - Java virtual machine - converts java code into instructions that can be understood by the corresponding operating system Different operating systems have different virtual machines corresponding to them. After the same piece of code is handed over to the virtual machine, the virtual machine is converted to the operating system The premise that Java language can cross platform is JVM.
The JVM is not cross platform

JDK,JRE,JVM

JVM---Java Virtual Machine---yes Java Language can cross platform conditions
JRE---Java Runtime Environment --- Java Runtime environment --- JVM+Core class library
JDK---Java Development Kit --- Java Development Kit --- development tool+JRE

Note: there should be no spaces or Chinese characters in the installation path

take Java The code is translated into instructions understood by the current operating system--compile--After compilation, a.class file,This file is called a bytecode file--This bytecode file is the instruction file for the current operating system

Entry program

class Demo{
	public static void main(String[] args){
		System.out,println("Hello World!");
	}
}
1,Main function public static void main(String[] args){}---It is the entrance of the program
2,class The file name corresponds to the class name---Each class generates a class file
3,If a class uses public To decorate(Public class),Then the class name and Java File names should be consistent
4,One Java Multiple classes can be defined in the file,But there can only be one public class
5,If the package name is added,When running, you need to class Put the file in the directory of the corresponding package,Then again java Package name.Class name
6,javac-d Directory where the compiled package is stored,To compile Java file(Package compilation)
7,java-cp class Package name of the directory where the file is stored.Class name
8.One Java There can be multiple classes in the file,But there can only be one public class


. Represents the current directory environment variable -- Java that specifies the running path of the command to the current operating system_ HOME=D:\Java\jdk1. 7.0_ 75 Path:%JAVA_ HOME%\bin; D:\Java\jdk1. 7.0_ 75\bin;

53 keywords

Words with special meanings
There are 53 keywords in Java, all of which are lowercase - two of which are not used at present: goto, const - reserved words
Keywords used to define data types

classinterfacebyteshortintlong
floatdoublecharbooleanvoidenum

Keywords for user-defined data type values

truefalsenull

Keywords for user-defined process control

ifelseswitchcasedefaultwhile
doforbreakcontinuereturn

Keywords for user-defined access modifier

privateprotectedpublic

Keywords for user-defined classes, functions, and variable modifiers

abstractfinalstaticsynchronized

Keywords between user-defined classes

extendsimplements

User defined keywords for creating and judging instances

newthissuperinstanceof

Keywords for user exception handling

trycatchfinallythrowthrows

Keywords for user packages

packageimport

Other modifier keywords

nativestrictfptransientvolatileassert

identifier

Custom name in program

rule

Composed of letters, numbers_,$form,However, it is not recommended $
Java Support Chinese naming,But not recommended
 The number cannot begin
 Keywords cannot be used

Hump nomenclature

Class name/Interface name:If it consists of multiple words,The first letter of each word is required to be capitalized--PlayBasketball,Demo
 Variable name/Method name:If it consists of multiple words,The first letter of the first word is lowercase,Capitalize the remaining words--playBaskeball,work
 Constant name:All words are capitalized,Between each word_separate---PLAY_BASKETBALL,SAM
 Package name:All words are lowercase,Between each layer of packages.separate--cn,chain

Command in cmd

 compile D disc  Demo.java file
 In the current path where the file is located cmd after
 input javac Space-d Space D:Space Demo.java(A space represents a space position) Compile into.class file
D:\>javac -d D: Demo.java Compile to current directory

Compile files into packages or packages on other disks
D:\>javac -d D:\cn Demo.java Compile into subdirectories of the current directory

D:\>javac -d E:\cn\tedu Demo.java Compile to a subdirectory of another directory


function.class The file is in the current directory
E:\cn\tedu>java -cp E:\\cn\tedu Demo After operation  HelloWorld

D:\>java -cp D:\\ Demo   HelloWorld
 
D:\>java -cp D:\\cn Demo HelloWorld

D:\>java -cp E:\\cn\tedu Demo  HelloWorld


 

Compiling other disks Demo.java file
 Find the disk first, such as E Disk input E: In input cd web(get into java Directory)
E:\web>javac -d E:\web Demo.java Compile into.class file

E:\web>javac -cp E:\\web Demo After operation gege

day02

notes

Explain your program in the code,(Troubleshooting)Three annotation methods for text
//Annotation text -- single line annotation
/*Annotation text*/---multiline comment 
/**Annotation text*/---Documentation Comments ---Can use javadoc Extract the annotation content to form a document--Can only be placed on classes or functions,javadoc Command can only be used to extract public classes

Computer constants

A quantity that cannot be changed by itself
 integer constant :All certificates 3,4,100
 Decimal constant:All decimals 1.02,5.36,8.7209
 character constants :Use a symbol''Marks constitute a character constant'a' '+''1'''
string constant :Use multiple characters""The flag constitutes a string constant"abc" "12w" "a" ""
Boolean Literals :There are only two values-- true/false--Used to represent logical values
 Null constant:null

Consider: 2 – integer, 2.0 – decimal '2' – character, "2" – string, '2.0' – illegal, "2.0" – string
Byte b=00001100;– Wrong - this is an octal number, which is beyond the range of byte
Byte—127 --01111111

Base system

restart at
Binary: 0-1, full 2 into 1, in jdk1 Before 7, it was not allowed to directly represent binary numbers in Java code, from jdk1 7. Binary numbers are allowed to be used in the code at the beginning. It is required to start with ob/OB, 1 + 1 = 10, 11 + 1 = 100
ob100100 OB10111 1=1 2=10 3=11 4=100 5=101 6=110 7=111 8=1000 9=1001 10=1010
Octal: 0-7, full 8 into 1, starting with 0, marking octal digit 7 + 1 = 10, 16 + 1 = 17, 17 + 1 = 20
Decimal: 0-9, full 10 into 1
Hexadecimal: 0-9,A-F/a-f, full 16 into 1, starting with Ox/OX, hexadecimal digit 9 + 1 = a, a + 1 = b
f+1=10 OX23 OXa 19+
variable
data type
Escape character
Conversion of data types
Cast / explicit
Original inverse complement three codes of data
operator
Arithmetic operator
Assignment Operators

day03
Relational operator
Logical operator
Bitwise Operators
Exchange the values of two variables
Ternary operator
Input data from the console
Process control

Topics: Java