Java learning notes

xiaoxiao2021-03-06  117

2004-8-12 Thursday Yina has heavy rain

1. How to set up a Java development environment (Win2000) Answer: start-control panel-system-advance-environment variables Setting environment variable: path =% PATH%; C: /J2SDK1.4.2_05/bin; classpath =.

Note: The Javac editor is always looking for files, while the Java interpreter only looks for the current directory if the "." Directory is included in the classpath. If the class path is not set, what problem does not produce - the "." Directory containing ".". However, if the class path is set, it does not include ".", It will generate problems - the program is not erroneous, but it can't run.

2. What is Java? Answer: 1) Programming Language (first compiled again); 2) Development environment; 3) Operation environment; 4) Deploy the environment;

3. Java Features Answer: 1) Simple (Java syntax is a "pure" version); 2) Portable 3) Object-Oriented 4) Distributed (Java opens a socket connection and other cumbersome network tasks It is very easy) 5) Quality (Java compiler) Check out the mistakes displayed in many other languages; the pointer model used by Java can eliminate possible possible possible) 7) Multi-threads (more The simplicity of thread programming is one of the main causes of Java's popular server-side development language) 8) Safety (using Java can build anti-virus and tamper-proof system) 9) Dynamic (Java can add new methods and instance variables) And the client does not need to do any changes) 10) The architecture neutral (independent of the byte code is independent of the computer architecture, as long as there is a runtime system, can be executed on a variety of processors)

4. Basic concepts in Java Answer: 1) The source file only includes a PUBLIC type class / interface, file name and class / interface name, with .java as a file suffix. 2) Package (Package, this idertify can only be placed in the first line, and only one line can only be organized) a piece of entity in a file system in a file system in a directory / folder type.

In fact, what you have learned today is much more than listed above, more knowledge points have met with us through exercises, and create classes, create classes, create classes, and control the format of printout (through message dialogue Box output results), as well as the difference between local variables, instance variables, global variables (class variables, static variables). The above knowledge points will gradually come into contact with future learning, so it is not described in detail. In addition, today's learning content is to spend a few times a few times before it is clear. Someone is in hand, it is so good!

Teaching Java's teachers have two, one taught knowledge, a counseling practice. Teacher Teacher Teacher is not warm, and there is a bamboo in the chest. Seeing him, as if seeing the height of Java. Teacher Xue, who is tutoring, has a question, close to our distance from Java.

2004-8-13 Friday Yin

1. Three forms of comments Answ: // Untrial Comments / * One or Multi-line Notes * / / ** Document Note * /

2. ";", "{}", "A: Java statement is separated by a semicolon; the Java code block is included in the braces; ignore spaces.

3. Identifier Answer: 1) Use to name, methods, and variables, and packages; 2) start with characters, "_" or "$"; 3) no length limit.

4. Data Type Answer: 1) Integer 8-bit-128 to 127 Short 16-bit-2 ^ 15 to 2 ^ 15-1 INT 32-bit-2 ^ 31 to 2 ^ 31-1 long 64-bit-2 ^ 63 Between 2 ^ 63-1 2) Floating point type Float 32-bit Double 64-bit 3) Character type char 16-bit 4) Boolean Boolean False / True Note: 1) Char is a 16-bit integer, literal value must be used The quotation is enclosed; 2) String is a class, non-raw data type; 4) 黙 黙 黙 Floating point type is Double; 5) The Float data type has a suffix "f" or "f", and the Double data type can be followed by suffix "D" or "d";

5. Identifiers Naming Rules A: 1) Class / Interface Name First Letter Capital; 2) Method, Variable Name First Letter Capsules, the remaining letter capitals; 3) The constant name is all uppercase; 4) All lowercases.

6. Understand the object A: In OOP, the program consists of objects, and these objects have some attributes and some operations (Methods) that the objects can be performed. The key to the efficiency of OOP is that it allows each object to execute a set of related tasks.

2004-8-16 Monday Yin

Expression and control flow

Variables and scope

A: 1) The local variable is defined inside the method, and its scope is the method, also known as temporary variables, and stack variables. 2) The instance variable is defined inside the class, and its scope is the entire class. If the initial value is not defined, the system will automatically assign it.

Type 黙 recognition BYTE 0 Short 0 int 0 long 0l float 0.0f double 0.0d char '/ u0000' Boolean False All Reference Types Null 2. Operation Answer: 1) >> The front is zero zero, the front is one supplement one ; 2) >>> No symbol right shift; 3) && short circuit, the front is fake, the expression is false, the back is not required; 4) || Short circuit or, true, expression is true, back is not calculated ;

3. Conversion between digital types: 1) Byte - → short - → int - → long 2) Char - → int - - → float 3) Float - → Double 4) long - - - - → Float 5) Long - - - → Double 6) Int - → Double Note: 1) The arrow indicates no information loss conversion, the virtual arrow indicates that the conversion may cause loss; 2) int and float is 32 bits, but Float There are several digits that represent the power of the power, which is small in the accuracy bits, so there may be losses. LONG turns to double; 3) Char and Short are 16 bits, but the char belongs no symbol number, its range is 0 ~ 2 ^ 16, the range of Short is -2 ^ 15 ~ 2 ^ 15-1, so char And SHORT cannot be converted to each other;

