当前位置:文档之家› Java学习笔记(必看经典)_New - 共33页

Java学习笔记(必看经典)_New - 共33页

Java学习笔记(必看经典)_New - 共33页
Java学习笔记(必看经典)_New - 共33页

JAVA --------

EVERYTHING IS OBJECT

OOP

class Student{

New

null

public int/void addNumber( ) throw Excepion {}

public int addNumber(int a,int b){

}

int a,int b

public

Student s=new Student()

Student Student “Student()”

()

Student s

Student

public student(string name,int a){

}

public student(int a,string name){

}

static void changename(student stu){stu.setName “LUCY”}

overloading overriding

JAVA overriding overloading

Overloading

overloading

overloading

overloading

public void teach(){};

public void teach(int a){};

public void teach(String a){}

Overloading

Byte—short—float—int—long—double

this

student(){};

student(string n){

this();// student()

}

student(int a) this(int a)

this this

This

Public void printNum(){

Int number=40

System.out.println(this.number);

}

This.number

this.number (this) number

Public

Private

private set get

this

this

11.29

SuperClass SonClass

Class Son extends Father{

}

JAVA

JAVA JAVA

overriding

overloading

public private

private

default

Protected

Public

Super() this

This()

super()

Animal a=new Dog()

Dog d=(Dog)a

Animal a=new Dog() Animal dog

Dog d=(Dog)a Dog()

instanceof

a instanceof Animal;( )

Animal

Animal true false a instanceof Animal True

a instanceof Dog True

instanceof

Instanceof

Animal a=new Animal()

Dog d=Dog()a;

Animal a=new Dog()

Animal a=getAnimal()

Public static Animal.getAnimal;

Return new Dog()

Overloading

shape circle rect

Shape zhouchang() area()

squ rect rect cha()

private public

11.29 Module6

Module6-7

static:

Static int data data

Int data

static int data;

m1.data=0;

m1.data++ 1, m2.data

Static

Public static void printData(){}

This.data

static

Static Singleton

Singleton 11.30

final

final final final

final

JAVA final JAVA

Final int AGE=10

Final static

Static final int age=10

JAVA public static final

final

Final int x=3

final

Public final void print(){}

final

final

private static final private static final

final private default protected public

Abstract(

abstract

Abstract

Final abstract

abstract

private void print(){}

Abstract void print()

abstract

Abstract static static abstract

\CODING\abstract\TestClass.java

public class TestClass{

public static void main(String[] args){

SuperClass sc=new SubClass();

Sc.print();

}

Abstract class SuperClass{

Abstract void print();}

}

class SubClass extends SuperClass(){

void print(){

System.out.println(“print”);}

}

JAVA interface

:

interface IA{

public interface

public

public public

class IAImple implements IA{

};

public public

public

class IAImpl extends java.util.Arrylist implement IA{}

Implements IA,IB

interface IC extends IA,IB{};

IA I=new IAImpl();

IAImple extends A implement IA,IB

IB I=new IAImple();

I instance of IAImple;

I instance of A;

I instance of IA;

I instance of IB;

true.

JAVA

XX

JAVA JDBC

JAVA Object JAVA

Object:

(1)finalize

(2)toString():

toString()

toString() toString()

toString()

(3)equal

String A=new String(“hello”);

String A=new String(“hello”);

A==B( FALSE)

AB

JAVA String final JAVA VM String a=”hello” NEW ”hello” ”hello” ”hello” String b=”hello” “hello”

String a=”hello”;

System.out.println(a==”hello”);

true

equal: System.out.println(a.equal(b));

equal

a.equal(b)

student a=new student(“LUCY”,20);

student b=new student(“LUCY”,20);

System.out.println(a.equal(b));

false

equal ture false

public boolean equals(Object o){

student s=(student)o;

if (https://www.doczj.com/doc/329262714.html,.equals(https://www.doczj.com/doc/329262714.html,)&&s.age==this.age)

else return false;

equals()

equals

public boolean equals(Object o){

if (this==o) return trun; //

if (o==null) return false;

if (! o instanceof strudent) return false; //

studeng s=(student)o; //

if (https://www.doczj.com/doc/329262714.html,.equals(https://www.doczj.com/doc/329262714.html,)&&s.age==this.age) return true;

else return false;

}

equals

employee String name,int id,double salary. get set toString equals

JAVA Object int char

int I=10;

String s=I+” ”;

String s1=String.valueOf(i);

Int I=10;

Interger I_class=new integer(I);

javadoc

“==”

JDK JDK JDK

double\interger\string

12.01

PROTECTED PRIVATE PUBLIC DEFAULT

this.

.this.

PRIVATE

private

outer inner outer.class outer$inner.class

TestOuter.java class.

out.inner.

inner s=new inner(); inner

new

Outer.Inner in=Outer.new.Inner()

Outer.Inner in=new Outer.Inner()

Outer private

public private

final

static

new

Outer.Inner in=new Outer.Inner()

private

People

{

run();

}

Machine{

run();

}

robot

class Robot extends People implement Machine.

run()

IA

IA I=new IA(){};

new

Out$1.class

Exception MODEL7

JAVA Throwable

Throwable Error Exception

Error

Error Throwable Exception

Exception Runtime exception

Runtime exception

Exception

throw

throws try

JDK throw

public void print() throws Exception.

throws Exception

throw new Exception() JAVA

try……catch

try { } catch(exception e){ }

exception exception exception catch

Try try catch try

try catch try catch catch exception excepiton JAVA

try catch finally finally

exception

try catch

API

Exception message catch

Catch(IOException e){System.out.println(e.message())};

Catch(IOException e){e.printStackTrace()};

try try

throw( try catch

try catch

excepiton RuntimeException Throw

throws Throws

assert

assert

Assert assert

throws throws try catch

int add(int a,int b)

{

return a+b

}

a+b=100; 100

12.02

API

java.util.* NEW

JAVA1.5 JAVA1.4

collection map

Collection Map

List Set SortedMap

SortedSet

JAVA

Collection

List List

Set List

SortedSet

Map Key-Value Key-Value key value key value

key1—value1;

key2—value2;

key3—value3.

SortedMap Map key SortedMap

List ArrayList LinkedList

ArrayList ArrayList ArrayList

ArrayList add(Object o)

ArrayList

import java.util.*

ArrayList

ArrayList

List get size Set

Collection Iterator() Set List

Iterator it=c.iterator(); interator Interator hasNext() True next Next()

Collections static

Sort List

Collections.Sort()

Sort

https://www.doczj.com/doc/329262714.html,ng Comparable

comparableTo(Object o)

int

>o >0

=o =0

TestArraylist java

-1

java.util Comparator( )

compare()

Sort Sort List,List(Compate)

comparTo() implement comparable.

EMPLOYEE ArrayList Iterator

JAVA1.5

LinkedList ArrayList

ArrayList object ArrayList

LinkedList

LinkedList

ArrayList LinkedList

LinkedList

LinkedList ArrayList

addFirst();

removeFirst();

addLast();

removeLast();

push pop

Push addFirst() pop removeFirst()

isEmpty()--

put get

Put addFirst() get removeLast()

List Vector ArrayList Vector

Vector

ArrayList

java.util.stack stack Vector stack Vector Vector Vector get

push get

Stack

LinkedList

JAVA1.5 collection queue

Set-HashSet

HashSet

Object final() toString() equals() hashCode()

HashSet

add(Object o) hashCode

int hc=o.hashCode(); hashCode

Int I=hc%n; I=0 a[0] I=1, a[1] equals() true equals() false hashCode

hashcode equals()

student hashcode

String String string

JDK hashCode

hashSet hashcode() equals() hashcode equals() True

equals() hashCode equals()

hashCode hashCode hashCode

public int hashCode(){

return name.hashcode()+age;

}

hashCode

hashSet

hashSet hashCode hashSet

hashSet HashSet

hashSet

new hashset employee

Student S

Al.add(s);

s.setName(“lucy”);

s2

12.05

SortedSet

SortedSet TreeSet: TreeSet

TreeSet

HashSet TreeSet HashCode() equals()

compareable compareTo()

HashSet CompareTo()

Set Map key value

ArrayList HashSet HashMap ArrayList HashMap

HashMap put() get()

Map keySet() set keySet() key put() value

Set s=m.keySet();

Interator it=new interator();

Object key=it.next();

Object value=m.get(key);

HashMap HashCode Sort

HashMap key value

Key

m.put(new sutdent(“Liucy”,30),”boss”)

Student

key HashCode() equals()

HashMap HashSet HashMap HashSet HashMap API HashSet (key.null) HashMap key value

TreeSet TreeMap

TreeSet TreeMap

——

相关主题
文本预览
相关文档 最新文档