Java basics 1

Source: Internet
Author: User
Tags define abstract java reference

 

1.JavaBasic Introduction

A)Configuration in the operating systemJavaEnvironment variable?

PATH = % PATH %; c: \ java \ bin;

CLASSPATH =.; c: \ java \ lib \ classes.zip

B)What should I pay attention to when naming class name, attribute name, method name, and constant name?

The identifier is composed of letters, numbers, and dollar signs "$", underlines "_". The first character is not a digit.

Class Name: The first letter must be capitalized, and the first letter of each word must also be capitalized.

The first letter of a class name can only be an underscore or letter, followed by a number.

Attribute name: the first letter is lowercase, and then the first letter of each word is also uppercase. It cannot be the same as the keyword.

Method Name: the first letter is lowercase, and then the first letter of each word is also uppercase.

Constant name: All letters must be capitalized and different words must be distinguished by underscores.

C)Must the class name be the same as what?

The class name must be the same as the created java file;

D)JavaCompile and run commands and formats?

Compile: javac class name. java

Run: java class name

E)JavaBasic Data Type in ?

Byte char short int float long double Boolean

F)JavaWhich data types are available?

Basic data types,

Reference Type (class type)

G)StringWhich of the following are common methods?

ValueOf (): converts other basic data types to strings.

Trim (): returns a copy of the string and removes the white space.

ToUpperCase (): uppercase

ToLowerCase (): lowercase characters

ToCharArray (): converts a string to a new character array.

Substring (int beginIndex, int endIndex): returns a new string, which is a substring of this string.

Length (): returns the length of this string.

LastIndexOf (String str) returns the index at the rightmost of the substring in this String.

Equals (Object anObject): Compares this string with the specified Object

EqualsIgnoreCase (String anotherString): Compares this String with another String, case-insensitive

IndexOf (String str): returns the index of the first occurrence of the substring in this String.

IsEmpty (): returns true only when length () is 0.

Concat (String str): connects the specified String to the end of the String.

2.Class and Object

A)Class Definition

Classes are abstracted by the same features and same behavior objects;

A class consists of two parts: attributes and methods. The attribute corresponds to the feature, and the method corresponds to the behavior.

B)Object Definition

Objects are the objects in real life and the objects imagined in my mind.

An object consists of features and behaviors.

C)Define the format of the class

Public class name {

Private Data Type attribute name;

Public return value type method name ([parameter type parameter name,...]) {

// Method body

}}

D)Format of the created object

Class Name object name = new class constructor;

E)Classification of methods

Whether or not the return value is returned;

There are no parameters;

F)Method Overloading

Must be in the same class,

The method name must be identical, and the number or type of parameters included in the method must be different.

G)Constructor

1. No Return Value Type

2. The function name must be the same as the class name.

3. There is no constructor with parameters by default. However, if there is a rewrite, the default constructor will not exist;

4. constructor is used to instantiate an object. An object is instantiated every time it is called.

H)Value Transfer

Applicable to the basic data type and String type;

The value transfer function copies the values in the target variable and stores them in a new variable. The new and old variables do not affect each other.

I)Reference Transfer

Applicable to java reference types.

The reference transfer is to copy the address stored in the object name and store it in another object name. The two object names point to the same memory and "change all ";

J)ThisKeywords

1. differentiate between attributes. This is an attribute, but not a form parameter;

2. indicates the current object. You can use this. Attribute or this. method name to call attributes and methods;

3.Class inheritance

A)Why inherit?

1. reduces the amount of code, improves work efficiency, and reduces code redundancy.

2. Improved Program scalability.

B)Inherited syntax format

Public class subclass (superclass) extends parent class (base class ){}

C)Which methods and attributes can the subclass inherit from the parent class?

All methods and attributes can be inherited.

But when calling:

The subclass and the parent class are in the same package: the subclass can call common and protected attributes and methods. If the subclass overrides the parent class method, the overwritten method is called;

Sub-classes are different from parent classes: only common methods and attributes can be called by the quilt class.

D)Method Rewriting

