SCJP note

xiaoxiao2021-03-06  72

Preface: Java's charm

One,

1. Powerful granting capabilities: the existence of the virtual machine, there are different virtual machines in different platforms. 2, object-oriented; 3, good security: virtual machine security settings, security of application servers. 4, networked capacity.

two,

Middleware technology: EJB is well solved with the problem of database connection.

three,

Design mode MVC

M v c Model View ControlJavabean JSP Servlet Taglib Applet Control Page Flow EJB Business Logic

IE --------------> Web Server --------------> Appliation Server --------> DB JSP Applet EJB JavaBean WebSerice Servlet

EJB cannot be deployed on the Internet, and the RI protocol cannot pass the firewall. The stateless session bean can be released as WebSerice.

Fourth, configure the environment of Java:

After the JDK1.4 is installed, ClassPath is added to the environment variable to modify the PATH.

1, ClassPath

C: /j2sdk1.4/lib/tools.jar "." indicates that the path to the virtual machine is from the current path. 2.path

C: /j2sdk1.4/bin

EditPlus increases the tools to compile and run Java. Compiling Java Tool Settings Commands C: /J2SDK1.4/bin/javac.exe Parameters $ (filename) Initial Directory $ (FileDir) Tool Settings Command C: /J2SDK1.4/bin/javac.exe Parameters $ FILENAME) WILENAME? Initial Directory $ (Filedir)

Chapter One

First, JVM

1. The Java store file name must be a buffer name that is the end of the Java program with a public class (including the class name of the main method) 2, the java program ends with .java.

Java is case sensitive, general code customs. The first character of the class name, method, and variables of the first character lowercase, constant is all uppercase.

Second, garbage collection mechanism GARBAGE COLLECTION

The variables in the memory area are not referenced by any program, automatically discard.

Supplementary instance? ?

Third, source file layout

Package abc.def ("." means the subdirectory path, with the relative path of the current directory as the starting point) PUBLIC CLASS A {} Class B {} Class C {}

Package: One form of organizational directory

|| ---- # ABC | | # Def | | ---- a.class | ---- B.Class | ---- C.class

Package / Make mechanism Javac -d. File name description only needs to be compiled, the output path of the class file is generated in the current directory.

The class file is placed in the package path and runs under the previous directory of the package when running the program.

Packing method: JAR CVF abc.jar ABC (Description: abc.jar is the target file, ABC source file) package is also packaged in the previous directory of the package.

After packaging it, you can test .jar in the ClassPath environment variable.

(Supplementary instance)

Chapter II identifier keyword type

1, the number cannot be the first character of the identifier.

2, Note in Java: int X; // A "//" part of "//" is comment content / * the variable x is an integer: * / int x; / * "and" * / " All the contents of the comment are comment, the compiler does not process this comment content / ** x - an integer representing the x coordinate * / int x; "/ **" and "* /" all content Comment content, the compiler does not work on this comment, this comment is 326 when the document tool Javadoc generates documents, and there are 52 keywords, where goto, consts have no practical effects.

4, TYPE type Basic types 8: Boolean, Char, Byte, Short, long, int, float, Double and C / C languages ​​are different, in the Java language, all basic data types have preset values. That is to say, when we declare a variable, even if we don't assign it, its value is also certain, not as unpredictable as in C / C . The specific type of preset is shown in the table below:

Basic data type preset value Boolean false char '/ u000' Byte (byte) 0 Short (Short) 0 INT 0 long 0l float 0.0l double 0.0d

In the Java language, all constants have three forms, which are: decimal, octal, and hexadecimal. It should be noted that the decimal number cannot be started at 0, because the number of octal is starting with 0, while the number of hexadecimal starts at 0x or 0x.

The default of the floating point is the Double integer for INT.

Character constant character type constants is a single character with a character caused by two single quotes. However, the two single quotes can't be single quotes and backslashes, ie '' 'and' / 'are incorrect ways.

Everyone must remember that the characters in the Java language are 16-bit Unicode characters, which is different from language such as C / C .

Like the C / C language, Java languages ​​also have a translivation sequence. The function of the translitement sequence in Java is shown in the following table:

Semicone sequence standard form function description / Continue / N NL Enter Ranking / T HT Horizontal Table / B BS Back Definition / R CR Enter No Rank / F FF Change Page / '' Single Route // / Froentyl Bar / "" Double Quotes / DDD 0DDD Octic Mode / XDDD 0xDDD Hex Sedew Mode / UDDDD 0xDDDDDDDDDDDDDDDDDDDE Double Number Character

String constant string constant is a series of characters caused by double quotes. Different from the C / C language, the string in the Java language is not implemented by the character array, but through the string class (ie String Class) is implemented.

Data Type Conversion Problem: (1) Small Range - "Large Range Automatic Conversion (2) Various Range -" Small Range Forced Conversion (3) In the same case, low accuracy is promoted to high precision (the principle of four) FLOAT F = 3.14f INT I = (int) 3.14 (4) Short, byte is automatically promoted to int, and then operates automatically when participating in the operation.

Public class javatest1 {public static void main (string [] args) {SHORT A, B, C; a = 1; b = 2; // c = A b; // A B result is int, no determination More than C range. C = (short) (a b); system.out.println (c);}}

Array object

Create an object: (1) Define a class; (2) declare an object; (3) Create an object;

The role of the new key: (1) Assign memory space for this object; (2) Returns a reference to the memory space, returns the first address; (reference is the alias of the pointer) (3) call constructor, the constructor is automatically Function assignment.

The class instance is equivalent to the object, which is a piecewise saved in the memory storage area.

Output Type System.out.Println (); From Moving Tostring () Public String Tostring () PUBLIC STRING TOSTRING

5. When the value transfer (test point) is called, the principle of passing principles: the basic type data of the basic type data, passes the argument of the copy reference type of the argument, passed the copy of the reference first address

Chapter III Variable Operator Process Control 1, Variables and Scope

(1) Member variables, also known as attributes, domains; can be used throughout the class, and the member variable automatically assigns initial value;

(2) Method variable. Also known as auto variables, local variables; in this method. The initial value is assigned when the method variable is executed, and the first value must be assigned before use.

2, short circuit operators &&, || have short-circuit role

A && B When A is False, do not perform B, short circuits; A || B When A is True, do not execute B, short circuits occur.

3, shift operator << left shims, vacancy, left shift value = 2 ^ n * original value (N mobile bits, no overflow, lost "0") >> right shift, vacancy 0 or 1, if the original number is 1, then supplement 1; if the original number is the highest is 0, then supplement 0; >>> right shift, the vacancy is all settled.

4, process control switch () {case constant 1: statement 1; Break; case constant 2: statement 2; Break; default: statement;

If not, the program will continue to execute and perform the next case.

The label only allows you to appear in front of the loop code.

Chapter 5 Array 1, declared an array, cannot indicate the size of the array. INT [] i; INT i []; 2, create array array members automation (equivalent to class member variable) int [] i = new int [3] 3, assignment i [0] = 1; int [] i = {1, 2, 3} int [] i, j; i = new int [3]; j = i; int [] i = new int [] {1, 2, 3}

2-dimensional array declaration, create int i [] [] = new int = [2] [3] int [] i [] = new int [2] [] (must point out the size of the first dimension) int [] [] I = New int [2] [3] The number of dimensions of arrays is different, and it cannot be assigned by switching applications. INT [] i, j []; i = new int [3]; j = new int [2] [3];

转载请注明原文地址:https://www.9cbs.com/read-119259.html

New Post(0)