SlideShare ist ein Scribd-Unternehmen logo
1 von 36
Downloaden Sie, um offline zu lesen
Java	
  5	
  &	
  6	
  Features	
  

            Jussi	
  Pohjolainen	
  
Tampere	
  University	
  of	
  Applied	
  Sciences	
  
Versions	
  and	
  Naming	
  
•    JDK	
  1.0	
  –	
  1996	
  	
  
•    JDK	
  1.1	
  –	
  1997	
  –	
  JDBC,	
  RMI,	
  ReflecQon..	
  
•    J2SE	
  1.2	
  –	
  1998	
  –	
  Swing,	
  CollecQons..	
  
•    J2SE	
  1.3	
  -­‐	
  2000	
  –	
  HotSpot	
  JVM..	
  
•    J2SE	
  1.4	
  –	
  2002	
  –	
  assert,	
  NIO,	
  Web	
  start..	
  
•    J2SE	
  5.0	
  (1.5)	
  –	
  2004	
  –	
  Generics,	
  Autoboxing..	
  
•    Java	
  SE	
  6	
  (1.6)	
  –	
  2006	
  –	
  Rhino,	
  JDBC	
  4.0	
  …	
  
•    Java	
  SE	
  7	
  (1.7)	
  –	
  2011	
  –	
  Small	
  language	
  changes,	
  
     API	
  Changes	
  
New	
  Features	
  
•  Java	
  SE	
  5	
  
     –  Generics	
  
     –  Autoboxing	
  
     –  Improved	
  looping	
  syntax	
  
     –  AnnotaQons	
  
     –  …	
  
•  Java	
  SE	
  6	
  
     –  XML	
  Processing	
  and	
  Web	
  Services	
  
     –  ScripQng	
  
     –  JDBC	
  4.0	
  
     –  Desktop	
  APIs	
  
     –  …	
  
     	
  
Generics	
  
ArrayList list = new ArrayList();
list.add("a");
list.add("b");
list.add(new Integer(22));

Iterator i = list.iterator();

while(i.hasNext()) {
    System.out.println((String) i.next());
}
Result	
  
Using	
  Generics	
  
ArrayList<String> list = new ArrayList<String>();
list.add("a");
list.add("b");
list.add(new Integer(22));

Iterator<String> i = list.iterator();

while(i.hasNext()) {
    System.out.println((String) i.next());
}
Result	
  
Enhanced	
  for	
  -­‐	
  loop	
  
ArrayList<String> list = new ArrayList<String>();
list.add("a");
list.add("b");
list.add("c");

// Loop array or collection. Iteration used
// even without declaration! The list object
// must implement java.lang.Iterable interface
for(String alphabet : list) {
    System.out.println(alphabet);
}
Java	
  1.4	
  
import java.util.*;

class Main {
    public static void main(String [] args) {
        // Does not work, 5 is not a Object type!
        someMethod(5);
    }

    public static void someMethod(Object a) {
        System.out.println(a.toString());
    }
}
Java	
  1.4:	
  SoluQon	
  
import java.util.*;

class Main {
    public static void main(String [] args) {
         Integer temp = new Integer(5);
         someMethod(temp);
    }

    public static void someMethod(Object a) {
        System.out.println(a.toString());
    }
}
Java	
  1.4:	
  Lot	
  of	
  Coding	
  
Integer a = new Integer(5);
Integer b = new Integer(6);
int aPrimitive = a.intValue();
Int bPrimitive = b.intValue();
Autoboxing	
  Comes	
  to	
  Rescue!	
  
class Main {
    public static void main(String [] args) {
        // Boxing
        Integer a = 2;

        // UnBoxing
        int s = 5 + a;
    }
}
Java	
  1.5	
  
class Main {
    public static void main(String [] args) {
        // Works!
        someMethod(5);
    }

    public static void someMethod(Object a) {
        System.out.println(a.toString());
    }
}
Java	
  1.5	
  
import java.util.*;

class Main {
    public static void main(String [] args) {
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.add(5);
        list.add(new Integer(6));
        list.add(7);

        for(int number : list) {
            System.out.println(number);
        }
    }
}
Enum	
  
•  An	
  enum	
  type	
  is	
  a	
  type	
  whose	
  fields	
  consist	
  of	
  
      a	
  fixed	
  set	
  of	
  constants	
  
	
  
enum Color {
     WHITE, BLACK, RED, YELLOW, BLUE;
}
Usage	
  