4. Force Type Conversion Answer: 1) Syntax: The type of target to be converted is given in parentheses, followed by the variable name to be converted. Example: DouBLC X = 9.997; INT NX = (int) x; 2) If the type of try to force the conversion exceeds the scope of the target type, the result is a different value that is interception; 3) Can't be in the Boolean value and any digital type Mandatory type conversion, if you want to conversion, use conditional expression, examples: b? 1: 0.

5. Three types of automatic conversion Answer: 1) Assignment Double D = 1.23F; 2) Method call Math.SQRT (2); 3) Value calculation conversion -9.232e20 1;

6. Two types of mandatory conversion (CAST) Answer: 1) Assignment 2) Method call

7. Switch and Case: 1) The Switch variable can be byte, short, char, int; 2) The default value can be located at the top of the switch code, the middle or bottom; 3) Break is not necessary. For example: Case 1: Case 2: Case 3:

2004-8-17 Tuesday

Array

1. A declaration number group: 1) a set of identical types (can be class) data; 2) A array is an object; 3) Declare an array does not create an object; 4) A number of groups can be declared in the following form: int [ ] i or int i [] car [] c or car C []

2. Create an array answer: 1) Create the original array int [] i = new int [2]; 2) Creating a class type array car [] c = new car [100]; 3) An array has an initial value after the creation is created.

3. Initialification number group: 1) Initialization, create, and declaration separate int [] i; i = new int [2]; i [0] = 0; i [1] = 1; 2) Initialization, create, and declaration Int [] i = {0, 1}; car [] c = {new car (), new car ()};

4. Multi-dimensional groups: 1) effective int [] [] i1 = new int [] [3]; int [] [] i2 = new int [2] []; i2 [0] = new int [2] , I2 [1] = new int [3]; 2) invalid int [] [] i1 = new int [] [3]; 3) array length int [] i = new int [5]; int LEN = i. Length; // len = 5; student [] [] st = new student [4] [6]; len = st.LENGTH; // LEN = 4; len = ST [0] .length; // len = 6 Which of the following paragraphs can be performed correctly? (a, c) 1. a char [] i = {'a', 'b'}; i = new char [] {'b', 'c'}; b char [] i = {'A', 'b'}; i = {'b', 'c'}; c char [] i = new char [2]; i = new char [] {'b', 'c'}; d char [] i = New char [2]; i = {'b', 'c'};

Wednesday, 2004-8-18

Today, I finished the array, and the concept of class opened a head. Package, inherit, polymorphism, exemplified by these three concepts, examples, cats, dogs, mammal motives. Lifting a cat, dog adding an eye as long as you change the parent class. Three eyes of dogs? We laugh, just, how to write today? It is some conceptual things.

The interface (Interface) is to solve multiple inheritance and inherit the polymorphism (class, method). The package can maximize code reuse. Class is an abstraction, containing properties and methods of changing attributes. Object is an instance of a class, except these still? Is the array be an object?

Can't be sure, then check the API, ask students, ask the teacher. Not good? That teacher gives you a small cookstick! After the classroom, the head is DV, and the image is truly recorded with our learning life, no one will leave the team.

Most knowledge solved in the classroom, time, reading, pre-study, how far can you see how far. Since it, look at the flowers in the fog; and the teacher teaches, and it is stunned. All the way, just worry: Whether you can finish Core Java for 18 days.

2004-8-19 Thursday

Objects and classes (on)

1. Package, Polymorphism, and Inheritance Answer: 1) Package a. Binding data and behavior in a package and hides data for the user's user. The data in the object is called the instance field, the function of operation data and the method of the object are called the object. "Method). A particular object is an instance of a particular value in an instance field. B. The key to implementing the package is never let the method directly access other class instance fields.

2) Inherit a. Build a new class on the basis of existing classes. When inheriting an existing class, it is reused (inherited) the method and field of the class, while also adding new methods and fields to the new class. B. When the subclass is defined by an extended superclass, only the difference between the subclass and superclars is required. Therefore, in the design class, put the most common method in the superclass, put more specialized methods in the subclass. 3) Polymorphism) An object variable can point to a variety of actual types.

2. Class and object Answer: 1) Class: Abstract of data type / metadata; 2) Object: Instance of the class (instance of).

3. Method definition: 1) Format ([argument_list>]) [throws ] {}, for example: public string getname () {return name;} 2) When there is no return value, the return type must be defined as a void; 3) The constructor has no return type.

4. Parameter passes A: Java language always uses the piped call. This means that the method is just a copy of all parameter values. Therefore, the method cannot modify the content of any parameter variables passed to it.

5. This Answer: 1) This is an implicit parameter, representing the object being constructed; 2) If the first statement of the constructor has the form (...), then this constructor will call other configurations in the same class. .

6. Features of the package: 1) Realize the specific implementation; 2) Enhance maintainability of all user unified interfaces; 3) Enhanced maintainability.

7. Method Overloaded: 1) The method name is the same; 2) The parameter must be different; 3) The return type can be different;

May 5-20 Friday sunny

Objects and classes (below)

8. Create and initialize the object A: 1) Assign memory space for an object and initialize the value of this object is: 0 / null / false. 2) Call the constructor.

