Dark Horse programmer-Basic enhancement ------ Day 1 (1)

Source: Internet
Author: User

Introduction and use of Eclipse:

Using Eclipse: myeclipse is a collection of eclipse tools. It is also a tool and software developed by Java. IDE is an integrated development environment, supporting engineering management; convenient graphical interface

Ah !!

Project: Generally, a relatively independent project is a project. A project contains multiple java files and resource files which can be managed by one project. This facilitates the maintenance of the relationship between various files.

Project, package, category,CodeThe package name generally starts with lowercase, and the variable name must be meaningful.

Workspace: a workspace can contain multiple project projects. A workspace retains the configuration of a set of Environment options for eclipse (version configuration information of the compiler and runtime environment, and configuration information of the shortcut keys ).

How to set the shortcut keys: Window window, preferences, General general, keys, and so on.

Set the template code block: Right-click the variable and select "surround with" to select the required template code block. How can we set a template code block? Select variables, window, and preferences

Preferences, Java, Editor, template templates, new, enter the name and description, enter the content in the patter box, and use Insert variable

.

Eclipse supports debugging: Double-click to set the breakpoint, find an icon like a worm on the toolbar, click to enter the debugging mode, select the data to be debugged, watch variable, F6 one-step execution, f5 enters the code block.

Import project:Find the project to be imported, paste it to the required workbench, import it (to see if JRE needs to be set), and set it in buildpath.

1.5 new features:

The advantage of static import is that you do not need to write the class name when calling the method. Call the max method in the class and directly import math, which is short for the code. For example, import static java. Lang. Math. sin;

Variable parameters:

Feature: it can only appear at the end of the parameter list;

... Is located between the variable type and the variable name. It can be left with or without spaces;

When a variable parameter method is called, the compiler implicitly creates an array for the variable parameter and accesses the variable parameter in the method body as an array.

Public static int add (int x, Int... ARGs)
{
Int sum = X;
/* For (INT z = 0; Z <args. length; Z ++)
{
Sum + = ARGs [Z];
}*/
For (INT Arg: ARGs)
{
Sum + = ARG;
}
Return sum;
}

Enhance the For Loop

Format: For (type variable name: Set, array name ){......}

The set variables can be arrays or must be collection classes that implement the iterable interface.

The iteration variable must be defined in () <int Arg>

For (INT Arg: ARGs ){

Sum + = ARG;

}

The basic data type can be boxed in or out of the box:

Public static void main (string [] ARGs)
{

Integer I = 2;
System. Out. println (I + 121 );
String S1 = new string ("ABC ");
String S2 = new string ("ABC ");
Integer I2 = 2;
Integer I3 = 2;
Integer I4 = 200;
Integer I5 = 200;
System. Out. println (I3 = I2); // true
System. Out. println (I4 = I5); // false, the value is out of the range.
Integer I6 = integer. valueof (222 );
Integer i7 = integer. valueof (222 );
System. Out. println (I6 = i7); // true; the value exceeds the value range of false.
}

As long as I2 and I3 are between-128----127, the box can be automatically disassembled (the usage of small integers with a high level). This design mode isMeta ModeFlyweight: a lot of very small objects, they have a lot of the same thing, you can

In order to turn them into an object, there are some different things into external attributes, and they are called external States as parameter input methods, the same is the singleton design pattern that we have heard of internally.

Design with an element in Enumeration

Enumeration:

Common Methods:Name()Can return the name of the enumerated constant, intOrdinal()Returns the ordinal number of an enumerated constant (where it is in the enumeration Declaration, where the ordinal number of an initial constant is zero ). String tostring (), return

The name of the enumerated constant.Valueof() Returns an enumerated constant of the specified enumeration type with the specified name.

Why is enumeration required? Its advantage: the source can be discovered during compilation.ProgramThe normal variable method cannot achieve this goal in the development stage.

Use a common class to implement the functions of the enumeration class:

Define a general class to implement: the class name can directly call static, the object private cannot be created, and the number of days can be defined as a constant final,

Define a general class to implement the enumeration class function: A private constructor. Each element is represented by a public static member variable. There may be several public or abstract methods.

Public abstract class weekday {
Private weekday (){}
Public final static weekday sun = new weekday (){
Public weekday nextday ()
{
Return mon;
}
};
Public final static weekday MON = new weekday (){
Public weekday nextday ()
{
Return sun;
}

// Public final static weekday tus = new weekday ();
// Public final static weekday Wen = new weekday ();
// Public final static weekday ther = new weekday ();
// Public final static weekday Fri = new weekday ();
// Public final static weekday sat = new weekday ();

Public abstract weekday nextday (); // abstract Method

/* Public weekday nextday ()
{
If (this = Sun)
Return mon;
Else
Return sun;
} * // * For another method: public abstract weekday nextday (), the class itself is abstract, and The subclass must overwrite the abstract method of the parent class */
};

Public String tostring ()
{
Return this = sun? "Sun": "mon"; // you have used the ternary operator here. There are only two results. Note the following when testing.
}
}

public class enumtest {
Public static void main (string [] ARGs) {
// todo auto-generated method stub
// weekday = weekday. mon;
// system. out. println (weekday. nextday ();
/* weekday = weekday. fri;
system. out. println (weekday);
system. out. println (weekday. name ();
system. out. println (weekday. ordinal ();
system. out. println (weekday. valueof ("mon");
system. out. println (weekday. values (). length); */
for (INT x = 0; x {< br> system. out. println (weekday. values () [x]);
}< BR >}< br> when defining an enumeration with constructor, all constructor methods must be written behind the element, the last element must end with a letter. */

Public Enum weekday
{
Sun (), mon (2), Tue, wed, Thi, Fri, SAT; // Sun (1) >>>>> two Sun >>> one
Private weekday () {system. Out. println ("one ");}
Private weekday (INT day) {system. Out. println ("two ");}
}
Each element is also a class, which is a subclass of trifficlamp and describes the abstract method of trifficlamp.
Public Enum trifficlamp {
Red (30) {// This is an enumeration class with parameters and abstract methods. Enumeration itself is a special class. When printing an enumeration, it automatically implements the tostring method.
Public trifficlamp nextlamp ()
{
Return green;
}
},
Green (45 ){
Public trifficlamp nextlamp ()
{
Return yellow;
}
},
Yellow (15 ){
Public trifficlamp nextlamp ()
{
Return red;
}
};
Public abstract trifficlamp nextlamp ();
Private int time;
Private trifficlamp (INT time)
{
This. Time = time;
}

}

..................................... .................... the New Technology ends ...................................... .......................................

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.