Good to learn

xiaoxiao2021-03-06  75

Experience

1.class file management

Be good at using package to manage your files

First, we must pay attention to environment variables.

SET PATH = C: /J2SDK1.4.1_06/bin;% PATH%

Set classpath = .; c: /j2sdk1.4.1_06/lib/tools.jar

Class Flying Today, in order to prevent the conflict of the Class file, you can use your own unique class name: domain name

If you have a package package

9cbs.shao

Javac -d. TestPackage.java when compiling this file

Then the compiler will automatically create a 9CBS / SHAO folder below the current working directory and put the .class file in it.

2. Class package

In order to give the user the largest free space but don't want him to unintentionally destroy your data, you can use the variable declaration as a class.

PRIVATE declares the method as public use of the public method to access variables to implement read and operations for variables. Define two methods to operate, one is getxxx (), one is setXXX (), (where xxx is the variable to access Member name (the first letter is capitalized) such as:

There is Private Int SK; then implements public void setsk () and getsk ();

For example, as follows:

Class Person

{

PRIVATE INT AGE;

Public Void Setage (INT i)

{

IF (i <0 || i> 130)

Return;

AGE = I;

}

Public int getage ()

{

Return Age;

}

}

Public Class TestPerson

{

Public static void main (string args [])

{

Person p1 = new person ();

P1.SETAGE (3);

p1.SETAGE (-6);

System.out.println (p1.getage ());

}

}

Usually called class properties, static modes class methods for class static variables

3. Naming habits

There are some incumbent habits to help communicate with others.

1.Package

2. Class word first letters all write myclass

3.Method name first letters lowercase other words first letters full case MYMETHOD

4. Variable name first letters lowercase other words first letters full case MYVAR

5. Constant is usually written in MyFinal

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

New Post(0)