9. Contents: 1) The constructor and class have the same name; 2) A class may have a plurality of constructors; 3) The constructor can have 0, 1 or more parameters; 4) The constructor does not return A value; 5) The constructor can only be called with the New operator.

10. Constructor Heavy Answer: 1) Acknowledge The constructor does not have a parameter constructor, which sets all instance fields to the default value; 2) If the class writes do not have a constructor, the system will automatically provide a confirmation constructor, then The object that is constructed is not constructed is illegal.

11. Subscription: 1) is a relationship (existing class, base class), or a parent class; and new class is called subclass Child class) or derived class); 2) a declared type, public class student extends Person {...}; 3) single inheritance.

12. Inheritance Answer: 1) The constructor cannot be initialized; 2) The method and field can be initialized; 3) The sub-constructor automatically calls the parent class's confirmation constructor; 4) When the parent class confessed that the constructor does not exist Subcarpse constructors should explicitly call other constructors of the superclass.

13. Super Answer: 1) Call the superclass method; 2) Call the superclass constructor.

14. Polymorphism A: 1) A object variable can point to a variety of actual types; 2) It is a runtime declaration.

15. InstanceOf Operation Answer: 1) Boolean Type; 2) Determines if an instance belongs to the specified class / interface 16. Casting Answer: 1) Process of converting a type forced into another type is called type conversion ( Casting); 2) The only reason for conversion is that after temporarily ignoring the actual type of objects, you need to use all the functions of the actual object; ; 4) Try to transition and instanceof operators as little as possible.

17. Overridden Answer: 1) The name, the parameter list, and the return type; 2) Modifier cannot get getting narrower and narrower; 3) abnormal throwing cannot be more and wider;

Monday, 2004-8-23 Monday

Advanced language characteristics (on)

1. Static field and method Answer: 1) Static field: There is only such a field in each class. Conversely, each object of the class has a copy of this instance field; 2) Static method: Direct access by objects; non-static variables cannot be accessed; not being rewritten by non-static methods;

2. Initialization Block Answer: 1) Execute it only; 2) The initialization block is first run, and then the body portion of the constructor is executed.

3. Detailed execution process after calling the constructor: 1) Initialize all data fields (0, 0.0, false or null); 2) Perform all field initialization statements and initial blocks in the order in the class declaration FIG. 3) If the first row code of the constructor is called another constructor, the called constructor body is performed; 4) performs the constructor main body.

4. Final Keyword Answer: 1) Final Class cannot be inherited; 2) Final method cannot be rewritten; 3) Final variables cannot be changed;

5. Abstract: 1) The method has no method, must be declared as an abstract method; example: Abstract int getage (); 2) A class containing an abstract method must declare an abstract class; 3) Abstract classes cannot be instantiated However, the object variables that can still be created; 4) Can declare the method or class type as abstraction; Note: 1) The abstract method is like method placeholders, these methods must be implemented in subclasses; 2) Even without abstract methods The class can also be declared as an abstract class.

6. Interface A: 1) The interface is another form of an abstract class (abstract class without instance variable); 2) All methods in an interface are abstract methods; 3) All variables in the interface must be defined as Final STATIC; 4) The interface can inherit multiple interfaces.

Note: 1) The method in the interface is automatically set to public, so declaration methods in the interface do not need to provide a public keyword. But when implementing the interface, the method must be declared as public.

2004-8-24 Tuesday

Advanced language characteristics (medium)

7. Access Control Answer: Modifier Internal Class Same Subclass Other PUBLIC √ √ √ √ Protected √ √ √ Default √ √ Private √

8. "==" Operators and Equals () Method Answer: 1) "==" Operator determines whether two references points to the same object; 2) Equals () method determines whether the two objects point to the same memory area (this The test is not too large. If you want to test whether the object is equal, you need to overwrite the Equals method and make more meaningful comparisons);

9. TOSTRING () Method Answer: 1) Like the equals () method, toString () is another important method of the object class; 2) It returns a string representing the value of the object. Almost every class covers this method to print the representation of the current state of the object. 3) Whenever the object is connected to the string, you can use the " " operator, and the Java compiler will automatically call the TOSTRING method to get the string representation of the object. Example: POINT P = New Point (10, 20); String Message = "The current position is" p; // automatically calls p.toString () 10. Internal Category: Internal classes are classes defined in other categories : 1) Internal class objects can access the implementation of the object that created it - including those private data; 2) Internal classes can hide, not seeing other classes in the same package; 3) Anonymous internal classes can easily define runtime Tune; 4) It is very convenient to use the internal class when writing an event program.

11. Static Internal Category: 1) The simplest form of internal classes; 2) Cannot be with the external class; 3) Compiled into a separate class file; 4) Only access the external class static method, static instance variable ( Includes private types);

12. Examples Internal Category: 1) Define inside the class, no static modifier; 2) like instance variables; 3) Access all instance variables of the external class; 4) Creating an instance of an instance of an instance in an external class : This.new innerClass (); 5) Create an instance of an instance of an instance in an external class: (New OuterClass ()). New InnerClass (); 6) Accessing an instance in an internal class: OuterClass.This . MEMBER;

13. Local internal classes: 1) Define in the method; 2) The minimum internal class; 3) and local variables are similar, cannot be defined as public, protected, private, and static; 4) can only access the Final local part variable.

