Java newbie entry - organized SCJP listening lesson

xiaoxiao2021-03-06  126

2004-7-30 12:07:00

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: the security setting of the virtual machine, the security of the application server.

4, networked capacity.

two,

Middleware technology: EJB

Very well solved the problem with the database connection.

three,

Design Patterns

MVC

M v c

Model View Control

JavaBean JSP servlet

Taglib Applet Control Page Transfer

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

"." Means that the path to the virtual machine find class begins with the current path.

2.path

C: /j2sdk1.4/bin

EditPlus increases the tools to compile and run Java.

Compile Java tool settings

Command C: /J2SDK1.4/bin/javac.exe

Parameter $ (filename)

Initial Directory $ (FileDir)

Tool settings running Java

Command C: /J2SDK1.4/bin/javac.exe

Parameters $ (filename) without Extension

Initial Directory $ (FileDir)

Chapter One

First, JVM

1. The Java store file name must be a public class name (including the class name of the main method)

2, the Java program ends with .java suffix name.

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

Note You only need to compile the primary call, the output path of the class file, generate a packet path 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)

Packing is also packaged in the previous directory of the package.

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

v Chapter 2 identifier keyword type

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

2, Note in Java:

INT X; // a letter "//" part of the "//" is comment content

/ *

The Variable X is an inTeger:

* / int x; Compiler does not process all content between "/ *" and "* /" for comment, / **

x - an integer representing thex coordinate

* /

INT X; "/ Doing Processing, this Note is the annotation content used when the document works **" and "* /" is the annotation of the javadoc generated documentation, the compiler is not

3, keyword

There are 52 in total, where goto, const has no practical effect.

4, TYPE type

Basic types 8: Boolean, Char, Byte, Short, Long, Int, Float, Double

When declaring a variable in the C / C language, it is, in the Java language, all basic data types have preset, that is, when I

Even if we don't assign a preset value of the type of type:, its value is also certain, not as unpredictable as in C / C . specific

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 starts at 0x or 0x. Can't start with 0, this is because the number of octal is starting with 0, and the number of sixteen

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

Character constant

Character-like 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 the characters in the Java language. It is a 16-bit Unicode character, 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:

Semi-sequence standard form function description

/ carry on

/ N NL Enter Renewal

/ t HT horizontal tab

/ b BS back

/ R CR Enter No Railway

/ f FF change page

/' ' apostrophe

// / backslash

/" " Double quotes

/ DDD 0DDD octal mode

/ xddd 0xDDD hexadecimal mode

/ udddd 0xddddd agode double-byte character

String constant

String constants is a series of characters that are not caused by the dual quotation marks, and different from the C / C language, the words in the Java language

Through the character array, it is implemented by a string class (ie, the String class).

Data type conversion problem:

(1) Small range - "Large-range automatic conversion

(2) Various range - "Small range forced conversion

(3) In the same case of the number, low-precision promotes high precision (the principle of four rounds)

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, and it cannot be determined whether it exceeds C. c = (short) (a b);

System.out.println (c);

}

}

Reference type

Array

Object

The process of creating an object:

(1) Define a class;

(2) Declare an object;

(3) Create an object;

The role of the new keyword:

(1) Allocate memory space for this object;

(2) Returns the reference to the memory space, return to the first address; (reference is the alias of the pointer)

(3) Call the constructor, the constructor automatically assigns a first value.

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 calls TSTRING ()

Public String Tostring ()

5, transfer (test point)

When the method is called, the principle of delivery principles:

The basic type of data is transmitted, the transfer is the copy of the argument.

The reference type of the reference, passed is a 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 is automatically assigned;

(2) Method variable. Also known as auto variables, local variables;

This method is used.

The initial value is assigned when the method variable is executed, and the first value must be assigned before use.

2, short circuit operator

&& || Have a short circuit

A && B When A is False, do not perform B, short circuits occur;

A || B When A is True, do not perform B, short circuits.

3, shift operator

<< Left movement, all the space to make 0, left shift) value = 2 ^ n * original value (N mobile bits, no overflow, lost "0"

>> Right shift, vacancy to supplement 0 or 1, if the original number is up to 1, then supplement 1; if the original number is up to 0, then supplement 0;

>>> right shift, all the space is 0.

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, declare an array, cannot indicate the size of the array.

Int [] i;

INT i [];

2. Create an array array member automation (equivalent to members variables)

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}

2D number group

Disclaimer, create

INT i [] [] = new int [2] [3]

Int [] i [] = new int [2] [] (must indicate the size of the first dimension)

int [] [] i = new int [2] [3]

The number of dimensions in array cannot be assigned by swap applications.

Int [] i, j [];

i = new int [3];

J = new int [2] [3];

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

New Post(0)