1.java缺点
- 大量使用内存
- 学习曲线比较曲折,但是幸好不是最难的
- 缓慢的启动时间
2.java知名的程序
- 游戏沙盘游戏,我的世界
- 淘宝网后端就是用java来开发的
- 安卓操作系统就是用java来开发的
3.java标识符命名方式
必须以字母,_,或者$开头命名
4.整数类型byte(-128~127)在使用来自网络或文件的数据流时非常有用
5.infinity指的是无穷大!
6.使用指定的命名来通过break操作(退出outer)
public class Main { public static void main(String args[]) { outer: for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (j + 1 < i) { System.out.println(); break outer; } System.out.print(" " + (i * j)); } } System.out.println(); } }
7.java类访问控制
访问说明符是pravite,public,potected和默认访问级别
8.私有pravite
class Test { int a; // default access public int b; // public access private int c; // private access // methods to access c void setc(int i) { c = i; } int getc() { return c; } } public class Main { public static void main(String args[]) { Test ob = new Test(); ob.a = 1; ob.b = 2; // This is not OK and will cause an error // ob.c = 100; // Error! // You must access c through its methods ob.setc(100); // OK System.out.println("a, b, and c: " + ob.a + " " + ob.b + " " + ob.getc()); } }
就是当产生一个类的实例时,该实例只能改变公共函数或者变量,若想改变私有变量则需通过调用公共的函数来改变。
protected可作为本类与继承类调用
9.成员类
成员类的实例方法可以调用实例方法封闭类和访问封闭类实例的非静态字段
class EnclosingClass { private int outerVariable; private void privateOuterMethod() { System.out.println(outerVariable); } class EnclosedClass { void accessEnclosingClass() { outerVariable = 1; privateOuterMethod(); } } } public class Main { public static void main(String[] args) { EnclosingClass ec = new EnclosingClass(); ec.new EnclosedClass().accessEnclosingClass(); // Output: 1 } }
10.内部类成员只能在内部类中访问(当前类),并且可能不被外部类使用。如果您尝试编译以下代码,您将收到错误消息。
public class Main { int outer_x = 100; // this is an inner class class Inner { int y = 10; // y is local to Inner void display() { System.out.println("display: outer_x = " + outer_x); } } void showy() { System.out.println(y); } }
如图将会报错因为outer_x不是当前类变量
11.abstract修饰类
1,abstract修饰类,会使这个类成为一个抽象类,这个类将不能生成对象实例,可以做为对象变量声明的类型,也就是编译时类型,抽象类就像当于一类的半成品,需要子类继承并覆盖其中的抽象方法。
2,abstract修饰方法,会使这个方法变成抽象方法,声明(定义)而没有实现,实现部分以";"代替。需要子类继承实现(覆盖)。
3.abstract修饰符在修饰类时必须放在类名前。
4.abstract修饰方法就是要求其子类覆盖(实现)这个方法。调用时可以以多态方式调用子类覆盖(实现)后的方法,也就是说抽象方法必须在其子类中实现,除非子类本身也是抽象类。
5.父类是抽象类,有抽象方法,子类继承父类,并把父类中的所有抽象方法都实现(覆盖),抽象类中有构造方法,是子类在构造子类对象时需要调用的父类(抽象类)的构造方法。
12.super
一个超类,他是直接调用父类里面得方法或者是变量。
只能放在构造函数是的第一条语句。
this()调用当前形参的构造方法,super()调用当前父类的无参构造方法,super(m,n)调用父类相同形参的构造方法