1. The method name must be the same

2. Implementation of methods should be different.

3. There must be an inheritance relationship.

4. The number and type of parameters included in the method must be identical.

5. The access modifier can be different from the parent class, but must be greater than or equal to the access modifier of the parent class.

E)Automatic Transformation

The condition is that there is an inheritance relationship;

Parent class name object name = new subclass Constructor (Parameter Value List );

Disadvantage: you cannot call the method that the subclass does not override.

Advantage: it encapsulates the unique methods of sub-classes;

It simplifies code writing and improves program scalability;

F)Polymorphism

Polymorphism is composed of a series of content combinations, including method overloading, inheritance, method rewriting, and automatic transformation.

G)Interface

An interface is used to define an abstract method. After an abstract method is defined, the implementation class must overwrite all the methods in the interface.

H)Abstract class

A set of interfaces and classes.

What are the differences between interfaces, abstract classes, and classes?

1. interfaces can only define abstract public methods. classes can define any methods that are not abstract.

2. The interface can implement multi-inheritance. abstract classes and common classes can only be single inheritance.

3. The key word of the interface definition is interface; the key word of the class definition is class.

4. interfaces can only be inherited. The inherited keywords are extends. classes can inherit (the inherited keywords are extends) or implement interfaces, you can implement multiple interfaces (the keyword is implements ).

5. The interface has no constructor and cannot instantiate objects. abstract classes cannot instantiate objects because they can define abstract methods. Common classes have constructor and can instantiate objects.

4.JavaGui and events

A)JavaHow many GUI sets are there?

Three types are available: swing, swt, and awt.

B)Why useSwing,Do not useAwt?

It provides all the functions that AWT can provide, and greatly expands AWT functions with pure Java code.

C)Which class does all graphic interfaces inherit from?

Object Class

D)Procedure

1. Determine the event source;

2. Set conditions for the event source and event capture conditions;

3. Create a class for event processing and instantiate the class object;

4. end;

E)Common listeners

Mouse listener (inherited fromMouseAdapterClass)

ActionListenerClass

F)ActionEventAndMouseEvent

ActionEvent is a semantic event, while MouseEvent is a low-level event.

 

5.Arrays and queues

A)Array

An array is a linear data structure.

What is an array operated on?

Array subscript

Multi-dimensional array

Is an extension of a one-dimensional array.

Get the format of the total number of rows?Array. length

Get the total number format of columns?Array [I]. length

Disadvantages of arrays?Only one type of data can be stored in the array;

The length of the array is fixed. It cannot be implemented in case of append or delete length.

B)Queue:Defines a class that encapsulates operations on arrays.

Arrays can be instantiated using objects.

A queue can only store one data type.

However, java provides a concept called generics. E can represent all java classes, and then E can be used together to store array elements of different types;

6.Redraw

1. A queue is required to store the obtained objects.

2. There must be a class for Drawing Images. Each painting is added to the queue.

3. Call the painting method of the parent class, and redraw the painting class stored in the cyclic queue once each time.

7.Wuziqi

I. Interface

Wuzi interface form: Set the form attributes and display the form

When displaying the interface, you need to have a checkerboard, which must always exist on the form.

A 15*15 checkboard. The size of each lattice is 40 pixels, and the size of each piece is 30 pixels.

Use arrays to correspond to the pawns.

Ii. Win-win algorithm:

If more than five pieces of the same color are connected to the "mi" direction, the player wins;

3. Man/machine:

8 (or more) pieces are arranged based on the links on the board );

There is a continuous activity (indicating that only one piece is connected, and the eight sides around it are active paths), and a half (indicating that a piece is connected, one side is blocked by a different color piece, and one line can only be down ), similarly, there are two active connections, two semi-connections, three active connections, three semi-connections, four active connections, and four semi-connections. These locations are set to different weights, and each piece has different weights, the weights of all pawns are accumulated together, and the place where the maximum weight is determined is the place where the sub-keys are located.

4. re-painting: each piece is placed in the queue and re-Painted together with the form.

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.