`
Odysseus_110
  • 浏览: 120349 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

SCJP 5.0 Study Notes(1)

    博客分类:
  • J2SE
F# 
阅读更多

Note:   Please feel free to modify, improve, circulate, and repost these notes at will.   Dave Allen

 

Collections Framework (only Maps, Iterators do not extend java.io.Collection Interface)

Collection interface

add(E)

addAll (Collection<e>)

remove(Object)

removeAll ( Collection<?>)

contains(Object)

size()

iterator ()

isEmpty ()

Object[] toArray () – returns Object array, must cast – e.g. String[] str = (String[]) myCollection.toArray ();

T[] toArry (T[] a) – returns typecast array – syntax: String[] str = myCollection.toArray (new String[0]);

Map interface,

SortedMap interface extends Map

put(keyObject , valueObject ) – inserts key/value pair, will overwrite duplicate keyObject values

keySet () – returns set of keys

values() – returns collection of values

get(Object), remove(Object), size(), clear()

entrySet () – returns set of Map.Entry type (key/value pair)

Map.Entry – a key/value pair, has getKey () and getValue () methods

 

Maps care about unique identifiers

There is no add() method; Don’t have to override equals(Object) method to compile, but necessary to find objects

HashMap

 

Hashtable

synchronized version of HashMap

TreeMap

Can have null values, but NO null keys

LinkedHashMap (extends Hashmap )

maintains insertion order, slower updates, faster iteration than HashMap , order remains same if replacing duplicate key, can have null keys or values

Set interface, SortedSet interface extends Set

boolean add() – if element already exists, returns false and element not added

Sets care about uniqueness

HashSet

 

LinkedHashSet (extends HashSet )

fastest iteration through items without duplicates (a Set) that maintains insertion order

TreeSet <T>

new TreeSet (), new TreeSet (Collection<E>), new TreeSet <T>(Comparator<? super E>)

List interface

Lists care about the index

ArrayList

fastest iteration through items with duplicates

Vector

synchronized version of ArrayList ; slower

LinkedList

addFirst (), getFirst ()

 

doubly linked, ideal for implementing a stack or maintaining an ordered sequence of objects when they are frequently inserted and removed from the middle of the sequence

Queu interface

peek() – returns highest priority entry without removing it

poll() – returns highest priority entry and removes it

offer() – adds entry

PriorityQue

 

Collections

Collections.sort (Collection)

Collections.sort (Collection, Comparator)

Collections.binarySearch (collectionName , pattern) – must be sorted first

Collections.binarySearch (collectionName , pattern, Comparator) – must be sorted first

Collections.reverse () – reverses order of elements in List, doesn’t have to be sorted first

Collections.reverserOrder () – returns Comparator that sorts in reverse, must b sorted first

Arrays

Arrays.sort (arrayToSort )

Arrays.binarySearch (arrayName , pattern), Arrays.binarySearch (collectionName , pattern, Comparator) – returns int index

Arrays.asList (arrayName ) – returns List, changes to either returned list or original array will be reflected in the other

Comparable interface

int compareT o (SpecificObject Type )

returns     negative int if this < Obj2

                0 if Objects are equal

                positive int if this > Obj2

Comparator class

int compare(SpecificObject Type1, SpecificObject Type2) – returns int with same meaning as above – substitute “SpecificObjectType1” for “this”

Iterator

boolean hasNext ()

next() – returns type Object which must be cast if no generic type is specified for iterator , even if Collection that called iterator () method has generics, like List<Integer>

 

Can use generics syntax to avoid explicit casting, e.g. Iterator <Dog> = dogs.iterator ();

 

 


Dates

java.util.Date

new Date() – date Object with current date

new Date(long millis ) – millis since Jan 1, 1970

 

getTime () – returns long

setTime (long millis )

 

internally stored as primitive long which is milliseconds between date and Jan 1, 1970

Calendar

Calendar.getInstance () – gets default Calendar (almost always GregorianCalendar ) with current time

Calendar.getInstance (Locale)

 

add( intField , intAmount ) – adds or decrements field.  intAmount can be negative

roll(intField , intAmount ) – larger parts of date will not be incremented/decremented, only the field specified

set(intField , intValue )

get(intField ) – e.g. calendarInstance.get (Calendar.MONTH );

set() – various other set methods

setTime (Date)

getTime () – returns Date object, useful for passing to DateFormat

setTimeInMillis (long millis )

getTimeInMillis () – returns long

compareTo (Calendar)

 

NO new Calendar(), only instantiated using getInstance (), months are 0-based (January is 0)

java.text .

NumberFormat

NumberFormat.getInstance (), NumberFormat.getInstance (Locale) – e.g. NumberFormat.getInstance (Locale.US );

NumberFormat.getNumberInstace ( ), NumberFormat.getNumberInstanceLocale () – same as getInstance ()?

NumberFormat.getCurrencyInstance (), NumberFormat.getCurrencyInstance (Locale)

 

format(long), format(double) – takes various numbers to be formatted, returns String

parse(String) – takes a String (must be formatted correctly to locale), returns a Number – e.g. parse(“$5,075”);

setParseIntegerOnly ( boolean ) – whether to format and display digits after decimal.

getMaximumFractionDigits (), getMinimumFractionDigits – get number of decimal places

setMaximumFractionDigits (int), setMinimumFractionDigits – set number of decimal places

get/setMinimum/MaximumIntegerDigits ()

 

Should only instantiated using getInstance ()

java.text . DateFormat

getInstance () – returns DateFormat with default Locale, sometimes SHORT style

getDateInstance () (has defaults, sometimes MEDIUM style),getDateInstance (styleConstant ), getDateInstance (styleConstant , Locale)

parse(String) – converts String to a Date

format(Date) – returns String with formatted Date

 

String format for each style

possible default format – 0/8/01 7:46 PM

DateFormat.SHORT   9/8/01

DateFormat.MEDIUM – Sep 8, 2001

DateFormat.LONG – September 8, 2001

DateFormat.FULL – Saturday, September 8, 2001

 

There is no format( Calendar) method.  Calendar must convert to Date first(using yourCalendar.getTime ()), then use format(Date)

DateFormat’s Locale can only be set at instantiation using getInstance () – NO new DateFormat ()

java.util.Locale

Locale.getDefault () – returns default Locale

new Locale(stringLanguage )

new Locale(stringLanguage , stringCountry ) – e.g. new Locale(“it”, “IT”)

 

setDefault (Locale)

getDisplayLanguage () – returns String of Language

getDisplayLanguage (Locale) – displays language using language of Locale passed in

getDisplayCountry () – returns String code

getDisplayCountry (Locale) – displays language using language of Locale passed in)

Locale.getAvailableLocales () – returns an array of Locales installed

 

used in Scanner, DateFormat , NumberFormat

 


String Stuff

String

new String(), new String(StringBuilder /Buffer)

new String(“StringLiteral ”)

new String(ExistingStringObject ) will create a new String object different than ExistingStringObject

 

length()

charAt (int)

concat (String)

equalsIgnoreCase (String)

substring(intIndex )

substring(startIntIndex , endIntIndexExclusive )

replace(char/stringRegex , char/stringReplacement )

replaceAll (char/stringRegex , char/stringReplacement )

replaceFirst (stringRegex , stringReplacement )

split(regex ) – returns String array of tokens, good for just small amount of data

split(regex , IntLengthOfArrayReturned )

toLowerCase ()

toUpperCase ()

trim() – remove whitespace off ends

toString () – returns a new String object

 

indexOf (char/String)

indexOf (char/String, startingIntIndex )

lastIndex (char/String, startingIntIndex )

lastIndex (char/String, startingIntIndex )

contains(charSequence )

matches(regex ) – returns boolean indicating if regex matches string

boolean startsWith (String)

boolean startsWith (String, offsetIndex )

String format(“formattingString ”, args ) – returns String formatted to specs

String format(Locale, “formattingString ”, args )

 

All methods return a String, do no alter original String

NO insert() method (this is in StringBuilder/StringBuffer )

NO length member variable (this is for array)

StringBuilder / StringBuffer

append(xxx) – can append almost any char related type

delete(intStartIndex , intEndIndexExclusive )

deleteCharAt ()

insert(intOffset , String)

reverse()

toString ()

length()

substring(startIndexInclusive )

substring(startIndex , endIndexProbablyExclusive )

 

lastIndexOf (String)

lastIndexOf (String, startSearchIndex )

replace(intStart , intEnd , String)

setCharAt ()

 

StringBuffer is synchronized and slower.

StringBuilder is not synchronized and faster

equals() method is not overridden, so it compares references, not meaningful values – same as ==

java.util .

Scanner

new Scanner(File), new Scanner(stringToSearchOrTokenize )

 

useDelimiter (String) – can be regex

useLocal (Locale)

hasNext (), hasNextInt (), hasNextFloat (), hasNextXxx () – for all primitives EXCEPT char

next(), nextInt (), nextFloat (), nextXxx – for all primitives EXCEPT char

Scanner.close () – static method that should be used after done with file

findInLine (regexString ) – returns String found

 

match() – returns MatchResult

matchResult.groupCount () – method in MatchResult (not Scanner)

matchResult.group (groupCountIndexInt ) – method in MatchResult (not Scanner)

 

Mostly used for tokenizing, but can also find regexes using findInLine ()

Default delimiter is whitespace

java.util.regex .

Pattern

Pattern.compile (regex ) – returns new Pattern

matcher(CharSequence ) – returns new Matcher

split(regex ) – returns String array of matching patterns found in the CharSequence

Pattern.matches (regex , stringtoSearch ) – returns Boolean indicating if string matches regex

 

/d             digits

/s             whitespace

/w            word character (letters, digits, or underscores)

  [af ]         a or f

  [a-f]        a, b, c, d, e, f

  [a-dA -D]                A,a,B,b,C,c,D,d

.               any character

+              greedy one or more (e.g. /d+ means one or more digits)

*              greedy zero or more (e.g. filename/d*)

?              greedy zero or more occurrences(e.g. /d?)

^              not (e.g. [^abc ] excludes abc )

 

String pattern = “\\d” creates string regex with \d.  String pattern = “\\.” creates string regex with .

java.util.regex .

Matcher

find() – returns boolean indicating a match’s existence, advances to next index that matches, left to right

start() – returns starting index

group() – returns string that matches

 

Probably Not on Exam

replaceAll (stringReplacement )

replaceFirst (stringReplacement )

appendReplacement (StringBuffer , stringReplacement ) --

appendTail (StringBuffer ) – to be used after appendReplacement

java.util .

Formatter

new Formatter(), new Formatter(Appendable , Locale) – Appendable can be StringBuilder/StringBuffer ,

BufferedWriter , FileWriter , but NOT String

 

format(“formattingString ”, args ) – returns formatted String

 

Serialization (package java.io , classes must implement Serializable to be serialized)

FileOutputStream

new FileOutputStream (stringFileName )

new FileOutputStream (File)

ObjectOutputStream

defaultWriteObject ()

writeObject (Object)

writeInt (int), writeFloat (float), writeXxx (xxx)

FileInputStream

new FileInputStream (stringFileName )

new FileInputStream (File)

ObjectInputStream

defaultReadObject ()

readObject () – returns Object, must be cast before use

readInt (), readFloat (), readXxx ()

 

 转自

<!---->     <!---->

分享到:
评论

相关推荐

    SCJP 5.0考试模拟机

    SCJP(Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0)是Java编程领域的一个重要认证,由Sun Microsystems(后被Oracle收购)推出,旨在验证开发者对Java SE 5.0平台的基础知识和编程...

    SCJP5.0真题题库

    SCJP(Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0)是Oracle公司推出的针对Java SE 5.0平台的程序员认证考试。这个题库是为准备SCJP 5.0考试的考生提供的资源,包含了大量实战题目,...

    SCJP5.0(310-055)LatesDump.rar_scjp

    【SCJP5.0(310-055)LatesDump.rar_scjp】这个压缩包文件主要包含的是关于Sun Certified Java Programmer(SCJP)5.0考试的最新模拟试题和复习资料。SCJP,也被称为Java SE Certified Programmer,是Oracle认证的一项...

    绝对值得收藏的scjp5.0考试模拟器(免安装,实用,经典)

    最经典的scjp5.0考试模拟器(免安装,实用,经典) 绝对值得收藏!

    Whizlabs SCJP 5.0

    1. SCJP50.exe:这很可能是Whizlabs SCJP 5.0学习软件的安装程序。用户可以运行这个.exe文件来在本地计算机上安装课程内容,包括模拟测试、学习材料等。 2. SCJP50-patch.exe:这个文件可能是针对SCJP50.exe的更新或...

    scjp 5.0(310-055)认证指南

    SCJP(Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0)是Java编程领域的一个重要认证,旨在验证开发者对于Java SE 5.0平台的基础知识和编程能力。这个认证对于那些希望深入理解Java语言...

    SCJP5.0 310-055 认证题库 09年版本

    SCJP(Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0)是Oracle公司为Java程序员提供的一项专业认证,旨在验证考生对Java SE 5.0编程语言的掌握程度。310-055是这个认证的考试代码,对应...

    SCJP5.0全套资料(个人心血笔记&2套题库)

    SCJP(Sun Certified Java Programmer)5.0是Java编程领域的一个重要认证,它验证了开发者对Java SE 5.0平台的基本理解与编程能力。这个认证对于那些希望深入理解Java语言特性和准备进入IT行业的专业人士来说,是...

    SCJP5.0模拟器

    SCJP(Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0)是Oracle公司(原Sun Microsystems)为Java开发者设立的一项认证考试,旨在验证考生对于Java SE 5.0编程语言的理解和应用能力。...

    SCJP5.0 java考试资料5.0版

    scjp考试辅导,包含各个要点,与真实考题相近

    SCJP5.0(Sun Certified Programmer for the Java 2 )

    Java SCJP(Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0)是Java开发者认证的一个重要里程碑,由Sun Microsystems(后被Oracle收购)推出,旨在验证程序员对Java SE 5.0(也称为Java ...

    scjp5.0

    scjp最新版,对于考scjp有很大帮助,

    SCJP5 study guaid

    《SCJP5 Study Guide》是Java程序员为了通过Sun Certified Programmer for Java 5 (SCJP5)认证考试的重要参考资料。SCJP是Java开发人员基础技能的一种官方认可,它验证了开发者对Java语言核心概念的理解和应用能力。...

    SCJP模拟器及考题

    这个认证曾经基于Java SE 5.0(即SCJP 5.0),而现在已被更新的OCPJP(Oracle Certified Professional, Java Programmer)所替代,尽管如此,SCJP 5.0仍然是学习Java基础知识的重要参考。 提供的资源包括"SCJP5.0....

    SCJP模拟器+JDK5.0+复习资料

    1. **类型注解**:JDK 5.0引入了类型注解,使得编译器和工具能够理解代码中的元数据,这为泛型、枚举、自动装箱/拆箱等提供了支持。 2. **泛型**:泛型允许在类、接口和方法中使用类型参数,提高了代码的类型安全性...

    scjp真题

    文件"310-055_Certkiller.pdf"和"310-055-Q&A-Troytec.pdf"很可能包含了针对SCJP 5.0考试的模拟试题和答案解析。310-055是SCJP 5.0考试的代码,Certkiller和Troytec可能是提供这些资源的培训机构或个人。 SCJP 5.0...

    SCJP考试资料(包含大部分原题)

    在提供的压缩包文件中,"scjp 5.0(310-055)认证指南.chm"很可能是一个包含SCJP 5.0考试复习资料的离线帮助文档。这类文档通常会详细介绍考试大纲,提供练习题,并解释各种Java编程概念。考生可以通过阅读此文档来...

    Java程序员5.0升级版本简介

    - **考试内容**:SCJP 5.0认证考试代码为CX-310-055,考试形式为多选题和拖放题,旨在测试考生对Java语言核心概念的理解以及J2SE 5.0的应用能力。 - **考试准备**: - 参加有教员指导的培训课程(如SL-275:Java...

    scjp(jdk5.0)认证

    ### SCJP (JDK 5.0) 认证知识点解析 #### 题目一:接口中的变量声明 **题目描述**: 考虑以下代码片段: ```java public interface Status { /* insert code here */ int MY_VALUE = 10; } ``` 在第12行插入哪些...

Global site tag (gtag.js) - Google Analytics