enum Color {
    WHITE, BLACK, RED, YELLOW, BLUE;
}

class Main {
    public static void main(String [] args) {
        System.out.println(Color.WHITE);

        Color c1 = Color.RED;
        System.out.println(c1);
}
Enum	
  
•  Enum	
  declaraQon	
  defines	
  a	
  class!	
  
•  Enum	
  can	
  include	
  methods	
  
•  Enum	
  constants	
  are	
  final	
  staQc	
  
•  Compiler	
  adds	
  special	
  methods	
  like	
  values	
  
   that	
  returns	
  an	
  array	
  containing	
  all	
  the	
  values	
  
   of	
  the	
  enum.	
  
•  Enum	
  class	
  extends	
  java.lang.enum	
  
Enum	
  
enum Color {
      WHITE, BLACK, RED, YELLOW, BLUE;
}

class Main {
    public static void main(String [] args) {
        for (Color c : Color.values()) {
             System.out.println(c);
        }
    }
}
StaQc	
  Import	
  (1/2)	
  
class Main {
    public static void main(String [] args) {
        int x = Integer.parseInt("55");
        int y = Integer.parseInt("56");
        int x = Integer.parseInt("57");
    }
}
StaQc	
  Import	
  (2/2)	
  
import static java.lang.Integer.parseInt;

class Main {
    public static void main(String [] args) {
        int x = parseInt("55");
        int y = parseInt("56");
        int z = parseInt("57");
    }
}
Metadata	
  
•  With	
  Java	
  5	
  it’s	
  possible	
  to	
  add	
  metadata	
  to	
  
   methods,	
  parameters,	
  fields,	
  variables..	
  
•  Metadata	
  is	
  given	
  by	
  using	
  annota,ons	
  
•  Many	
  annota.ons	
  replace	
  what	
  would	
  
   otherwise	
  have	
  been	
  comments	
  in	
  code.	
  
•  Java	
  5	
  has	
  built-­‐in	
  annotaQons	
  
Override:	
  Does	
  not	
  Compile!	
  
class Human {
    public void eat() {
        System.out.println("Eats food");
    }
}

class Programmer extends Human {
    @Override
    public void eatSomeTypo() {
        System.out.println("Eats pizza");
    }
}

class Main {
    public static void main(String [] args) {
        Programmer jack = new Programmer();
        jack.eat();
    }
}
Other	
  AnnotaQons	
  used	
  By	
  Compiler	
  
•  @Depricated	
  –	
  Gives	
  warning	
  if	
  when	
  
   depricated	
  method	
  or	
  class	
  is	
  used	
  
•  @SuppressWarnings	
  –	
  Suppress	
  all	
  warnings	
  
   that	
  would	
  normally	
  generate	
  
System.out.format	
  
import java.util.Date;

class Main {
    public static void main(String [] args) {
        Date d = new Date();
        // Lot of format characters available!
        System.out.format("Today is %TF", d);
    }
}
Variable	
  Argument	
  List	
  
class Main {
    public static void printGreeting(String... names) {
          for (String n : names) {
              System.out.println("Hello " + n + ". ");
          }
    }

    public static void main(String[] args) {
          String [] names = {"Jack", "Paul"};

          printGreeting("Jack", "Paul");
          printGreeting(names);
    }
}
User	
  Input:	
  Scanner	
  
Scanner in = new Scanner(System.in);
int a = in.nextInt();
Java	
  6:	
  XML	
  &	
  Web	
  Services	
  
•  Easy	
  way	
  of	
  creaQng	
  Web	
  Services	
  
•  Expose	
  web	
  service	
  with	
  a	
  simple	
  annotaQon	
  
	
  
	
  
Web	
  Service	
  
package hello;

import javax.jws.WebService;

@WebService

public class CircleFunctions {
    public double getArea(double r) {
        return java.lang.Math.PI * (r * r);
    }

    public double getCircumference(double r) {
        return 2 * java.lang.Math.PI * r;
    }
}
Server	
  
import javax.xml.ws.Endpoint;

class Publish {
    public static void main(String[] args) {

   Endpoint.publish(
            "http://localhost:8080/circlefunctions",
            new CircleFunctions());

    }
Generate	
  Stub	
  Files	
  
•  Generate	
  stub	
  files:	
  
   –  wsgen	
  –cp	
  .	
  hello.CircleFuncQons	
  
Java	
  6:	
  Rhino	
  
•  Framework	
  to	
  connect	
  to	
  Java	
  programs	
  to	
  
