Java console

1) system.console() returns console object 

2) readLine and readPassword() are two methods for input. readLine() returns a string whereas readPassword() returns a charecter array.

Serialization :

1) serialization stores the state of the object.

2) cannot add transient objects to serializable.

3) Object inputstream and outputstream are used to serialize and store the values. 

ObjectInputStream.readObject();

ObjectOutputStream.writeObject();

4) FileOutputStream and FileInputStream are wrapped in ObjectInputStream and ObjectOutputStream respectively.

5) Object class should implement serializable marker interface. (means serializable interface dont have any methods to implement)

6) When you save an object java serialzation will take care of saving the entire object graph. ie it stores the state of all the 

objects that are present in the current object.

7) All the objects that are instatantiated in serializable object should also be serializable other wise jvm will through 

java.NotSerializableException.

8) Transcient variables are not serialized.

9) If the superclass of serializable objects are not serializable then all the variables inherited from the superclass will be initialized 

to their original values.(ie only the instances that are declared on the serializable object are stored and all the other

variables are initiazed using the super() constructor)

10) Static variables are not stored as a part of serialization. As static variables belongs to class rather than the object.



Date,Numbers, Currencies

1) Available classes -

1) java.util.Date - 

2) java.util.Calendar - Additon of days , (operations on date object)

3) java.text.DateFormat - Specifies formats like (dd/yy/mm)

4) java.text.NumberFormat - Format numbers and currencies.

5) java.util.locale - Format dates and curriences to their respective locals.

2)Date - stores time irrespective of time zones.

setTime and getTime are available methods.

3) Calendar - Abstract class

1) Calendar c = Calendar.getInstance();

2) c.setTime(Date)

3) c.add(Calendar.Month, addValue) //Add integer months to the given date.

4) c.roll(Calendar.Month,addValue) // The difference between roll and add is roll adds only particular subfield(like month etc)

5) c.getTime() - returns Date object.

4) DateFormat - Another abstract class 

1) DateFormat df = DateFormat.getDateInstance();

2) df.format(Date);

3) df.parse(df.toString()) - retunrs date object;

throws parseException to be caught or thrown.


5) Locale - 

1) Two constructors - new Locale(language), new Locale(lang, country)

2) LocaleObject.getDisplayCountry() - Displays Local country

3) LocaleObject.getDisplayLanguage() - Displays Locale Language



6) NumberFormat - Abstract Class

1) NumberFormat.getInstance()

2) NumberFormat.getCurrencyInstance(Locale);

3) NumberFormat.get/setMaximumFractionDigits(int);

4) NumberFormat.setParseIntegersOnly(boolean);



Parsing, tokenizing and Formatting.

 javax.util.regex.Pattern, javax.util.regex.Matcher, javax.util.regex.Scanner,String.split(), java.util.Format();



1) Regex is a language and we have to follow some syntax. 

Pattern p = Pattern.compile("expression") - creates a pattern

Matcher m = p.matches(text) - results are stored in matcher.

m.find() - return true when any matches are found.

m.group() - return the matched string.

2) Regex engine starts from left to right and once a source charecter is in match, it cannot be reused.

3) Search using metacharecters

1) \d - digit

2) \s - white space

3) \w - word/digit/Underscore(_)

4) [abcABC] - search should include only these 6 charecters

5) [a-f] - search should include only a-f charecters



4) Search using quantifiers

1) 0[xX][0-9a-fA-f] - searches 3 digit hexadecimal numbers

2) + one or more

3) [] - exactly one occurance

4) ([])+ - one or more occurances.

5) * - zero or more occurances

6) ? - zero or one occurance

7) .(dot) - any charecter can serve here

5) Greedy Quantifiers (Reads the entire the text and then comes back towards right and include the string)

1) ?? zero or one

2) *? zero or more

3) +? one or more

6) Search using Scanner Class

1) Scanner s = new Scanner(System.in);

7) String.split(); 

takes delimiters and spilts the string.

String[] tokens = ActualString.split(",");

8) Scanner methods to split data.

scanner.hasNext()

scanner.hasNextBoolean()

scanner.hasNextInteger();

scanner.hasNextXxx() and Scanner.nextXxx();

9) java.io.printStream 

- printf() and format()

%[arg_index$][flags][width][.precision]conversion char

1) flags 

- - left justify

+ - include + and -ve

0 - pad elements with 0

, - use local locale

( - enclose negative numbers with paranthesis

2) width - the numbers of charecteres you want to display

3) precision - How many digits to be displayed after decmical point

* equals() method will always return true if both the objects are of same literal and contains the same value.

* To be read again - NumberFormat, Scanner



ALL about SCJP = SCJP 1.6, mock, certification, scjp 1.5 , scjp questions, scjp books, scjp hand written notes, scjp dumps, scjp trainings, scjp video tutorials, scjp simulators etc.