Joke Collection Website - Public benefit messages - Basic knowledge of java

Basic knowledge of java

1.PATH environment variable.

This function is to specify the command search path. When executing a command under the command line, such as javac compiling a java program, it will look in the path specified by the path variable to see if it can find the corresponding command program. We need to add the bin directory under the jdk installation directory to the existing PATH variable. Bin directory contains frequently used executable files, such as javac/java/javadoc, etc. After setting the PATH variable, we can execute tools such as javac/java in any directory.

CLASSPATH environment variable.

This function is used to specify the class search path. If you want to use the already written class, the premise is of course that you can find it. The JVM looks for classes through the class path. We need to set dt.jar and tools.jar in the lib subdirectory under the jdk installation directory as class paths. Of course, the current directory must also be added to this variable.

2, public examination {

/**

* @param args

*/

Public static void main(String[] args) {

// TODO automatically generated method stub

int sum = 0; //Set a variable to sum the values.

for(int I = 1; I<= 100; i++){

sum = sum+I;

}

System. Out. println(" 1+2+3+ sum ...+100: "+sum");

}

}

3. Import java.util.arrays;

Common class test {

/**

* @param args

*/

Public static void main(String[] args) {

// TODO automatically generated method stub

int str[]={ 1,3,9,5,4,8,2 };

arrays . sort(str);

System.out.println ("Maximum number in array:"+str [str. length-1]);

}

}

4, public examination {

/**

* @param args

*/

Public static void main(String[] args) {

// TODO automatically generated method stub

string str = " ABC . Java . txt "; //Define the variable setting file name.

system . out . println(str . substring(str . lastindexof(" . ")+ 1));

}

}

5, public students {

Private string name; //Name

Private age; //age

Private dichotomy; //result

Public student (string name, integer, double score) {

this.name = name

This.age = age;

this.score = score

}

Public string getName() {

Returns the name;

}

Public void setName {

this.name = name

}

public int getAge() {

Regression age;

}

Public invalid storage (integer) {

This.age = age;

}

public double getScore() {

Returns a score;

}

Public Invalid Set Score (Double Score) {

this.score = score

}

}

6. I will not post the code. Create a loan object by yourself. Then put the scores of five objects in an array, and directly call the array name method to sort the output.

7. Method: You can read and write with file stream. Landlord can choose byte stream or character stream according to file type. If the landlord still needs it, you can write the code.

8.TCP (Transmission Control Protocol) is a connection-based protocol, that is, a reliable connection must be established with the other party before sending and receiving data formally. A TCP connection can only be established after three sessions, and the process is very complicated. We only make a simple and vivid introduction here, as long as you can understand the process. Let's take a look at the simple process of these three conversations: Host A sends a connection request packet to Host B: "I want to send you data, can I?" This is the first conversation; Host B sends a data packet to host A, and host A agrees to connect and asks for synchronization (synchronization means that the two hosts are sending and receiving and coordinating their work): "OK, when will you send it?" This is the second conversation; Host A sends another data packet to confirm the request of synchronizing host B: "I'll send it now, you can continue!" " "This is the third conversation. The purpose of the three sessions is to synchronize the sending and receiving of data packets. After three conversations, Host A will formally send data to Host B. ..

TCP protocol can provide reliable communication connection for applications, so that the byte stream sent by one computer can be sent to other computers on the network without error. A highly reliable data communication system usually uses TCP protocol to transmit data.

Connection-oriented UDP protocol

"Non-connection-oriented" means that you don't need to establish a connection with the other party before formal communication, and you can send it directly regardless of the other party's status. This is very similar to the popular mobile phone short message: when sending a short message, you only need to enter the other party's mobile phone number.

Udp (User Datagram Protocol) is a protocol corresponding to TCP. It is a non-connection-oriented protocol, it does not establish a connection with the other party, but sends data packets directly!

UDP is suitable for the application environment where only a small amount of data is transmitted at a time and the reliability requirement is not high. For example, we often use the "ping" command to test whether the TCP/IP communication between two hosts is normal. In fact, the principle of the "ping" command is to send a UDP packet to the other host, and then the other host confirms the receipt of the packet. If the message of whether the packet arrives is fed back in time, then the network is connected. For example, by default, the ping operation sends four packets (as shown in Figure 2). As you can see, the number of packets sent is 4, and the number of packets received is also 4 (because the other host will send back a packet to confirm receipt). This fully shows that UDP protocol is a connectionless protocol, and there is no process of establishing a connection. Because UDP protocol has no connection process, the communication effect is high; But because of this, its reliability is not as high as TCP protocol. QQ uses UDP to send messages, so sometimes you can't receive messages.

TCP and UDP have their own advantages and disadvantages and are suitable for different communication environments.

9 、& ltform id = " register " name = " register " method = " post " action = " " & gt;

& lttable width="380" border="0 " >

& lttr & gt

& lttd width="93" height="37 "> User name:

& lttd width="27 1 " >

& ltinput type = " text " name = " username " id = " username "/& gt;

& lt/TD & gt;

& lt/tr & gt;

& lttr & gt

& lttd height="30 "> password:

& lttd & gt& ltinput type = " password " name = " pwd " id = " pwd "/& gt; & lt/TD & gt;

& lt/tr & gt;

& lttr & gt

& lttd height="26 "> Confirm password:

& lttd & gt& ltinput type = " password " name = " confirm pwd " id = " confirm pwd "/& gt; & lt/TD & gt;

& lt/tr & gt;

& lttr & gt

& lttd height="33 "> Gender:

& lttd & gt

& ltinput type = " radio " name = " sex " value = " female "/& gt;

man

& ltinput type = " radio " name = " sex " value = " male "/& gt;

Female Shanghai

& lt/select & gt;

& lt/TD & gt;

& lt/tr & gt;

& lttr & gt

& lttd & gt hobbies:

& lttd & gt& lt label & gt

& ltinput type = " checkbox " name = " hobby " id = " mountain " value = " mountain "/& gt;

climb mountains

& ltinput type = " checkbox " name = " hobby " id = " basketball " value = " basketball "/& gt;

basketball

& ltinput type = " checkbox " name = " hobby " id = " swimming " value = " swimming "/& gt;

swim

& lt/tr & gt;

& lttr & gt

Introduction to & lttd & gt:

& lttd & gt

& lttextarea name = " introduce " cols = " 30 " id = " introduce " rows = " 3 " >& lt/textarea & gt;

& lt/TD & gt;

& lt/tr & gt;

& lttr & gt

& lttd & gt? & lt/TD & gt;

& lttd & gt& lt label & gt

& ltinput type = " button " name = " submit " value = " submit " onclick = " check()"/& gt;

& lt/label & gt; & lt/TD & gt;

& lt/tr & gt;

& lt/table & gt;

& lt/form & gt;

10, I'll write you a js, and you call this method in the code.

& lt scripting language = "JavaScript" type = "text/JavaScript" >

Function check () {

//Judge the user name

var username = document . getelementbyid(" username ")。 Value;

//Define a regular expression. User name must be alphanumeric or underlined and cannot start with a number.

Valregex1=/[a-za-z _] [0-9a-za-z _] $/

var s = document . getelementbyid(" username ")。 Value;

alert(regex 1 . test);

Return;

if(regex 1 . test(username)){

Alert ("User name must be alphanumeric or underlined and cannot start with a number");

Return;

}

//Judge the password

//Define a regular expression, and the password must be 6- 16 alphanumeric underscore.

Valregex 2 =/[0-9a-za-z _] {6,16} $/

var pwd = document . getelementbyid(" pwd ")。 Value;

if(regex2.test(pwd)==false){

Alert ("Password must be 6- 16 alphanumeric underscore");

Return;

}

//Judge the confirmation password

var confirm pwd = document . getelementbyid(" confirm pwd ");

if(pwd.value! =confirmpwd.value){

Alert ("The two password entries are inconsistent, please re-enter!" );

Return;

}

//Judge gender, city, hobby and introduction.

var sex = document . getelementsbyname(" sex ");

var city = document . getelementbyid(" city ");

var hobby = document . getelementsbyname(" hobby ");

var introduce = document . getelementbyid(" introduce ");

var t = 0;

for(var I = 0; I< gender. Length; i++){

If (sex [me]. checked==true){

t++;

}

}

if(t==0){

Alert ("Please select a gender!" );

Return;

}

t = 0;

for(var I = 0; I< like. Length; i++){

If (hobby [me]. checked==true){

t++;

}

}

if(t==0){

Alert ("Please choose a hobby!" );

Return;

}

if(city.value==""){

Alert ("City cannot be empty, please select a city");

Return;

}

if(introduce . value = = " " | | introduce . value . length = = 0){

Alert ("Personal data cannot be empty");

Return;

}

}

& lt/script & gt;

Please point out any mistakes in the above, thank you.