   scripQng-­‐language	
  interpreters.	
  
•  Rhino	
  JS	
  Engine	
  comes	
  with	
  Java	
  6	
  
•  To	
  ability	
  to	
  run	
  JS	
  from	
  Java	
  and	
  JS	
  from	
  
   command	
  line	
  
•  Rhino	
  is	
  wriken	
  in	
  Java	
  
Example	
  
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class Main {
    public static void main(String[] args) {
        ScriptEngineManager mgr = new ScriptEngineManager();
        ScriptEngine engine = mgr.getEngineByName("JavaScript");

        // Now we have a script engine instance that
        // can execute some JavaScript
        try {
            engine.eval("print('Hello')");
        } catch (ScriptException ex) {
            ex.printStackTrace();
        }
    }
}
Java	
  6:	
  GUI	
  
•    Faster	
  Splash	
  Screens	
  
•    System	
  tray	
  support	
  
•    Improved	
  Drag	
  and	
  Drop	
  
•    Improved	
  Layout	
  
•    WriQng	
  of	
  Gif	
  -­‐	
  files	
  
Java	
  6:	
  DB	
  Support	
  
•  Java	
  6	
  comes	
  with	
  preinstalled	
  relaQonal	
  
   database,	
  Oracle	
  release	
  of	
  Apache	
  Derby	
  
   Project	
  
•  Java	
  DB	
  is	
  installed	
  automaQcally	
  as	
  part	
  of	
  
   the	
  Java	
  SE	
  Development	
  Kit	
  (JDK).	
  
•  For	
  a	
  Java	
  DB	
  installaQon,	
  set	
  the	
  
