Dark Horse programmer _ JavaSE learning summary 11th days _ development tools & amp; API common objects 1, _ javase 11th days

Source: Internet
Author: User

Dark Horse programmer _ JavaSE learning summary 11th days _ development tools & APIs common objects 1, _ javase 11th days

------- Android training, java training, and hope to communicate with you! ----------

11.01 introduction to common development tools

1: notepad software provided by the operating system

2: Advanced Notepad software example: Editplus, Notepad ++, and UltraEdit

3: Integrated Development Environment (IDE)

This type of software is an application used in the development environment. It generally includes code editor, compiler, debugger, and graphic interface tools.

Integrated development software, including code writing, analysis, compilation, and debugging. All software with this feature can be called IDE.

Example: JCreator, JBuilder, NetBeans, JDeveloper, Eclipse, and MyEclipse

11.02 overview of Eclipse and MyEclipse

Eclipse is a scalable open-source IDE.

Eclipse features: free, pure Java programming, installation-free, and strong scalability

Because it is written in Java, JDK and JRE must be provided for it.

MyEclipse: added functional plug-ins Based on Eclipse, charging for plug-ins, providing a powerful system architecture platform in WEB Development

11.03 download, install, and uninstall Eclipse

Download: http://eclipse.org/

Installation:

Decompress the green version to use (Eclipse)

Double-click the installation version and run next (JDK)

Uninstall:

You can delete folders directly in green.

Professional uninstall software for installation or add and delete programs for control panel

11.04 how to write a HelloWorld case in Eclipse

Select a workspace: The workspace is actually the directory where the source code we write is located.

Use Eclipse to complete a HelloWorld case

The Code takes the project as the basic unit

1. Create a project 2. Create a package 3. Create a Class 4. write code

11.05 how to compile and run a program in Eclipse

Compile: automatically compile. It has been compiled at the moment of saving.

Run:

1. Click the green intriangle button run

2. Click Run under the run menu. You can also use the shortcut key Ctrl + F11

3. Select the file to be Run or right-click the file content to be Run → Run as → Java Application. You can see the Console, which is the built-in Console of Eclipse.

11.06 prompts for Eclipse localization and syntax check

Chinese: Use dropins to install plug-ins

Starting from Eclipse3.5, there is an additional dropins directory under the installation directory. You only need to extract the plug-in and put it in this directory.

Similarly, this method is especially convenient to uninstall plug-ins. We recommend this method.

Both the Chinese and English versions can be used.

 

Source code syntax check

Red Ripple: Incorrect source code

Yellow wavy lines: unused members or members with security risks

11.07 overview of Eclipse windows and views

Window: each basic form is called a window

PackageExplorer: displays the project structure, packages, classes, and resources.

Outline: displays the class structure for easy searching, identification, and modification.

Console: The running result is displayed in this window.

Problems: displays the location of all syntax and errors

Hierarchy: displays the Java inheritance Hierarchy. Press F4.

View: A view is a combination of some windows.

Example: Java view and Debug View

11.08 basic configuration of Eclipse Workspace

1: Environment configuration for program compilation and running (usually not changed)

Window → Preferences → Java

Compiler: the maximum version is selected by default in the compiling environment.

Installed JREs: The JDK Installed in the runtime environment by default. We recommend that you configure Java environment variables.

Use a lower version for compilation and a higher version for running.

A higher version is used during compilation, and a lower version is not supported during runtime.

We recommend that you compile and run the same version.

2: how to remove the default comment

Window → Preferences → Java → Code Style → Code Templates

Select unwanted content and Edit it through Edit on the right

Note: Only delete comments. Do not delete comments that are not comments.

3: Display and hide row numbers

Display: Right-click the blank area on the far left of the Code area and choose Show Line Numbers.

Hide: perform the preceding action again.

4: font size and color

A. Font size And color of the Java code area: window → Preferences → General → Appearance → Colors And Fonts → Java Edit Text Font

