Going Further with the Java Language

Contents

  • Autoboxing
  • Varargs
  • Type-safe enumerations
  • Static imports

baseType… paramName ellipsis denotes an arbitrary varargs and Overloading void myMethod(int a,int b){} void myMethod(short… val){}

enums are implicitly final subclasses of java.lang.Enum equals().tostring(),ordinal()

Complex Enum

Static Import

some classes contain a lot of static members > kitchen sink

Try with Resources

``` try(resource1,resource2,resource3){

} catch(IOException e1, Exception e2) //close() methods called here, with inversed order

## Generic classes

class CyclicList{ private ArrayList elements; private int currentPosition; priate int maxElements; }

### using wildcards
>Java SE 7 allows you to omit type information when you invoke a constructor

# console class

java.oi.console class printf() writer() flush(): force buffered content to be written now reader() ```

String objects are immutable

this enables the JVM to optimize memory usage but it can impair performance if you do a lot of string handling

formatter class

Formatter formatter = new Formatter(sb, Locale.UK) formatter.format(Locale.FRANCE,’Here is a big number: %.4f\n’,1234.12341)

Regular Expression Syntax

\. matches the literal

File Handling

Writer: Abstract class

printWriter: high-level class,wirtes the whole lines of text to a stream

bufferedWriter: Buffers output characters to a stream, for effiency

OutputStreamWriter: low level class, writes bytes to a stream

FileWriter: writes characters to a file

Reflaction

  • Recap of classes : type.class Inner class outerType$InnerType.class