   DERBY_HOME	
  environment	
  variable	
  
Java	
  7	
  
•      Using	
  Strings	
  in	
  switch	
  statements	
  
•      Syntax	
  for	
  automaQc	
  cleaning	
  of	
  streams	
  
•      Numeric	
  literals	
  with	
  underscores	
  
•      OR	
  in	
  excepQon	
  catches	
  
	
  

Weitere ähnliche Inhalte

Was ist angesagt?

Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Ganesh Samarthyam
 
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIModern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIGanesh Samarthyam
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeletonIram Ramrajkar
 
Functional Thinking - Programming with Lambdas in Java 8
Functional Thinking - Programming with Lambdas in Java 8Functional Thinking - Programming with Lambdas in Java 8
Functional Thinking - Programming with Lambdas in Java 8Ganesh Samarthyam
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghStuart Roebuck
 
Alternatives of JPA/Hibernate
Alternatives of JPA/HibernateAlternatives of JPA/Hibernate
Alternatives of JPA/HibernateSunghyouk Bae
 
Getting started with Java 9 modules
Getting started with Java 9 modulesGetting started with Java 9 modules
Getting started with Java 9 modulesRafael Winterhalter
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.Tarunsingh198
 

Was ist angesagt? (20)

Java 8 Feature Preview
Java 8 Feature PreviewJava 8 Feature Preview
Java 8 Feature Preview
 
Smart Migration to JDK 8
Smart Migration to JDK 8Smart Migration to JDK 8
Smart Migration to JDK 8
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams
 
Java 8 Features
Java 8 FeaturesJava 8 Features
Java 8 Features
 
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIModern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
Java concurrency questions and answers
Java concurrency questions and answers Java concurrency questions and answers
Java concurrency questions and answers
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeleton
 
Functional Thinking - Programming with Lambdas in Java 8
Functional Thinking - Programming with Lambdas in Java 8Functional Thinking - Programming with Lambdas in Java 8
Functional Thinking - Programming with Lambdas in Java 8
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
Java 8: the good parts!
Java 8: the good parts!Java 8: the good parts!
Java 8: the good parts!
 
Alternatives of JPA/Hibernate
Alternatives of JPA/HibernateAlternatives of JPA/Hibernate
Alternatives of JPA/Hibernate
 
Getting started with Java 9 modules
Getting started with Java 9 modulesGetting started with Java 9 modules
Getting started with Java 9 modules
 
Core Java - Quiz Questions - Bug Hunt
Core Java - Quiz Questions - Bug HuntCore Java - Quiz Questions - Bug Hunt
Core Java - Quiz Questions - Bug Hunt
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
Core java
Core javaCore java
Core java
 
Java Tut1
Java Tut1Java Tut1
Java Tut1
 
Sailing with Java 8 Streams
Sailing with Java 8 StreamsSailing with Java 8 Streams
Sailing with Java 8 Streams
 
Java Concurrency by Example
Java Concurrency by ExampleJava Concurrency by Example
Java Concurrency by Example
 

Ähnlich wie Java 5 and 6 New Features

Java Programs
Java ProgramsJava Programs
Java Programsvvpadhu
 
Basic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time APIBasic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time APIjagriti srivastava
 
Java Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECJava Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECSreedhar Chowdam
 
4java Basic Syntax
4java Basic Syntax4java Basic Syntax
4java Basic SyntaxAdil Jafri
 
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Ayes Chinmay
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)Chhom Karath
 
Testing basics for developers
Testing basics for developersTesting basics for developers
Testing basics for developersAnton Udovychenko
 
모던자바의 역습
모던자바의 역습모던자바의 역습
모던자바의 역습DoHyun Jung
 
JSUG - Tech Tips1 by Christoph Pickl
JSUG - Tech Tips1 by Christoph PicklJSUG - Tech Tips1 by Christoph Pickl
JSUG - Tech Tips1 by Christoph PicklChristoph Pickl
 
Lec 5 13_aug [compatibility mode]
Lec 5 13_aug [compatibility mode]Lec 5 13_aug [compatibility mode]
Lec 5 13_aug [compatibility mode]Palak Sanghani
 
DevNexus 2020: Discover Modern Java
DevNexus 2020: Discover Modern JavaDevNexus 2020: Discover Modern Java
DevNexus 2020: Discover Modern JavaHenri Tremblay
 

Ähnlich wie Java 5 and 6 New Features (20)

Java Programs
Java ProgramsJava Programs
Java Programs
 
Core java
Core javaCore java
Core java
 
Java Language fundamental
Java Language fundamentalJava Language fundamental
Java Language fundamental
 
Basic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time APIBasic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time API
 
Java Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECJava Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPREC
 
Java Notes
Java Notes Java Notes
Java Notes
 
Mastering Java ByteCode
Mastering Java ByteCodeMastering Java ByteCode
Mastering Java ByteCode
 
4java Basic Syntax
4java Basic Syntax4java Basic Syntax
4java Basic Syntax
 
What is new in Java 8
What is new in Java 8What is new in Java 8
What is new in Java 8
 
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
 
Testing basics for developers
Testing basics for developersTesting basics for developers
Testing basics for developers
 
Jvm a brief introduction
Jvm  a brief introductionJvm  a brief introduction
Jvm a brief introduction
 
Core java Essentials
Core java EssentialsCore java Essentials
Core java Essentials
 
모던자바의 역습
모던자바의 역습모던자바의 역습
모던자바의 역습
 
JSUG - Tech Tips1 by Christoph Pickl
JSUG - Tech Tips1 by Christoph PicklJSUG - Tech Tips1 by Christoph Pickl
JSUG - Tech Tips1 by Christoph Pickl
 
Lec 5 13_aug [compatibility mode]
Lec 5 13_aug [compatibility mode]Lec 5 13_aug [compatibility mode]
Lec 5 13_aug [compatibility mode]
 
Java ppt
Java pptJava ppt
Java ppt
 
DevNexus 2020: Discover Modern Java
DevNexus 2020: Discover Modern JavaDevNexus 2020: Discover Modern Java
DevNexus 2020: Discover Modern Java
 
java input & output statements
 java input & output statements java input & output statements
java input & output statements
 

Mehr von Jussi Pohjolainen

libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferencesJussi Pohjolainen
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationJussi Pohjolainen
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDXJussi Pohjolainen
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript DevelopmentJussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame AnimationJussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame AnimationJussi Pohjolainen
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDXJussi Pohjolainen
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDXJussi Pohjolainen
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesJussi Pohjolainen
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platformJussi Pohjolainen
 

Mehr von Jussi Pohjolainen (20)

Moved to Speakerdeck
Moved to SpeakerdeckMoved to Speakerdeck
Moved to Speakerdeck
 
Java Web Services
Java Web ServicesJava Web Services
Java Web Services
 
Box2D and libGDX
Box2D and libGDXBox2D and libGDX
Box2D and libGDX
 
libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and Preferences
 
libGDX: Tiled Maps
libGDX: Tiled MapslibGDX: Tiled Maps
libGDX: Tiled Maps
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame Animation
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDX
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
libGDX: Scene2D
libGDX: Scene2DlibGDX: Scene2D
libGDX: Scene2D
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: User Input
libGDX: User InputlibGDX: User Input
libGDX: User Input
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDX
 
Android Threading
Android ThreadingAndroid Threading
Android Threading
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platform
 
Intro to Asha UI
Intro to Asha UIIntro to Asha UI
Intro to Asha UI
 

Kürzlich hochgeladen

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 

Kürzlich hochgeladen (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

Java 5 and 6 New Features

  • 1. Java  5  &  6  Features   Jussi  Pohjolainen   Tampere  University  of  Applied  Sciences  
  • 2. Versions  and  Naming   •  JDK  1.0  –  1996     •  JDK  1.1  –  1997  –  JDBC,  RMI,  ReflecQon..   •  J2SE  1.2  –  1998  –  Swing,  CollecQons..   •  J2SE  1.3  -­‐  2000  –  HotSpot  JVM..   •  J2SE  1.4  –  2002  –  assert,  NIO,  Web  start..   •  J2SE  5.0  (1.5)  –  2004  –  Generics,  Autoboxing..   •  Java  SE  6  (1.6)  –  2006  –  Rhino,  JDBC  4.0  …   •  Java  SE  7  (1.7)  –  2011  –  Small  language  changes,   API  Changes  
  • 3. New  Features   •  Java  SE  5   –  Generics   –  Autoboxing   –  Improved  looping  syntax   –  AnnotaQons   –  …   •  Java  SE  6   –  XML  Processing  and  Web  Services   –  ScripQng   –  JDBC  4.0   –  Desktop  APIs   –  …    
  • 4. Generics   ArrayList list = new ArrayList(); list.add("a"); list.add("b"); list.add(new Integer(22)); Iterator i = list.iterator(); while(i.hasNext()) { System.out.println((String) i.next()); }
  • 6. Using  Generics   ArrayList<String> list = new ArrayList<String>(); list.add("a"); list.add("b"); list.add(new Integer(22)); Iterator<String> i = list.iterator(); while(i.hasNext()) { System.out.println((String) i.next()); }
  • 8. Enhanced  for  -­‐  loop   ArrayList<String> list = new ArrayList<String>(); list.add("a"); list.add("b"); list.add("c"); // Loop array or collection. Iteration used // even without declaration! The list object // must implement java.lang.Iterable interface for(String alphabet : list) { System.out.println(alphabet); }
  • 9. Java  1.4   import java.util.*; class Main { public static void main(String [] args) { // Does not work, 5 is not a Object type! someMethod(5); } public static void someMethod(Object a) { System.out.println(a.toString()); } }
  • 10. Java  1.4:  SoluQon   import java.util.*; class Main { public static void main(String [] args) { Integer temp = new Integer(5); someMethod(temp); } public static void someMethod(Object a) { System.out.println(a.toString()); } }
  • 11. Java  1.4:  Lot  of  Coding   Integer a = new Integer(5); Integer b = new Integer(6); int aPrimitive = a.intValue(); Int bPrimitive = b.intValue();
  • 12. Autoboxing  Comes  to  Rescue!   class Main { public static void main(String [] args) { // Boxing Integer a = 2; // UnBoxing int s = 5 + a; } }
  • 13. Java  1.5   class Main { public static void main(String [] args) { // Works! someMethod(5); } public static void someMethod(Object a) { System.out.println(a.toString()); } }
  • 14. Java  1.5   import java.util.*; class Main { public static void main(String [] args) { ArrayList<Integer> list = new ArrayList<Integer>(); list.add(5); list.add(new Integer(6)); list.add(7); for(int number : list) { System.out.println(number); } } }
  • 15. Enum   •  An  enum  type  is  a  type  whose  fields  consist  of   a  fixed  set  of  constants     enum Color { WHITE, BLACK, RED, YELLOW, BLUE; }
  • 16. Usage   enum Color { WHITE, BLACK, RED, YELLOW, BLUE; } class Main { public static void main(String [] args) { System.out.println(Color.WHITE); Color c1 = Color.RED; System.out.println(c1); }
  • 17. Enum   •  Enum  declaraQon  defines  a  class!   •  Enum  can  include  methods   •  Enum  constants  are  final  staQc   •  Compiler  adds  special  methods  like  values   that  returns  an  array  containing  all  the  values   of  the  enum.   •  Enum  class  extends  java.lang.enum  
  • 18. Enum   enum Color { WHITE, BLACK, RED, YELLOW, BLUE; } class Main { public static void main(String [] args) { for (Color c : Color.values()) { System.out.println(c); } } }
  • 19. StaQc  Import  (1/2)   class Main { public static void main(String [] args) { int x = Integer.parseInt("55"); int y = Integer.parseInt("56"); int x = Integer.parseInt("57"); } }
  • 20. StaQc  Import  (2/2)   import static java.lang.Integer.parseInt; class Main { public static void main(String [] args) { int x = parseInt("55"); int y = parseInt("56"); int z = parseInt("57"); } }
  • 21. Metadata   •  With  Java  5  it’s  possible  to  add  metadata  to   methods,  parameters,  fields,  variables..   •  Metadata  is  given  by  using  annota,ons   •  Many  annota.ons  replace  what  would   otherwise  have  been  comments  in  code.   •  Java  5  has  built-­‐in  annotaQons  
  • 22. Override:  Does  not  Compile!   class Human { public void eat() { System.out.println("Eats food"); } } class Programmer extends Human { @Override public void eatSomeTypo() { System.out.println("Eats pizza"); } } class Main { public static void main(String [] args) { Programmer jack = new Programmer(); jack.eat(); } }
  • 23. Other  AnnotaQons  used  By  Compiler   •  @Depricated  –  Gives  warning  if  when   depricated  method  or  class  is  used   •  @SuppressWarnings  –  Suppress  all  warnings   that  would  normally  generate  
  • 24. System.out.format   import java.util.Date; class Main { public static void main(String [] args) { Date d = new Date(); // Lot of format characters available! System.out.format("Today is %TF", d); } }
  • 25. Variable  Argument  List   class Main { public static void printGreeting(String... names) { for (String n : names) { System.out.println("Hello " + n + ". "); } } public static void main(String[] args) { String [] names = {"Jack", "Paul"}; printGreeting("Jack", "Paul"); printGreeting(names); } }
  • 26. User  Input:  Scanner   Scanner in = new Scanner(System.in); int a = in.nextInt();
  • 27. Java  6:  XML  &  Web  Services   •  Easy  way  of  creaQng  Web  Services   •  Expose  web  service  with  a  simple  annotaQon      
  • 28. Web  Service   package hello; import javax.jws.WebService; @WebService public class CircleFunctions { public double getArea(double r) { return java.lang.Math.PI * (r * r); } public double getCircumference(double r) { return 2 * java.lang.Math.PI * r; } }
  • 29. Server   import javax.xml.ws.Endpoint; class Publish { public static void main(String[] args) { Endpoint.publish( "http://localhost:8080/circlefunctions", new CircleFunctions()); }
  • 30. Generate  Stub  Files   •  Generate  stub  files:   –  wsgen  –cp  .  hello.CircleFuncQons  
  • 31.
  • 32. Java  6:  Rhino   •  Framework  to  connect  to  Java  programs  to   scripQng-­‐language  interpreters.   •  Rhino  JS  Engine  comes  with  Java  6   •  To  ability  to  run  JS  from  Java  and  JS  from   command  line   •  Rhino  is  wriken  in  Java  
  • 33. Example   import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; public class Main { public static void main(String[] args) { ScriptEngineManager mgr = new ScriptEngineManager(); ScriptEngine engine = mgr.getEngineByName("JavaScript"); // Now we have a script engine instance that // can execute some JavaScript try { engine.eval("print('Hello')"); } catch (ScriptException ex) { ex.printStackTrace(); } } }
  • 34. Java  6:  GUI   •  Faster  Splash  Screens   •  System  tray  support   •  Improved  Drag  and  Drop   •  Improved  Layout   •  WriQng  of  Gif  -­‐  files  
  • 35. Java  6:  DB  Support   •  Java  6  comes  with  preinstalled  relaQonal   database,  Oracle  release  of  Apache  Derby   Project   •  Java  DB  is  installed  automaQcally  as  part  of   the  Java  SE  Development  Kit  (JDK).   •  For  a  Java  DB  installaQon,  set  the   DERBY_HOME  environment  variable  
  • 36. Java  7   •  Using  Strings  in  switch  statements   •  Syntax  for  automaQc  cleaning  of  streams   •  Numeric  literals  with  underscores   •  OR  in  excepQon  catches