B. Console: window → Preferences → General → Appearance → Colors And Fonts → Debug → Console font

C. Other files: window → Preferences → General → Appearance → Colors And Fonts → Basic → Text Font

5: Form disorder. Reset the form window → Reset Perspective

6: Display Console Window → Show View → Console

11.09 use of content auxiliary keys in Eclipse

Alt +/: displays the content of the secondary key.

Main + alt +/: display the main method

Syso + alt +/: displays the output statement.

Other Tips

11.10 use of shortcuts in Eclipse

Common shortcut keys

Ctrl + shift + f: Format

Ctrl + shift + o: import package

Note:

Ctrl +/: single line comment

Ctrl + shift +/: multi-line comment

Ctrl + shift + \: Cancel multi-line comment

Select the code alt + up/down arrow: Move the code up/down

Select the class name (F3 or Ctrl + Click): view the source code

11.11 Automatic Generation of constructor and get_set methods in Eclipse

Automatically Generated Constructor

1. Right-click the construction method without parameters in the code area → source → Generate Constructors from Superclass

2. Right-click the construction method with parameters in the code area → source → Generate Constructors using fields → finish

Automatically Generate the get/set Method: Right-click the code area → source → Generate Getters and Setters

11.12 simplified the inheritance of abstract classes or interfaces in Eclipse

Inherit abstract classes or implement interfaces

1: In the previous practice, first write the class, and then inherit the class or implement the interface in the class.

2: when creating a class, select the class to be inherited or the implemented interface.

An Object is the parent class of all classes. All classes directly or indirectly inherit from the Object.

Override is an annotation, indicating that this method overrides the parent class.

11.13 compile a standard student class in Eclipse and test it

11.14 writing High Jump interfaces in Eclipse abstract animals and specific animal subclasses

11.15 how to generate a jar package in Eclipse and import it to a new project

Jar is a compressed package of multiple class files.

Jar is easy to use.

Jar package: select project → right-click → Export → Java → Jar file → specify a path and a name → Finish

Use jar package: copy the jar package and paste it to the project path to be used. Select the jar package, right-click Build path → add to build path

11.16 how does Eclipse create help documents and use jar packages?

Create help document: select project → right-click → Export → Java → Javadoc → Finish

11.17 how to delete and import projects in Eclipse

Delete A Project: select a project → right-click → Delete 1. Delete from Project Area 2. Delete from hard disk

Import project: Right-click the project area → import → General expand → Existing Projects into Workspace → next, and select the project to import. Note: The project name is selected.

11.18 notes for Eclipse import Project

How to view the project path: Select → right-click → Properties → Resource → Location

Notes for importing a project:

1. A project with the same name cannot appear in the project area (create or import)

2. folders created at will cannot be imported as projects.

Modify project problems:

1. Do not arbitrarily modify the project name

2. If you really want to modify it, do not forget the <name> name in the configuration file. project to change it to the name you changed </name>

11.19 precautions for receiving projects in Eclipse Development

When receiving a message from the same project, first store the directory to delete the original project, then store it again, and then refresh the project.

11.20 basic use of debug in Eclipse

Debugging: Debugging programs and viewing program execution processes

What is a breakpoint: A flag indicating where to start viewing the program

How to set breakpoints: double-click the leftmost part of the first statement of the method.

Where to set the breakpoint: add the first valid statement of each method

How to run the program after the breakpoint is set: In the code area → right-click → Debug as → Java Appliaction

See where:

Debug: Press F6 at the place where the breakpoint is tested, or click. The execution process of one row at a time.

Variables: View program variable changes

ForDemo: source file to be viewed

Console: Console

How to remove breakpoints:

1. Double-click the breakpoint again.

2. Find the Debug view and click Breakpoints. Then, all Breakpoints are displayed, and the trigger is clicked to delete all Breakpoints.

11.21 view parameter passing problems in Java in Eclipse

11.22 API Overview

