Java5 Annotations - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

Java5 Annotations

Description:

This additional data, or annotation, can be read by the javac compiler or other ... (Apache/Bea) Beehive .NET 2.0. 7. Aug 23, 2005. Annotatie typen. Marker annotation ... – PowerPoint PPT presentation

Number of Views:58
Avg rating:3.0/5.0
Slides: 24
Provided by: AinoAnd3
Category:

less

Transcript and Presenter's Notes

Title: Java5 Annotations


1
Java5 Annotations
  • Aino Andriessen

2
Inleiding
  • Java5
  • annotations (jsr 175)
  • generics
  • enhanced for loop
  • auto(un)boxing
  • enumerations
  • static imports
  • variable arguments
  • formatted output
  • enhanced java.util.Properties
  • jvm enhancements
  • JMX console

3
Java 5
  • Ondersteuning ides
  • JDeveloper 10.1.3 preview
  • tools gt Manage Libraries gt toevoegen java5
  • project properties gt libraries
  • Eclipse 3.1
  • NetBeans
  • IDEA
  • ...

4
Wat zijn annotaties?
  • The metadata feature in J2SE 5.0 provides the
    ability to associate additional data alongside
    Java types, methods, and fields. This additional
    data, or annotation, can be read by the javac
    compiler or other tools, and depending on
    configuration can also be stored in the class
    file and can be discovered at runtime using the
    Java reflection API.
  • Extra informatie in de java klasse tbv code
    generatie, run-time informatie

5
Metadata / Annotaties
  • Program annotation facility
  • we already have _at_deprecated, transient
  • Can add annotions to any declaration, including
    package
  • Annotations are instances of annotation types
    which can be declared.
  • Annotations can be processed by tools, or by
    reflective code.
  • code generation, class loading, runtime
  • Some annotion types built in

6
  • Niet nieuw
  • JavaDoc
  • XDoclet
  • (Apache/Bea) Beehive
  • .NET 2.0

7
Annotatie typen
  • Marker annotation
  • _at_Financial public class Invoice ...
  • Normal annotation name/value pairs
  • _at_optimise( levelhigh threadsafefalse
    lastCheck2/12/2004)
  • public void credit(Money amount) ...

8
Built-ins - Override
  • java.lang.Override
  • target method
  • marks methods intended to override a superclass
    method
  • kan een compiler error opleveren

9
Buit-ins - Documented
  • java.lang.annotation.Documented
  • documentatie van de annotatie door bijv. JavaDoc

10
Buit-ins - Deprecated
  • java.lang.annotation.Deprecated
  • target class, method, field

11
Buit-ins - Inherited
  • java.lang.annotation.Inherited
  • Indicates that an annotation type is
    automatically inherited.
  • _at_inherited
  • public _at_interface Author ...
  • _at_Author(fred)
  • public class MySuperclass ..
  • public class MySubclass extends MySuperclass
    ... // will inherit the Author annotation

12
Built-ins - Retention
  • java.lang.annotation.Retention
  • Defines the availability (enum java.lang.annotatio
    n.RetentionPolicy)
  • source
  • class (default)
  • runtime

13
Built-ins - Target
  • java.lang.annotation.Target
  • Indicate the type of program element (enum
    java.lang.annotation.ElementType) to which the
    declared annotation is applicable
  • TYPE
  • FIELD
  • METHOD
  • PARAMETER
  • CONSTRUCTOR
  • LOCAL_VARIABLE
  • ANNOTATION_TYPE
  • PACKAGE
  • default all

14
Built-ins - SuppressWarnings
  • java.lang.SuppressWarnings
  • Indicatie dat de compiler warnings onderdrukt
    moeten worden.

15
User-defined
  • demo

16
Toepassingen
  • JEE 5
  • EJB 3.0
  • JUnit 4
  • ...

17
Session bean
  • package oracle.ejb30
  • import javax.ejb.Remote
  • _at_Remote
  • public interface HelloWorld
  • public void sayHello(String name)
  • -----------
  • package oracle.ejb30
  • import javax.ejb.Stateless
  • _at_Stateless
  • public class HelloWorldBean implements HelloWorld
  • public void sayHello(String name)
  • System.out.println("Hello "name " from
    first EJB3.0")

18
session bean - 2
  • Context context new InitialContext()
  • HelloWorld helloWorld (HelloWorld)context.lookup
    ("javacomp/env/ejb/HelloWorld")
  • helloWorld.sayHello(args0 )

19
Entity bean
  • _at_Entity
  • _at_Table(name "EMP")
  • public class Employee implements
    java.io.Serializable
  • private int empNo
  • private String eName
  • private double sal
  • _at_Id
  • _at_Column(name"EMPNO", primaryKeytrue)
  • public int getEmpNo()
  • return empNo
  • ..

20
entity bean - 2
  • _at_Stateless
  • public class EmployeeFacadeBean implements
    EmployeeFacade
  • _at_Resource
  • private EntityManager em
  • private Employee emp
  • public Employee findEmployeeByEmpNo(int empNo)
  • return ((Employee) em.find("Employee",empNo))
  • public void addEmployee(int empNo, String
    eName, double sal)
  • if (emp null) emp new Employee()
  • ...
  • em.persist(emp)

21
Apt
  • Annotation Processing Tool

src
class
apt
22
XDoclet
  • Code generation based on javadoc comments
  • Original for EJB

23
Referenties
  • Java5
  • http//java.sun.com/developer/technicalArticles/re
    leases/j2se15langfeat/
  • http//java.sun.com/reference/tigeradoption/
  • Annotations
  • http//java.sun.com/j2se/1.5.0/docs/guide/language
    /annotations.html
  • http//www.javaworld.com/javaworld/jw-07-2004/jw-0
    719-tiger3.html
  • http//www.onjava.com/pub/a/onjava/2004/04/21/decl
    arative.html
  • http//www-128.ibm.com/developerworks/java/library
    /j-cwt08025.html
  • EJB 3.0
  • http//www.oracle.com/technology/tech/java/ejb30.h
    tml
  • Apt
  • http//java.sun.com/j2se/1.5.0/docs/guide/apt/Gett
    ingStarted.html
Write a Comment
User Comments (0)
About PowerShow.com