Java se6 comprehensive learning Summary

Source: Internet
Author: User

1st ~ Chapter 6

1. Two Java Applet running methods

Package CH2;

Import java. AWT .*;

// This is a sample of a Java Applet. It shows two ways to run a Java Applet directly, and to run it in HTML code.
Public class sayhello extends java. Applet. Applet
{
Public void Init ()
{
Setsize (100,100 );
}

Public void paint (Graphics g)
{
G. drawstring ("Hello Java 2! ", 20, 50 );
}
}

Run Java sayhello. Java directly or in HTML: appletviewer sayhello. Java

2. usage of the break and continue with tags:

Package ch6;

// Loop usage, including break and continue. You can try to remove the loop and then use break and continue. The effect is different.
Public class mark
{
Public static void main (string argv [])
{
Int I, J;
Loop1:
For (I = 1; I <= 5; I ++)
{
Loop2:
For (j = 1; j <= 5; j ++)
{
If (j = 3)
Break loop2; // jump out of the loop2 Loop

If (I = J)
Continue loop1; // continue the next round of loop1 Loop

System. Out. println (I + "*" + J + "=" + I * j );
}
}
}
}

7th ~ Chapter 8

1. class type conversion in the class family. Notes about method calling after conversion!

2. Super (), this () calls the parent class constructor and its own constructors, rules

3. overload, masking (attribute), and rewriting (method)

4. Interface precautions: Mark the concept and usage of the interface

Public class prog8_5
{
Public static void main (string argv [])
{
Tank tank = new tank ();
Fighter fighter = new fighter ();
/* The type is tank, and both methods can be called. If car tank = new tank ();
Tank can only call the car Reid method to move */
Tank. Move ();
Tank. Shoot ();
Fighter. Move ();
Fighter. Shoot ();
}
}

Public class prog8_6
{
Public static void main (string argv [])
{
Weapon tank = new tank (); // The interface can also be used as a type to declare an object !!!
Weapon fighter = new fighter ();

Tank. Shoot (); // only methods in this interface can be called !!!

Fighter. Shoot ();
}
}

Difference !!!

Chapter 2 Common Object Methods

1. type conversion of the class. The sibling type cannot be converted. conversion to the parent class does not work in conversion to the sibling type !!! One is a compilation error and the other is a runtime error.

No matter how you turn around, what kind of class is an object, it will always be the object of that class.

Question about calling methods and attributes during the conversion process? ,,?

2. Determine whether the object contains the same content. For your own class, you need to rewrite the equals method. For example:

Public class myobject
{
Public int data;

Public myobject (int I)
{
Data = I;
}

Public Boolean equals (Object OBJ)
{
If (OBJ! = NULL & (OBJ instanceof myobject ))
If (this. Data = (myobject) OBJ). Data)
Return true;

Return false;
}
}

3. hash code

Two identical objects (with the same content but not the same references) have the same hash code. Hash is used in the equals method to obtain its wrapper hash code. Therefore, when you rewrite equals, The hashcode must also be rewritten.

Package ch9.equals;

Public class myobject implements cloneable
{
Public int data;

Public myobject (int I)
{
Data = I;
}

Public Boolean equals (Object OBJ)
{
If (OBJ! = NULL & (OBJ instanceof myobject ))
If (this. Data = (myobject) OBJ). Data)
Return true;

Return false;
}

Public int hashcode ()
{
Return (New INTEGER (data). hashcode ());
}

Public object clone ()
{
Try
{
Return super. Clone ();
}
Catch (clonenotsupportedexception E)
{
System. Out. println (E );
Return NULL;
}
}
}

Package ch9.equals;

Public class prog9_6
{
Public static void main (string argv [])
{
Myobject obj1 = new myobject (1 );
Myobject obj2 = new myobject (1 );
Myobject obj3 = new myobject (3 );
// 1, 2hashcode is equal
System. Out. println ("obj1's hash code:" + obj1.hashcode ());
System. Out. println ("obj2's hash code:" + obj2.hashcode ());
System. Out. println ("obj3's hash code:" + obj3.hashcode ());
}
}

The above also contains the object clone method !!!

Chapter 10 deep memory

1. Use of Java. util. arrays API

Tostring and deeptostring, deepequals, and sort. Search for binarysearch

2. Pass the parameter. Only the value is passed! Object Reference is actually a value transfer.

3. Garbage Collection

Finalize is a method called by GC before the object is recycled. You can use it to do something and check whether the object has been recycled. Print Information or something

Chapter 2 internal classes

Members are internal classes: class level and object level.

Difference !!!

public class InnerClasses{private static String staticAttribute = "Outter class' static attribute";private String instantiateAttribute = "Outter class' instantiate attribute";public void instantiateMethod(){System.out.println("Outter class' intantiate method");}public static void staticMethod(){System.out.println("Outter class' static method");}public static class StaticInnerClass{public StaticInnerClass(){System.out.println("static Inner class");}public void access(){System.out.println(staticAttribute);staticMethod();}}public class InstantiateInnerClass{public InstantiateInnerClass(){System.out.println("Instantiate Inner class");}public void access(){System.out.println(instantiateAttribute);instantiateMethod();}}}
public class InnerClassExample1{public static void main(String argv[]){InnerClasses.StaticInnerClass in;in = new InnerClasses.StaticInnerClass();in.access();}}
public class InnerClassExample2{public static void main(String argv[]){InnerClasses out = new InnerClasses();InnerClasses.InstantiateInnerClass in;in = out.new InstantiateInnerClass();in.access();}}

The two types of members are internal class access methods!

Regional internal class

Anonymous internal class!

Chapter 19 and 20 deep character string processing for packaging

Omitted

Chapter 4 File Processing thread

Previously written

The principle of data stream connection! Filter stream system. Important

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.