Wednesday, 2004-8-25 Wednesday

Advanced language characteristics (below)

14. Anonymous internal class Answer: 1) No class; 2) No Class key; 3) No inheritance and declaration; 4) There is no constructive function;

15. Package Answer: Original Basic Type Packaging Boolean Boolean Byte Byte Short Short Char Character Int Integer Long Long Float Float Double Double

16. Collection Interface Level Answer: Collection ↑ | ˉˉˉˉˉˉ | set list map ↑ ↑ | | sortedset sortedmap

1) SET: There is no repetitive object in the set class; 2) sortedset: and set interfaces, but elements are arranged in ascending paragraph; 3) List: Elements are loaded and removed, and repeated objects can be saved. 4) MAP: The only keyword identified object is stored, and there is no repeat keyword. 5) SortedMap: and the Map class, but the object is arranged in ascending order of their keywords. 17. Collection class levels include specific classes: Collection ↑ | ˉˉˉˉˉˉ | Hashset LinkedList Hashtable (SET) Vector, ArrayList Hashmap (list) ↑ ↑ | | Treeset Treemap (SortedMap)

18. The differences and contacts between the five most common sets: 1) ArrayList: single, non-synchronous, efficiency, multi-use for query 2) Vector: element single, synchronization, thread security, more to query 3) LINKEDLIST: Element is single, mostly used for insertion and deletion 4) Hashmap: Element is paired, non-synchronous, element can be empty 5) Hashtable: Element is pair, synchronization, element is not empty

19. Reflection: 1) Determine the class of an object; 2) Get a class of modifications, variables, methods, system functions, and phase class information of the parent class; 3) find out which constants and methods are from one interface Declare; 4) Creating a class that is known at runtime; 5) Method for calling an object;

2004-8-26 Thursday sunny

abnormal

1. Abnormal basic concept answer: 1) Abnormal event change program process; 2) When an exception event occurs, an exception is thrown; 3) The code response processing exception is called Exception Handler; 4) Exception handler capture exception ; 5) Abnormal processing allows you to concentrate on solve problems in one place, then separate the code of the wrong code to another.

2. Capture anomalited answer: 1) Set a TRY / CATCH code block; 2) If any code in the TRY block throws an exception specified by the CATCH clause, then a. Program skips the other code in the TRY block; b. Program performs processor code in the Catch clause. 3) If there is no exception in the TRY block, skip the Catch Sentence content directly. 4) If the exception thrown in the TRY block is not specified in the Catch clause, the method will immediately exit.

3. Processing anomalous: 1) Capture and handle those who are known how to handle exceptions, and passing those who don't know how to handle it; 2) If you want to pass anomalies, you must add a throws modifier in the definition of the method to notify The caller may throw an exception; 3) The abnormality thrown by the subclass method cannot exceed the range of the super class method throws instruction. If the parent class does not throw any exception, you must capture each "checking exception" in the sub-class method.

4. Capture multiple anomalous answers: 1) Each exception type uses a Catch clause; 2) As previously Catch clause captures exception, it will directly skip the following Catch clause content; 3) It is recommended to press the subclass of the exception -> Super class The order of order is arranged in the order of the Catch clause. 5. Finally declaration A: No matter if it is captured, the code in the finally clause is executed;

6. Exception call stack Answer: 1. Which method called code occurs, which method is returned to, and the code called by the main method has an exception, returns to the virtual machine.

7. Exception Level Answer: 1) The class originating from Error represents an uncommon environment (usually hardware level); 2) The application cannot restore normal from Error; 3) All Java exceptions originate from Exception; 4) RuntimeExcepiton is also called unchecked anomalies; 5) No abnormalities do not have to capture; 6) Other abnormalities, also known as inspection exceptions, must be processed

Object ↑ throwable ↑ | ˉˉˉˉˉˉˉˉ | Error Exception | ↑ | | ˉˉˉˉˉˉˉ | rtimeException

8. Some unchecked anomalous: 1) java.lang.arithMeticexception such as: except 0; 2) java.lang.nullpointersReption, such as: no initialization, a referen, use; 3) java.lang.ArrayIndexoutofboundsexception, such as: call a 10 The content of the eleventh element of an element; 4) java.lang.numberformatexception such as Integer.Parseint ("a");

9. Write your own anomalus: 1) It is only necessary to inherit from Exception or from Exception's subclasses. You can derive the class you need; 2) Get used to providing a default constructor for each anomaly class And a constructor containing detailed information.

10. Throw your own anomalited answer: 1) Add a THROWS modifier in the definition of the method to notify the caller to throw an exception; 2) construct a class of instances in the method, then throw it Example.

Three java little jokes

1. As a father's son, I am his subclass, I inherit his properties and methods, but why my father will drive, I won't? This method of driving this may be a final type.

2. You go to 20 companies to interview, maybe there is no family asking you the internal class (tired). Although the internal class is very small, no human-nature companies have a successful application, it is recommended to go.

