Download presentation
Presentation is loading. Please wait.
Published byFerdinand Beasley Modified over 9 years ago
2
No move to Java 7 until end of this year IT deploy Java 7 everywhere BE/CO remove it again! So don’t rely on it being installed on a console ‘free’ support for Java 1.6 stops this summer Have to pay afterwards We can’t specify 1.7 in our JNLP files a JaWS would need internet access to download 1.7 JRE Many other new features, but I’ll outline what was interesting for me…
3
Just like primitive switch() switch (dayOfWeekArg) { case "Monday": … Java compiler generates generally more efficient bytecode from switch statements that use String objects than from chained if-then- else statements
4
int toto4 = 5_______2; Why? Readability! Not everywhere though 3_.1415 <- Not next to a decimal point 999_99_9999_L <- Not next to F or L suffix 52_ <- Not at the end of a literal 0_x45 <- Can’t separate 0x! Rule is that if it doesn’t make it more readable, it’s invalid!
5
Now we can have literals expressed in binary 0b or 0B prefix (like 0x/0X for hex) 0b00110001 This can make bit patterns much easier to understand than using hexadecimal for example Same rules for 64 bits apply as decimal 0b10100001010001011010000101000101101000010100 01011010000101000101L
6
Typing reduced Map > myMap = new HashMap >(); …becomes… Map > myMap = new HashMap<>(); Compiler knows what it’s expecting so infers it automatically!
7
Often several exceptions are thrown from a single call to a method Java 7 allows you to ‘OR’ the exceptions in the catch statement try{…}catch (IOException|SQLException ex) { } Also, you can promote a class to a subclass in the throws declaration Void toto(String s) throws AEx, BEx { try { //... } catch (Exception e) { throw e; } } The compiler checks that e is indeed of type Aex or Bex This is really useful when catching many exceptions (generically) and rethrowing them with more inclusive type checking
8
You can now ‘monitor’ files or directories Can be used as a handy inter-process- communication mechanism Used in FESA 3 Navigator (using 3 rd party library at the moment) ‘notify me when a new file appears in a directory’ Uses native system calls (ReadDirectoryChangesW / iNotify on Windows / Linux) On other platforms falls back to polling
9
Very poor info prior to Java 7 Metadata (size, owner, creation time, etc) Also isSymbolicLink(Path)isSymbolicLink(Path) ?etPosixFilePermissions(Path, LinkOption...) ?etPosixFilePermissions(Path, LinkOption...) … + a lot more attributes depending on file system (windows, posix etc) Can now give much better error messages when something goes wrong with a file access Previously you just got ‘false’ when trying to do many file operations! File systems info as well
10
Previously it was very cumbersome to intialise Lists/Sets/Maps etc. Inialising Lists List list = ["item"]; Accessing Lists String item = list[0]; Initializing Sets Set set = {"item"}; Maps… Map map = {"key" : 1}; int value = map["key"]; Etc… Result is much less code and typing!
11
We should take care not to use any new features in Java 7 if we intend to use in CCC We _could_ use from our terminal servers Main benefits are for IO (Sockets, NIO.2 not in detail here) But lots of nice language modifications Less typing! We now wait for CO!
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.