Application Programming Interface

An API is a Java class that provides various functions in JDK.

11.23 Similarities and Differences between Chinese and programming languages

Similarities: basic syntax and a large number of Idioms

Difference: to learn Chinese, you must first learn and then use it. To learn programming, you can use it now.

11.24 overview of Object classes

Object Class Overview:

Class Object is the root class of the class hierarchy. Each class uses an Object as a superclass. All objects (including arrays) implement this class method.

Constructor: public Object (). The constructor of the subclass accesses the non-argument constructor of the parent class by default.

11.25 hashCode () method of Object Class

Public int hashCode (): returns the hash code value of this object.

The hashCode method returns different integers for different objects. This is generally achieved by converting the internal address of the object into an integer.

Example:

1 Student s1 = new Student();2 System.out.println(s1.hashCode());//185644633 Student s2 = new Student();4 System.out.println(s2.hashCode());//238218385 Student s3 = s1;6 System.out.println(s3.hashCode());//18564463

11.26 getClass () method of Object Class

Public final Class <?> GetClass (): returns the runtime class of this Object.

Example:

1 Student s1 = new Student (); 2 Class c = s1.getClass (); 3 String name = c. getName (); 4 System. out. println (name); // com. test. student5 // chained programming 6 String str = s1.getClass (). getName (); 7 System. out. println (str); // com. test. student

11.27 toString () method of the Object class

Public String toString (): returns the String representation of the object.

The toString method of the Object class returns a string consisting of the Class Name (the Object is an instance of the class) the at tag "@" and the unsigned hexadecimal representation of the object's hash code.

In other words, this method returns a string whose value is equal:

GetClass (). getName () + '@' + Integer. toHexString (hashCode ())

Example:

1 Student s = new Student (); 2 System. out. println (s. getClass (). getName (); // com. test. student3 System. out. println (s. hashCode (); // 32034434 // convert a number into a hexadecimal 5 System. out. println (Integer. toHexString (s. hashCode (); // 30e1736 System. out. println (s. toString (); // com. test. student @ 30e1737 // name of the directly output object. By default, the toString () method of the object is called 8 System. out. println (s); // com. test. student @ 30e173

11.28 equals () method of Object Class

Public boolean equals (Object obj): Indicates whether another Object is "equal" to this Object. By default, it is compared with the address value, but it is of little significance to compare the address value, this method should be overwritten by subclass.

= Of the basic type: compare whether the values are equal

= Of the reference type: compare whether the address value is equal

Example:

1 Student s1 = new Student ("James", 15); 2 Student s2 = new Student ("James", 15); 3 Student s3 = s1; 4 System. out. println (s1 = s2); // false5 System. out. println (s1 = s3); // true 6 System. out. println (s1.equals (s2); // false7 System. out. println (s1.equals (s3); // true

11.29 code optimization of the equals () method of the Object class

Example:

Override the equals method of the Student Class

1 Student s1 = new Student ("James", 15); 2 Student s2 = new Student ("James", 15); 3 Student s3 = s1; 4 System. out. println (s1 = s2); // false5 System. out. println (s1 = s3); // true 6 System. out. println (s1.equals (s2); // true7 System. out. println (s1.equals (s3); // true

11.30 finalize () method and clone () method of the Object class

1. protected void finalize ()

Throws Throwable: When the Garbage Collector determines that there are no more references to this object, the object's garbage collector calls this method.

2. protected Object clone ()

Throws CloneNotSupportedException: Creates and returns a copy of this object.

Example:

1 Student s1 = new Student (); 2 s1.setName ("James"); 3 s1.setAge (25); 4 // clone Student Object 5 Object obj = s1.clone (); 6 Student s2 = (Student) obj; 7 System. out. println (s2.getName () + ":" + s2.getAge (); // James: 25

The cloned class must implement the Cloneable interface. The Cloneable interface is a tag interface that indicates that the Object. clone () method can legally copy the instance by field.

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.