3. When you go out this morning, you watched a scene that shouldn't see it, so that you have not worked for one day. Seeing this exception, your project manager comes to ask you how to encounter problems (try to capture abnormalities)? You shake your head (unusual type is wrong), then your transaction manager came over, you told him that you have seen your favorite POLO car in the morning. The transaction manager comforts you can turn the target into BMW, and promise to open his BMW together on the weekend to go to the sea pastoral pocket (capture abnormal), your emotions are greatly improved and automatically overtime (exceptions are processed, the program is working properly). Unfortunately, your business manager is not good, he directly reflects your situation to the general manager (capture exception, no processing directly). More unfortunately, maybe your company's personnel and project managers are just not, this situation is seen by your head, he will be removed (first captured by Exception, rough processing). After you are expelled, the entire project cannot go, and finally the company is announced. Because the whole company is alone. 2004-8-27 Friday sunny

Create a graphical user interface

1. AWT A: 1) Abstract Window Toolkit (Abstract Graphics Tool); 2) Provide a series of objects to create a graphical user interface; 3) In the java.awt package, all types of types: A component: Visualization graphics Basic class, including containers; B vessel: a special component that can load other components; C Layout Manager: The container is used to locate (arrange) a user interface component.

2. Create a graphical user interface Step 1: Select the container: 1) Components can be added to the container; 2) Usually use the following vessels: frame, dialog, applet, panel; component ↑ Container ↑ | ˉˉˉˉˉˉ | ˉˉˉˉˉˉ | Scrollpane Window Panel ↑ | ˉˉˉˉˉ | | Frame Dialog Applet ↑ FileDialog

3. Container Method: 1) Add (Component COM): Add components to the container; 2) setLayout (): Setting the layout manager; 3) Pack (): Build a form according to the layout of the preferred size and components; 4) SetTitle (): Set the form header;

4. Create a graphical user interface Step 2: Select the Layout Manager: 1) Set the container manager; 2) Component method setLocation (), setsize (), setbounds () Define the size of the component and Location; 3) Window Controller Acknowledgment Layout Manager is borderLayout; 4) Panel class container configurable layout manager is borderlayout;

5. Create a graphical user interface Step 3: Add Component Enterorader Answer: 1) Creating Components TextField TF = New TextField (); ... 2) Use the container method Add () to increase the component into the container Add (TF);

6. Create a graphical user interface Step 4: Create a transaction Answer: Use the component method: addXxxListener ()

7. Frames Answer: 1) Original from a Window class; 2) Can not be placed in other parts as a part; 3) There is title, even frame and menu toolbar; 4) The default layout manager is borderLayout; 5) Use setLayout () Change the layout manager; 6) Create a Frame code: frame frame = new frame ("The first GUI"). 8. Panels Answer: 1) Typically added to other containers; 2) Place a set of related components into the container; 3) The default layout manager is flowLayout;

9. FlowLayout Layout Manager A: 1) Respect each component itself; 2) Construction method: flowLayout () FlowLayout (int Align) FlowLayout (int Align, int hgap, int vgAP) int align: flowLayout.left, flowlayout .Right, flowlayout.center, flowlayout.Trailing, flowlayout.trailing

10. BorderLayout Layout Manager A: 1) Divided into five areas: BorderLayout.center, BorderLayout.east, BorderLayout.west, BorderLayout.South, BorderLayout.North 2) The north-south area holds the component height, but the width is changed by the width of the container; 3) Things to maintain the width of the component, but the height is changed by the container width; 4) Changes in the central region, high and wide changes; 5) Construction method borderLayout (), BorderLayout (int hgap, int vgap)

11. GridLayout Layout Manager A: 1) Aligning components in the container; 2) Each grid is equal size; 3) Ignore the original size of each component; 4) Construction method: GridLayout () GridLayout (int ROWS, INT COLS) GridLayout (int Rows, int COLS, INT HGAP, INT VGAP)

12. CardLayout Layout Manager A: 1) Processes each component into a card, only one card visible at any time; 2) Do not respect the original size of the component; 3) Method: Cardlayout () Cardlayout (int HGAP) , int VGAP) 4) Cardlayout Method Void First (Container C) Void Last (Container C) Void Show (Container C, String Name) 13. GridbagLayout Layout A: 1) Place the component in grid 2) A component can take multi-line or column; 3) When the component is determined by the gridbagconstraints object when the component is added to the container; 4) Construct: GridbagLayout (); 5) Important: setConstraints (Component C) Gridbagconstraints GCS)

14. GridBagConstraints Class A: Constructor GridBagConstraints () GridBagConstraints (int gridx, int gridy, int gridwidth, int gridheight, double weightx, double weighty, int anchor, int fill, Insets insets, int ipadx, int ipady) 2004-8- 30 Monday sunny

AWT component library

1. Component public method Answer: 1) setForeground (): Setup color; setBackground (): Set background color; 2) getForeGround (): get the foreground color; setBackground (): get background color; 3) setENABLED (): make Component is valid; getNabled (): Available in components; 4) setvisible (): make components visual; getVisible (): acquisition component visual state; 5) setFont (): Set component font; getFont (): acquisition components Font; 6) setsize (): Set component size; getSize (): acquire component size; 7) getPreferRedsize (): get the default size; 8) setLocation (): Set the component location; getLocation (): get the component location; 9 ) setbounds (): Move and re-adjust the size; getBounds (): Returns the range of this component (location and size); 10) Paint (): Drawing components; repain (): heavy painting; Update (): Update;

