您的位置:首页 > 编程语言 > Java开发

java se web向需要的资料整理1

2012-01-17 20:37 190 查看
首先,j2se 建议用editplus来写(因为本身不会很难)

1.思想:封装继承多态

单纯从简单的角度来说:封装就是getset的爪哇豆子。。//口胡的。。其实是用java语言编写的可重用的软件组件

(私有成员变量,private int age; public get()/set())

  继承:下面helloworld里的class C,Base,父节点,基(父)类

  多态:子类实例化后把实例化的对象交给父类操控(类似)或者交给接口来传递值。

  EG:Father f = new Son();←class Son extends Father

2.8个基本数据类型,.java文件命名规则

基本类型:byte short int long float double boolean char

     .java文件命名规则 _$+英文开头

3.hello world(加强版)



interface B{

// this is a interface
public void bbb();
}
class C{

//// this is a BaseA
public void use(String s){
if(s.equals("Hello world"))
System.out.println("yeah,I'm java.Greeting to you");
}
}
public class A extends C implements B{

// We can use constructor to Say start
public A(){
System.out.print("This is a Start.");
System.out.println("");
}
// We should implement bbb method
public void bbb(){
this.use("Hello world");
}
public static void main(String args[]){
new A().bbb();
}
}


3. new instance(很多名词基于英文讲比较实在,渣英文如有错误,请各位看官指出谢谢。。)

     As we all known,java is a object-oriented language.So if you want to use class,you should instantiate it.eg:helloworld.java--new A()

     But this isn't which we want to do.If class A() has another method.new A().ccc()??

     terrible...So the normal new instance is to give it a handle(a);

     eg: A a = new A(); a.bbb(); a.ccc();

     So helloworld.java main method is modified to:

public static void main(String args[]){

//new instance
A a = new A();
a.bbb();
}
                          

             注:本身想用多态但懒(拖走。。)。。。。

             顺便。其实把A改成B就可以了。。。。(打死。。)

4.constructor method,override(overwriting and overloading,this and super)

  member method and constructor method's difference.

  member method has a return object.constructor not.

  member:If you want to use, you should handle.method

  constructor:new class(),it will start to run.

  eg:

class A{
public A(){
System.out.println("This is constructor");
}
public void aa(){
System.out.println("This is Member method");
}
public static void main(String args[]){
new A();
System.out.println("=====================");
new A().aa();
}
}


    override:

      1.overwriting

             baseClass B has method aa()

             extendClass A has method aa()

             we use aa() is Class A not Class B.(normal)

       2.overloading

              Class A has two or more constructor,like aa(),aa(String s) etc.

     eg:

class BaseA{
public void AA(){
System.out.println("AA");
}
}
class A extends BaseA{
public A(){
System.out.println("overloading with no Parameter");
}
public A(String s){
System.out.println("overloading with String");
}
public void AAA(){
super.AA();
System.out.println("=================");
System.out.println("this is overwriting AAA");
this.AA();
}
public void AA(){
System.out.println("this is overwriting AA");
}
public static void main(String args[]){
new A();// overloading with no Parameter
System.out.println("===================");
new A("AA");// overloading with String
System.out.println("===================");
new A().AAA();
/* overloading with no Parameter
* AA
* =================
* this is overwriting AAA
* this is overwriting AA
*/
System.out.println("===================");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息