分享
 
 
 

SCJP知识点总结

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

封装、重写、重载

l 代码的高效率并不是封装的优点。

l 实现一个接口的类和接口是is a 的关系。

l 子类重写父类方法的时候,方法返回值的类型一定相同,否则编译不通过。

l 如果子类实现多态时,若只是方法的返回值不同,将在第二个及以后的方法编译出错。

l 如果实现多态时,方法的参数是f(int ,int)和f(long , int);那么f(1,2)将执行f(int , int)。

l 子类中如果调用super( )或this( )则必须在方法的第一行,且不能同时出现。

内部类

l static inner classes:

只有最上层的类可以有,并且它只能访问static 变量

l member inner classes:

要创建它的实例,必须有一个指向上层的引用,它不能含有static方法。

l local inner classes:

只有被声明为final的本地变量(不是上层)才可以直接访问,local and anonymous 内部类不能被声明为private、public、protected or static。

l anonymous inner classes:

匿名类不能含有构造函数。

注:在内部类中,this 指的是内部类的实例,要得到enclosing class 的实例,要在前面加前缀。

线程

l 创建、初始化、开始新线程

线程可以通过继承Thread 和重写public void run( )来加以创建

也可以通过有Runnable 对象参数的构造方法来实现。

Start( )方法只能调用一否会抛出RunnableException, (ThreadStateException)

Thread 类实现了Runnable

l 线程的状态的转换

runnable->running->dead

wait( )和sleep( )可使线程waiting

waiting->runnable

一个线程dead后不能start again

Object 定义了wait( )、notify( )、notifyAll()等方法。

Notify() is to sigmal that it should proceed in executing instructions.

Interrupted() and interrupt() are instance methods of Thread.

Sleep( ) and yield( ) are static methods of Thread.

l 使线程sleep

sleep( )可以使线程停止执行一段时间,但锁没解开。

Interrupt( )可以停止sleep( )和waiting( )

处于I/O阻塞状态或在等待锁的线程不能被Interrupt( )

sleep( )方法必须有try,catch,或被throws

l 通过waiting 和 notifying 进行通信

注意用synchronized

l 死锁、yield( )

l 只有run( )方法在Runnable interface 中被定义。

The java.lang.Math

Using the java.lang.Math Class

l The abs() method is overloaded to take an int ,a long ,a float ,or a double.

l The abs() method can return a negative if the argument is the minimum int or long value equal to the value of Integer.MIN_VALUE or Long.MIN_VALUE, respectively.

l The max() method is overloaded to take int,long,float,double arguments.

l The min() method is overloaded to take int,long,float,double arguments.

l The random() method returns a double greater than or equal to 0.0 and less than 1.0.

l Random does not take any arguments.

l The methods ceil(), floor(), round() all return integer equivalent doubles.

l The round() method is overloaded to take a float(the other method takes a double). Math.round( 9.5) = 10

l The method sin( ), cos( ),and tan() take a double angle in radians.

l The method sqrt() can return NaN if the argument is NaN or less than zero. Static double sqrt(double)

Strings

Creating and Working with Strings in java

l String operations are carried out by String class, which can be found in the java.lang package.

l Strings can be concatenated with the following syntax:

String s = new String(<>);

l “ + ” and toString( )

Storage of Strings and String immutability

l In java, strings are immutable. Their contents can never be changed.

l Text for strings defined at compile time and strings with identical contents may share the same memory space.

Constructors and Methods for the String Class

l None of the methods for the String class change the actual contends of the string; they only return new values.

l The equals() method is used to compare two strings and determine whether they are identical. The == operator should not be used, as it will only determine whether the two string variables reference the same object.

l The indexOf( ) and lastIndexOf() methods of the String class can be used to search a string’s contents for a specific character or sequence of characters.

Using the StringBuffer Class

l Their contents can be changed.

l StringBuffers are initialized with a certain character capacity. If this capacity is extended, the StringBuffer object automatically grows.

Constructors and Methods for the StringBuffer Class

l The setCharAt() , insert() , delete(), and append() methods are used to work with individual characters and string of characters in StringBuffers.

l All positional arguments for methods in the String or StringBuffer classes are zero-based. The first charater is reference as zero.

The java.util Package

The Collection Framework

l The four properties that differentiate collections are

sorted,ordered,allows duplicates,and uses keys.

l In strict terminology ,a set cannot be both ordered and sorted.

l An ordered set keeps track of the sequence in which objects are added to it. It is unsorted, however.

l A sorted set uses the natural ordering of its objects, such as alphabetical.

Collection Interfaces and Classes

l A Set can store only unique objects, not duplicates.

l A List keeps the objects indexed in a definite order.

l A Map stores objects in ascending to keys.

l SortedSet stores objects in ascending order without duplicates.

l The null object can’t be used to sort objects, so a SortedSet can’t contain objects that are null. Likewise, a SortedMap can’t contain keys that are null.

l HashSet implements the Set Interface.

l LinkedList ,vector, and ArrayList implement List.

l HashMap and Hashtable implement the Map interface.

l TreeMap implements the SortedMap interface.

The java.awt Package

Components

l The java.awt.Component class is the abstract superclass for all nonmenu graphical components in java.awt package.

l A custom component can be created by extending an existing component subclass or by extending the java.awt.Component class directly.

Containers

A container is a type if component that contains other components.

A container is itself a subclass of component,so it is possible to nest containers within one another.

Layout Managers

A container uses a layout manager to position the components that it contains. It is specified using the Container.setLayout() method.

The layout manager for a container determines the size and position of each component within a container.

If no layout manager is specified for a container then absolute positioning is used to determine each component’s position.

Menus

MenuComponent is at the top of the hierarchy for all menu subclasses.MenuComponent does not inherit from Component.

A MenuBar must be associated with a Frame in order to visible.That is accomplished using the Frame.setMenuBar() method.

A MenuBar can have Menu objects added to it using the add() method.

Menus can have MenuItems and all subclasses of MenuItem added to it using the add() method.Menu is a subclass of MenuItem,so a Menu can be added to another Menu.

Painting

The Canvas class is used by creating a subclass of Canvas, then overriding the paint() method.

All Components have a paint() method.

To ask the GUI to refresh a component, the repaint() menthod can be called. There is no guarantee it will be refreshed right away.

Images,text and shapes can be rendered to a Canvas or any Component using the Graphics object associated with the paint() method.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有