2. Button Answer: 1) Generate actions Action; 2) Constructor: Button () Button (String Label) 3) Method: SetActionCommand (): Set the command name of the action event triggered by this button GetActionCommand (): Returns the command name of the action event triggered by this button; setLabel (): Set the tag of this button; getLabel (): get the tag of this button; addActionListener (): Add the specified action listener to pick up Button action event; RemoveActionListener (): Remove the specified action listener to make the button no longer receive action events; getActionListener (): Return to all registered action listeners; 3. Canvas (Canvas) A: 1) Used to display graphics; 2) Draw profile, pixel and text with many colors 3) Construction method: canvase () Canvas (graphicsconfiguration conf)) Method: Paint () Update ()

4. Checkbox Answer: 1) Use, display a check box in an selected or unchecked; 2) As a member of the checkbox group, its performance and radio button; 3) Constructor: checkbox () checkbox (String label) checkbox (String label, boolean state) checkbox (String label, boolea state, CheckboxGroup group) checkbox (String label, CheckboxGroup, boolean state) 4) relates to a method a checkbox: addItemListener (): Add specified Project Listener Receives the check box project event; removeItemListener (): Remove the specified project listener, so that the check box no longer receives the check box event; setState (): Set the check box to a specified state; getState : Judgment the check is in the "Open" or "Off" state; setLabel (): Settings the check box tag; getLabel (): Get the check box tab. 5) About CHECKBOXGROUP method GetSelectedCheckbox (): Get the current selection from the check box group; setSelectedCheckbox (): Setting the check box in the check box group is selected. 5. Down-down list (Choice) Answer: 1 Single selection of drop-down menu; 2) The currently selected item is displayed on the screen; 3) Constructor: Choice () 4) Method: add (): To drop list Add option elements; insert: GetSelectedItem (): getSelectedItem (): getSelected InditEx (): getSelected InditEx (): GetSelectedIndex (): Returns the index of the current option; getItem (): Return to the drop-down list Specify the index position element Format; additemlistener (): Add to specify a project listener, receive item events from the drop-down list; removeItemListener (): Remove the specified item listener to make it no longer receive item events from the drop-down list;

6. Label Answer: 1) Used to display text on the screen; 2) There is no direct interactive action; 3) Construction method: label () label (String text) Label (String text, int alignment) method SetText (): Set the text of the tag as the specified content; getText (): get the tag text content;

7. List (list) Answer: 1) Display a set of text options on the screen; 2) Allow users to select or multi-selection; 3) Construction Method List () List (int Rows, Boolean Multiplemodel)

8. TextField Answer: 1) Provide a single line of editing text 2) Textfield () TextField (int columns) TextField (String Text, int columns)

9. TextArea Answer: 1) Provide multi-column editable text area; TEXTAREA (String Text) Textarea (String Text, Int Rows, Int Cols) Textarea (String Text, Int Rows, Int Cols, Int Scrollbars) 10. Dialog (Dialog) A: 1) A free window with title and border 2) Acknowledged layout manager is borderLayout; 3) must have a caller; 4) can be mode and non-mode.

11. File dialog (File Dialog) Answer: 1) Mode dialog; 2) to select a file;

12. Scroll PANe Answer: 1) A container class; 2) can be scrolled automatically or vertically for a single component;

13. MenuBar A: 1) A menu bar component is a horizontal menu that can only be added to a frame and become the root of all menu trees. 2) Set the menu strip with the setmenubar () method of the frame;

14. Menu Answer: 1) The main function is to load menu items; 2) Inherit from the Menuitem class, so it can load other menus;

15. MenuItem Answer: 1) The menu item component is a text "leaf" node of the menu tree. They are usually added to the menu to form a complete menu; 2) usually add an ActionListener to a menu In the object to provide the behavior of the menu.

16. PopupMenu Answer: 1) Provides a separate menu that can be displayed on any component; 2) You can add menu entry and menu to the pop-up menu.

AWT event model

1. What is an event? Answer: 1) Event source - Event generator; 2) Event - describes what the object happens; 3) Event processor - Receive events, interpret events, and process user interactions;

2. Event Source Answer: 1) The event source is a result of an event; 2) Provisioning method allows other methods to increase or remove event processors; example: Click on the mouse on the Button component to generate an ActionEvent from this button This ActionEvent instance is an object that contains an object of information about the event that happens.

3. Event Processor Answer: 1) The event processor is a method of receiving events, interpreting events and handling user interaction.

4. Event Type A: 1) For each type of event, there is an interface, this interface must be implemented by an object of the class you want to receive this event. This interface also requires defining one or more methods. These methods are called when a specific event occurs.

5. ActionEvent Answer: 1) Double-click the list item; 2) The button is selected; 3) The menu item is selected; 4) The text field carries.

6. TextEvent A: Applicable two line text domain synchronization

7. ItemEvent Answer: 1) Multi-Selection Box is selected or canceled; 2) Optional menu selection or cancel; 3) The drop-down list item is selected; 4) List item selection.

8. Event adapter A: 1) Event adapter Air implements all methods of an event processor; 2) You only need to inherit and rewrite the method you are interested in

Tuesday, 2004-8-31 Tuesday

Java basic class

1. JFC preview: 1) Java basic class is a complete collection of GUI components and services, which greatly simplifies the development and implementation of robust Java applications; 2) Part of the Java base class is swing, swing is building in AWT Collection of some components of the upper layer; 3) The Java base class mainly contains 5 APIs: a. AWT: Provides a variety of GUI tools for all kinds of Java applications; b. Java2d: a graphic API provides a Java application Set of advanced classes related to 2D graphic image; C. Accessibility API: Provides an advanced tool to assist in developing applications using non-traditional inputs and outputs. D. DRAG & DROP: Provides interoperability between Java and local applications to exchange data between Java applications and applications that do not support Java technology. E. Swing: The key points of the JFC module are used to develop a window-based application development, which provides a rich set of components and work frames to specify how the GUI shows its visual effects independently of the platform. 2. Swing Introduction Answer: 1) It is constructed around the API to achieve the API of the AWT; 2) Most components are not intended to be implemented with the platform like AWT.

3. Import Swing Processes Answer: 1) Import Swing Package; 2) Select the appearance and feel (3) Set the window container a. JFrame is similar to the frame; b. You can't directly add the component directly to JFrame; c A Content Pane contains all Frame visual components except the menu

4. JComponent Category: 1) All swings are implemented as a subclass of JComponent; 2) Swing components inherit the following features from JComponent: a. Border (SetBorder () method Specifies the border displayed around the component, EmptyBorder instance Specifies that a component has a certain amount of additional space around it); b. Double buffer (can improve the appearance of a frequently changed component, the default is double buffer); c. Prompt box (by using the settooltiptext () method to specify A string, providing users with help information about a component) D. Keyboard navigation E. Application range of plug-in appearance and feelings

Java applet

1. What is applet? A: 1) Applet is an Java class that can be embedded in an HTML page and can be downloaded and executed through a web browser; 2) Applet runs through the browser or Applet Viewers;

2. APPLET Safety Restriction A: 1) Perform another program at runtime; 2) Input / output of any file; 3) Call local method; 4) Try to open any system of any system other than the host that provides an applet.

3. APPLET and AWT Answer: java.lang.object | | java.awt.component | | java.awt.panel | | java.applet.applet

4. Applet method and application lifecycle answer: 1) init () a. This is called only when the applet is loaded first, and the completion before calling start (); b. Can be used for initialization data values; 2) start () A. When the applet is visible 3) stop () a. Run 5. Applet tag: 1) code = appletfile.class is given file name containing compiled Applet subclasses ; 2) width = Pixels Height = Pixels gives the initial width and height of the Applet display area; 3) CodeBase = codeBaseURL Specifies the URL of the applet (including the applet code, if this property is not specified, use the URL of the document 4) Align = alignment Specifies an alignment of Applet 5) Provides parameters 6. APPLET and browser interaction method Answer: 1) getParameter (String name): Number of parameters; 2) GetCodeBase (): Returns a URL object that describes the Applet class file itself; 3) getDocumentBase (): Returns a URL object that describes the HTML file loaded by the applet;

2004-9-1 Wednesday rain

Thread

1. What is thread? Answer: 1) A thread is a single continuous control; 2) A software can handle a series of thread constructs; 3) Threads can run at the same time, independent of each other; 4) Package is java.lang.thread;

2. Makeups for threads or contexts: 1) A virtual processor; 2) Code code executed by the CPU may or cannot be shared by multiple threads, which is independent. Two threads If you perform instance code of the same class, they can share the same code. 3) The data data of the code operation can or cannot be shared by multiple threads, which is independent. Two threads share access to a common object, they can share the same data.

3. Thread mechanism Answer: 1) When the thread starts, the code is executed; 2) Two methods of creating a thread: a. Inherit the Thread class; b. Implement the Runnable interface.

4. Create a thread by inheriting the Thread class: 1) Define public class mythread extends thread {public void run () {...}} 2) Initialization Mythread Testthread = new mythread ()

5. By implementing the interface to create a runnable thread A: 1) define the public class MyRunnable implements Runnable {public void run () {...}} 2) Initialization MyRunnable testRunnable = new MyRunnable (); Thread testThread = new Thread (testRunnable)

6. Comparative Answer for two types: 1) Inheriting the Thread class is object-oriented programming; 2) Implementing the runnable interface solves the single inheritance

7. Thread Scheduling Answer: 1) The thread is preemptive, but it is not necessarily a time; 2) There are multiple threads to run, but only one thread is actually run. 3) All running threads are saved in the pool according to priority, and when a blocked thread becomes running, it will be placed in the corresponding shipping pool, the thread in the highest priority non-empty pool get the processor time. 4) Sleep () call gives a chance to run lower priority threads, and Yield () methods will only give an opportunity to perform the same priority thread. 8. Basic Answers of Threads: 1) Starting Thread: Using the start () method, this means that the thread can schedule and execute by JVM, and does not mean that the thread will be executed immediately. 2) Termination of a thread: When a thread ends running and terminates, it cannot run again. 3) Test a thread: isalive () method is used to determine if a thread is still live. The living thread does not mean that the thread is running. 4) Delay thread: SLEEP (): Stop threads for a while, after interval, threads do not necessarily resume execution immediately. Join (): Hangs the current thread until the thread it calls.

9. SYNCHRONIZED keyword: 1) Identify a set of variables should be used exclusively by a thread; 2) Public void push (char c) {synchronized (this) {...}} public synchronized void push (char c) { ...} 3) All access to fragile data should be synchronized, and fragile data protected by Synchronized should be private.

10. Thread interactions: 1) WAIT (): Treas for the lock and CPU; 2) Notify (): Remove an arbitrary thread from the object's waiting pool and put it in the lock pool, there are objects there Always waiting until the lock mark of the object can be obtained. 3) NotifyAll (): Remove all threads waiting for that object from the waiting pool and put it in the locked pool, only the thread in the lock pool can get the object's lock mark, the lock mark allows the thread to call Wait from last time ( The interrupted place will continue to operate.

2004-9-2 Thursday Yin

Flow I / O and file

1. Flow and basic knowledge A: 1) A stream is the source or purpose of the byte 2) The two basic streams are: input streams and output streams 2. InputStream Method Answer: 1) Three basic read () methods A INT read (): a byte or -1; b. int in (byte []): read the data into the byte array and returns the number of bytes read; c. Int Read (Byte [], int, int, and Int): The two int parameters specify the sub-range of the array to be filled. 2) Other methods a. Void Close (): Close the stream, such as using a filter stream, shutting down the stream on the top of the stack, closing the rest of the stream. B. Int available (): Returns the number of bytes that can be read from the stream. C. SKIP (long): Discard the specified number of characters in the stream.

2. OutputStream Method Answer: 1) Three basic read () methods a. Void write (): b. Void write (byte []): c. Void write (byte [], int, int, int): write output flow . 2) Other methods a. Void Close (): Close the stream, such as using a filter stream, shutting down the stream on the top of the stack, closing the rest of the stream. B. Int flush (): Allows you to force a write operation. 3. FileInputStream and FileOutputStream Answer: 1) Node stream uses disk files. 2) To construct a fileInputStream, the associated file must exist and readable. 3) To construct a fileOutputStream and the output file already exists, it will be overwritten. FileInputStream Infile = New FileInputStream ("myfile.dat"); FileOutputStream outfile = new fileoutputstream ("results.dat");

4. BufferInputStream and BufferOutputStream A: Filter stream, can increase the efficiency of I / O operation

5. DataInputStream and DataStream A: Read and write Java base classes through the stream, pay attention to the method of DataInputStream and DataOutputStream.

6. PipedInputStream and PipedOutputStream Answer: Used to communicate between threads.

7. Reader and Writer Answers: 1) Java technology uses Unicode to represent strings and characters and provide 16-bit version of stream to process characters in a similar way. 2) InputStreamReader and OutputStreamWriter are interfaces in the word current and character streams. 3) If a Conversion rule is switched between byte coding and Unicode defined using the default platform.

8. Documentation A: 1) A file object can represent a file or directory; File (String Parent, String Child); D. File (URI URI) 4) Directory Separation File.seParetor 9. Random Access File A: 1) Implemented two interfaces: DataInput and DataOutput; 2) As long as the file can be opened You can read and write; 3) You can read and write files through file pointers; 4) Access to all read () and write () operations in DataInputStream and DataOutputStream; 5) Movement in the file: a. Long getfilepointer () : Returns the current location of the file pointer. B. Void Seek (Long POS): Sets the file pointer to a given absolute position. C. Long length (): Returns the length of the file.

10. Serialization Answer: 1) Store an object to a permanent memory called a stay; 2) Only the data of the object is serially connected; 3) The data marked as the Transient keyword is not serialized.

2004-9-3 Friday

1. Socket Answer: 1) Endpoints between the inter-process communication links under a specific programming model. 2) A Socket includes two streams: one input stream (reads data written in another process) and an output stream (sending data to another process).

2. Network Answer in Java: 1) Connected address (Host Name or IP Address); 2) Port number (range from 0-65535, less than 1024) to predefined services);

3. Network model in Java: A: 1) The server assigns a port number. If the customer requests a connection, the server uses the accept () method to open the socket connection; 2) Customer establish a connection at Host's Port port; 3) Server and customers Communication is performed using InputStream and OutputStream.

4. A server established: 1) ServerSocket server = new ServerSocket (post) 2) Socket connection = server.accept (); 3) ObjectInputStream input = new ObjectInputStream (connection.getInputStream ()); ObjectOutputStream output = new ObjectOutputStream (connection .getOutputStream ()); 4) Processing input and output flow; 5) Close the stream and socket.

5. A client established: 1) Socket connection = new Socket (127.0.0.1, 7777); 2) ObjectInputStream input = new ObjectInputStream (connection.getInputStream ()); ObjectOutputStream output = new ObjectOutputStream (connection.getOutputStream ()); 3) Processing input and output flow; 4) Close the stream and socket.

6. URL Connection: 1) URL and URLConnection classes encapsulate a large number of complex operations from remote server access information; 2) Support HTTP and FTP resource URL URL = New URL ("http://www.enterinfo.net" ) URL URL = New URL ("ftp: //tonydeng@enterInfo.net") 3) Open a network connection URLConnection urlconn = url.openconnection () Open an input stream InputStream in = url.openStream ()

7. UDP Socket Answer: 1) Unconnected Protocol 2) Unaffected Message Reliable Transfer 3) Supported by DataGramsocket and DataGRampacket class in Java technology

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

New Post(0)