SlideShare a Scribd company logo
1 of 72
[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Note Which over loaded  version of the method to call is based on the  reference  type of the argument passed at  compile  time. Example  UseAnimals.java
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Constructors are used to initialize instance variable state. class Foo { int size; String name; Foo(String name, int size) { this.name = name; this.size = size; } }
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Method Overriding When a method in a subclass has the same name and type signature as a method in its superclass, then the method in the  subclass is said to  override  the method in the superclass. The rules for overriding a method are as follows: •  The argument list must exactly match that of the overridden  method. If they don't match, you can end up with an overloaded  method •  The return type must be the same as, or a subtype of, the return  type declared in the original overridden method in the superclass. •  The access level can't be more restrictive than the overridden  method's.
•  The access level CAN be less restrictive than that of the overridden  method. •  The overriding method CAN throw any unchecked (runtime)  exception, regardless of whether the overridden method declares  the exception. •  The overriding method must NOT throw checked exceptions  that are new or broader than those declared by the overridden  method. •  You cannot override a method marked final. •  You cannot override a method marked static. •  If a method can't be inherited, you cannot override it.
Examples Legal and Illegal method overrides Consider  public class Animal{ public void eat(){ } }
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
 
 
Note  Which over ridden  version of the method to call is decided at  runtime  based on  object  type. Why Overridden Methods? Overridden methods allow Java to support run-time polymorphism. A call to an overridden method is resolved at run time,  rather than compile time. Example  Dispatch.java
Difference between Overloaded and Overridden methods
The Super Keyword super is used in a class to refer to its superclass super is used to refer to the members of superclass,  both data attributes and methods  Behavior invoked does not have to be in the superclass;  it can be further up in the hierarchy
Example interface I { int x = 0; }  class T1 implements I { int x = 1; }  class T2 extends T1 { int x = 2; }  class T3 extends T2 {  int x = 3;  void test() {  System.out.println("x="+x);  System.out.println("super.x="+super.x);  System.out.println("((T2)this).x="+((T2)this).x);  System.out.println("((T1)this).x="+((T1)this).x);  System.out.println("((I)this).x="+((I)this).x);  }  }  class Test {  public static void main(String[] args) {  new T3().test();  } }
Static import Statement This statement is used in  situations where there is a need  of frequent access to static final fields (constants) and static methods  from one or two classes.  Prefixing the name of these classes over and over can result in  cluttered code.  The  static import  statement gives a way to import the constants  and static methods so as to avoid to prefix the name of their class.
The java.lang.Math class defines the PI constant and many  static methods, including methods for calculating sines, cosines,  tangents, square roots, maxima, minima, exponents, and many  more.  For example,   public static final double PI 3.141592653589793  public static double cos(double a)  Ordinarily, to use these objects from another class, you prefix  the class name, as follows.  double r = Math.cos(Math.PI * 2);
Use the static import statement to import the static members of  java.lang.Math so that you don't need to prefix the class name, Math.  The static members of Math can be imported either individually:  import  static  java.lang.Math.PI; or as a group:  import  static  java.lang.Math.*;  Once they have been imported, the static members can be used  without qualification  double r = cos(PI * 2);
Enumerations With JDK 5.0 , Java restrict a variable to having one of only a few  predefined values – in other words, one value from enumerated list By using this simple declaration  enum CoffeeSize { BIG, HUGE, OVERWHELMING} you can guarantee that the compiler will stop you from assigning  anything to coffeeSize except BIG, HUGE, OVERWHELMING. Statement like this  CoffeeSize cs = CoffeeSize.LARGE; will give compile time error.
Enumerations  •  It’s a list of named constants. •  Enumerations were added to Java language beginning with JDK 5.0 •  In Java enumeration defines a class type. •  An enumeration is created using enum keyword enum Apple{ Jonathan, GoldenDel, RedDel, Winesap, Cortland } Here enumeration list various Apple varieties. Example  EnumDemo
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Enums Declaration Outside class   Example CoffeeTest1.java Inside class   Example CoffeeTest2.java What would be the output public class CoffeeTest1 { public static void main(String[] args) { enum CoffeeSize { BIG, HUGE, OVERWHELMING } Coffee drink = new Coffee(); drink.size = CoffeeSize.BIG; } }
Answer Compile time error, cannot declare enums in method. Note   •  Semicolon at the end of enum declaration is optional. •  enums are not Strings or ints, each of the enumerated CoffeeSize  types are actually instance of CoffeeSize.
enum is a kind of class which look something like this class CoffeeSize { public static final CoffeeSize BIG =new CoffeeSize("BIG", 0); public static final CoffeeSize HUGE =new CoffeeSize("HUGE", 1); public static final CoffeeSize OVERWHELMING = new CoffeeSize("OVERWHELMING", 2); public CoffeeSize(String enumName, int index) { // stuff here } public static void main(String[] args) { System.out.println(CoffeeSize.BIG); } }
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
values() and valueOf() Methods •  All enumerations automatically contain two predefined methods values() and valueOf() •  The values() method returns an array that contains a list of  enumeration constants. •  valueOf() method returns the enumeration constant whose value  correspond to the string passed in str. Example  EnumDemo2
Java Enumerations are Class Types Although its not possible to instantiate an enum using new,but  it has the same capabilities as other classes. Each enumeration constant is an object of its enumeration type.So if a  constructor is defined for an enum,the constructor is called when each enumeration constant is created. Example  EnumDemo3
Enumerations Inherit Enum Its not possible to inherit a superclass when declaring an enum, All enumerations automatically inherit one: java.lang.Enum Three commonly used methods of Enum class final int ordial() This is used to obtain a value that indicates an enumeration  constant’s position in the list of constants. final int compareTo(enum-type e) Used to compare the ordinal value of two constants. equals() To compare for equality of an enumeration constant with  any other object.
Wrapper Classes Java use the simple data type such as int or char,these  data types are not part of object hierarchy. At times its needed to create an object representation for  one of these simple types. For example  Data structures implemented by Java operate on  objects which means these cannot be used to store primitive types.
Wrapper Classes and their Constructor Arguments
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
valueOf() Provide an approach to creating wrapper objects. Float f2 = Float.valueOf("3.14f"); // assigns 3.14 to the Float object f2 xxxValue() When you need to convert the value of a wrapped numeric to a  primitive, use one of the many xxxValue() methods. Integer i2 = new Integer(42);  byte b = i2.byteValue(); short s = i2.shortValue();
parseXxx() Both parseXxx() and valueOf() take a String as an argument. The difference between the two methods is •  parseXxx() returns the named primitive. •  valueOf() returns a newly created wrapped object of the type that  invoked the method. double d4 = Double.parseDouble("3.14"); // convert a String to a primitive result is d4 = 3.14 toString() toString() method  allow you to get some meaningful  representation of a given object. Double d = new Double("3.14"); System.out.println("d = "+ d.toString() );
In summary, the essential method signatures for Wrapper  conversion methods are primitive xxxValue()  - to convert a Wrapper to a primitive primitive parseXxx(String)  - to convert a String to a primitive Wrapper valueOf(String)  - to convert a String to a Wrapper
Boxing The process of encapsulating a value within an object is called boxing. Integer iOb= new Integer(100); Unboxing The process of extracting avalue from a type wrapper is called  unboxing.  int i = iOb.intValue();
Autoboxing/unboxing With JDK 5, Java added two important features: autoboxing and auto-unboxing. Autoboxing  is a process by which a primitive type is automatically encapsulated into its equivalent type wrapper whenever the object of  that type is needed. Auto-unboxing   is a process by which the value of a boxed object is  automatically extracted from a type wrapper when its value is needed. There is no need to call a method as intValue() or doubleValue().
The modern way to construct an Integer object  that has the value 100 Integer iOb=100; To unbox an object, assign that object reference to a primitive type  variable int i=iOb; Example  AutoBox.java Autoboxing with method parameters and return values Example  AutoBox2.java
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Overloading with Boxing class AddBoxing { static void go(Integer x) {  System.out.println("Integer");  } static void go(long x) {  System.out.println("long");  } public static void main(String [] args) {   int i = 5; go(i); // which go() will be invoked? } } The answer is that the compiler will choose widening over boxing,  so the output will be long
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Methods of Object class
Nested and Inner Class It is possible to define a class within another class; such classes are known as  nested classes . The scope of a nested class is bounded by the scope of its  enclosing class. Thus, if class B is defined within class A,  then B is known to A, but not outside of A. A nested class has access to the members, including  private members, of the class in which it is nested.  However, the enclosing class does not have access to the  members of the nested class.
[object Object],[object Object],[object Object]
Static Nested class A  static nested class  is one which has the  static  modifier applied. Because it is static, it must access the  members of its enclosing class through an object. That is,  it cannot refer to members of its enclosing class directly.  Because of this restriction, static nested classes are seldom  used.
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Non Static Nested Class (Inner Class) The most important type of nested class is the  inner  class .  An inner class is a  non-static nested class .  It has access to all of the variables and methods of its  outer class and may refer to them directly in the same way  that other non-static members of the outer class do. Thus, an  inner class is fully within the scope of its enclosing class.
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Local class   Class defined inside methods Nested classes can be declared in any block, and that this  means you can define a class inside a method. Points to consider 1.Anything declared inside a method is not a member of the class,  but is local to the method. The immediate consequence is that  classes declared in methods are private to the method and cannot  be marked with any access modifier; neither can they be marked as  static. 2.A method-local inner class can be instantiated only within the  method where the inner class is defined. 3. The method-local inner class object can access enclosing (outer)  class object private members. Example  MyOuter2.java
The only modifiers you  can  apply to a method-local inner class are abstract and final, but as always, never both at the same time. Remember that a local class declared in a static method has access to only static members of the enclosing class, since there is  no associated instance of the enclosing class.  If you're in a static method, there is no this, so an inner class in a  static method is subject to the same restrictions as the static  method. In other words, no access to instance variables.
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
We define two classes, Popcorn and Food. * Popcorn has one method, pop(). * Food has one instance variable, declared as type Popcorn.  That's it for Food,Food has  no  methods. The Popcorn reference variable refers  not  to an instance of Popcorn,  but to  an instance of an anonymous (unnamed) subclass of Popcorn .
Let's look at just the anonymous class code: 2. Popcorn p = new Popcorn() { 3.  public void pop() { 4.  System.out.println("anonymous popcorn"); 5.  } 6. }; Line 2 says Declare a reference variable, p, of type Popcorn. Then  declare a new class that has no name, but that is a  subclass  of  Popcorn. And here's the curly brace that opens the class definition…
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Annotations (Metadata) Annotations are used to embed supplemental information into a source file, this does not change the action of a program. The term Metadata is also used to refer to this feature. Some API’s require “side files” to be maintained in parallel with  programs.  JavaBeans requires a BeanInfo class to be maintained in parallel  with a bean.  Enterprise JavaBeans (EJB) requires a  deployment descriptor .  It would be more convenient and less error-prone if the  information in these side files were maintained as  annotations  in the program itself.
Transient modifier is an ad hoc annotation indicating that a field  should be ignored by the serialization subsystem,  and the @deprecated javadoc tag is an ad hoc annotation  indicating that the method should no longer be used.  With the release of JDK5.0 the platform has a general purpose  annotation, that permit you to define and use your own annotation  types.
Annotations have a number of uses, among them:  Information for the compiler  — Annotations can be used by the  compiler to detect errors or suppress warnings.  Compiler-time and deployment-time processing  — Software tools  can process annotation information to generate code, XML files, and  so forth.  Runtime processing  — Some annotations are available to be  examined at runtime.
Declaring Annotation public @interface RequestForEnhancement {  int id();  String synopsis();  String engineer();  String date();  }  Once an annotation type is defined, use it to annotate declarations.
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Marker  Annotation An annotation type with no elements is termed a  marker  annotation  type, for example:  public @interface Preliminary { }  It is permissible to omit the parentheses in marker annotations,  @Preliminary public class TimeTravel { ... }
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example :  Test,Foo,RunTests import java.lang.annotation.*; @Retention(RetentionPolicy.RUNTIME)  @Target(ElementType.METHOD)  public @interface Test { }  The annotation type declaration is itself annotated. Such annotations  are called  meta-annotations . Here @Retention(RetentionPolicy.RUNTIME) indicates that  annotations with this type are to be retained by the VM so they can  be read reflectively at run-time.  @Target(ElementType.METHOD) indicates that this annotation  type can be used to annotate only method declarations.
Annotation Examples Meta.java This example uses reflection to display the annotation associated with a  method. Meta1.java This example uses reflection to display the annotation associated with a  method having arguments. Meta2.java This example demonstrate how to obtain all annotations That have RUNTIME retention that are associated with an item. Meta3.java This example demonstrate the use of default values in an  annotation.

More Related Content

What's hot

Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysUnit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysDevaKumari Vijay
 
The Go Programing Language 1
The Go Programing Language 1The Go Programing Language 1
The Go Programing Language 1İbrahim Kürce
 
Java interview questions 1
Java interview questions 1Java interview questions 1
Java interview questions 1Sherihan Anver
 
java: basics, user input, data type, constructor
java:  basics, user input, data type, constructorjava:  basics, user input, data type, constructor
java: basics, user input, data type, constructorShivam Singhal
 
Ap Power Point Chpt5
Ap Power Point Chpt5Ap Power Point Chpt5
Ap Power Point Chpt5dplunkett
 
Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in javaElizabeth alexander
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in javaAhsan Raja
 
Comparable/ Comparator
Comparable/ ComparatorComparable/ Comparator
Comparable/ ComparatorSean McElrath
 
Comparable and comparator – a detailed discussion
Comparable and comparator – a detailed discussionComparable and comparator – a detailed discussion
Comparable and comparator – a detailed discussionDharmendra Prasad
 
OCA Java SE 8 Exam Chapter 6 Exceptions
OCA Java SE 8 Exam Chapter 6 ExceptionsOCA Java SE 8 Exam Chapter 6 Exceptions
OCA Java SE 8 Exam Chapter 6 Exceptionsİbrahim Kürce
 
Refactoring bad codesmell
Refactoring bad codesmellRefactoring bad codesmell
Refactoring bad codesmellhyunglak kim
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaCPD INDIA
 
Method Overloading In Java
Method Overloading In JavaMethod Overloading In Java
Method Overloading In JavaCharthaGaglani
 

What's hot (20)

Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
 
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysUnit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
 
The Go Programing Language 1
The Go Programing Language 1The Go Programing Language 1
The Go Programing Language 1
 
Java interview questions 1
Java interview questions 1Java interview questions 1
Java interview questions 1
 
Java interview
Java interviewJava interview
Java interview
 
java: basics, user input, data type, constructor
java:  basics, user input, data type, constructorjava:  basics, user input, data type, constructor
java: basics, user input, data type, constructor
 
Core java by amit
Core java by amitCore java by amit
Core java by amit
 
Ap Power Point Chpt5
Ap Power Point Chpt5Ap Power Point Chpt5
Ap Power Point Chpt5
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in java
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in java
 
Comparable/ Comparator
Comparable/ ComparatorComparable/ Comparator
Comparable/ Comparator
 
Ppt chapter11
Ppt chapter11Ppt chapter11
Ppt chapter11
 
Comparable and comparator – a detailed discussion
Comparable and comparator – a detailed discussionComparable and comparator – a detailed discussion
Comparable and comparator – a detailed discussion
 
OCA Java SE 8 Exam Chapter 6 Exceptions
OCA Java SE 8 Exam Chapter 6 ExceptionsOCA Java SE 8 Exam Chapter 6 Exceptions
OCA Java SE 8 Exam Chapter 6 Exceptions
 
Refactoring bad codesmell
Refactoring bad codesmellRefactoring bad codesmell
Refactoring bad codesmell
 
Ppt chapter09
Ppt chapter09Ppt chapter09
Ppt chapter09
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Method Overloading In Java
Method Overloading In JavaMethod Overloading In Java
Method Overloading In Java
 
Unit 4 Java
Unit 4 JavaUnit 4 Java
Unit 4 Java
 

Similar to Md06 advance class features

Java findamentals2
Java findamentals2Java findamentals2
Java findamentals2Todor Kolev
 
Java findamentals2
Java findamentals2Java findamentals2
Java findamentals2Todor Kolev
 
Enumerations in java.pptx
Enumerations in java.pptxEnumerations in java.pptx
Enumerations in java.pptxSrizan Pokrel
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptxEpsiba1
 
Learn java
Learn javaLearn java
Learn javaPalahuja
 
Unit 7 inheritance
Unit 7 inheritanceUnit 7 inheritance
Unit 7 inheritanceatcnerd
 
Corejava Training in Bangalore Tutorial
Corejava Training in Bangalore TutorialCorejava Training in Bangalore Tutorial
Corejava Training in Bangalore Tutorialrajkamaltibacademy
 
SOEN6441.generics.ppt
SOEN6441.generics.pptSOEN6441.generics.ppt
SOEN6441.generics.pptElieMambou1
 
CIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaCIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaHamad Odhabi
 
Core Java Concepts
Core Java ConceptsCore Java Concepts
Core Java Conceptsmdfkhan625
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rdConnex
 
A Case Study on Java. Java Presentation
A Case Study on Java. Java Presentation A Case Study on Java. Java Presentation
A Case Study on Java. Java Presentation Ayush Gupta
 
Introduction of Object Oriented Programming Language using Java. .pptx
Introduction of Object Oriented Programming Language using Java. .pptxIntroduction of Object Oriented Programming Language using Java. .pptx
Introduction of Object Oriented Programming Language using Java. .pptxPoonam60376
 

Similar to Md06 advance class features (20)

Md03 - part3
Md03 - part3Md03 - part3
Md03 - part3
 
Java findamentals2
Java findamentals2Java findamentals2
Java findamentals2
 
Java findamentals2
Java findamentals2Java findamentals2
Java findamentals2
 
Enumerations in java.pptx
Enumerations in java.pptxEnumerations in java.pptx
Enumerations in java.pptx
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptx
 
Java
JavaJava
Java
 
Learn java
Learn javaLearn java
Learn java
 
Unit 7 inheritance
Unit 7 inheritanceUnit 7 inheritance
Unit 7 inheritance
 
Md04 flow control
Md04 flow controlMd04 flow control
Md04 flow control
 
14 interface
14  interface14  interface
14 interface
 
Corejava Training in Bangalore Tutorial
Corejava Training in Bangalore TutorialCorejava Training in Bangalore Tutorial
Corejava Training in Bangalore Tutorial
 
SOEN6441.generics.ppt
SOEN6441.generics.pptSOEN6441.generics.ppt
SOEN6441.generics.ppt
 
M C6java3
M C6java3M C6java3
M C6java3
 
CIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaCIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in Java
 
Core Java Concepts
Core Java ConceptsCore Java Concepts
Core Java Concepts
 
Java scjp-part1
Java scjp-part1Java scjp-part1
Java scjp-part1
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
 
JAVA LOOP.pptx
JAVA LOOP.pptxJAVA LOOP.pptx
JAVA LOOP.pptx
 
A Case Study on Java. Java Presentation
A Case Study on Java. Java Presentation A Case Study on Java. Java Presentation
A Case Study on Java. Java Presentation
 
Introduction of Object Oriented Programming Language using Java. .pptx
Introduction of Object Oriented Programming Language using Java. .pptxIntroduction of Object Oriented Programming Language using Java. .pptx
Introduction of Object Oriented Programming Language using Java. .pptx
 

More from Rakesh Madugula

More from Rakesh Madugula (11)

New features and enhancement
New features and enhancementNew features and enhancement
New features and enhancement
 
Md13 networking
Md13 networkingMd13 networking
Md13 networking
 
Md121 streams
Md121 streamsMd121 streams
Md121 streams
 
Md11 gui event handling
Md11 gui event handlingMd11 gui event handling
Md11 gui event handling
 
Md10 building java gu is
Md10 building java gu isMd10 building java gu is
Md10 building java gu is
 
Md09 multithreading
Md09 multithreadingMd09 multithreading
Md09 multithreading
 
Md08 collection api
Md08 collection apiMd08 collection api
Md08 collection api
 
Md07 exceptions&assertion
Md07 exceptions&assertionMd07 exceptions&assertion
Md07 exceptions&assertion
 
Md05 arrays
Md05 arraysMd05 arrays
Md05 arrays
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
 
A begineers guide of JAVA - Getting Started
 A begineers guide of JAVA - Getting Started A begineers guide of JAVA - Getting Started
A begineers guide of JAVA - Getting Started
 

Recently uploaded

ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDhatriParmar
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWQuiz Club NITW
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleCeline George
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17Celine George
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptxmary850239
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Association for Project Management
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvRicaMaeCastro1
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 

Recently uploaded (20)

ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITW
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP Module
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 

Md06 advance class features

  • 1.
  • 2.
  • 3.
  • 4.
  • 5. Note Which over loaded version of the method to call is based on the reference type of the argument passed at compile time. Example UseAnimals.java
  • 6.
  • 7. Constructors are used to initialize instance variable state. class Foo { int size; String name; Foo(String name, int size) { this.name = name; this.size = size; } }
  • 8.
  • 9.
  • 10. Method Overriding When a method in a subclass has the same name and type signature as a method in its superclass, then the method in the subclass is said to override the method in the superclass. The rules for overriding a method are as follows: • The argument list must exactly match that of the overridden method. If they don't match, you can end up with an overloaded method • The return type must be the same as, or a subtype of, the return type declared in the original overridden method in the superclass. • The access level can't be more restrictive than the overridden method's.
  • 11. • The access level CAN be less restrictive than that of the overridden method. • The overriding method CAN throw any unchecked (runtime) exception, regardless of whether the overridden method declares the exception. • The overriding method must NOT throw checked exceptions that are new or broader than those declared by the overridden method. • You cannot override a method marked final. • You cannot override a method marked static. • If a method can't be inherited, you cannot override it.
  • 12. Examples Legal and Illegal method overrides Consider public class Animal{ public void eat(){ } }
  • 13.
  • 14.  
  • 15.  
  • 16. Note Which over ridden version of the method to call is decided at runtime based on object type. Why Overridden Methods? Overridden methods allow Java to support run-time polymorphism. A call to an overridden method is resolved at run time, rather than compile time. Example Dispatch.java
  • 17. Difference between Overloaded and Overridden methods
  • 18. The Super Keyword super is used in a class to refer to its superclass super is used to refer to the members of superclass, both data attributes and methods Behavior invoked does not have to be in the superclass; it can be further up in the hierarchy
  • 19. Example interface I { int x = 0; } class T1 implements I { int x = 1; } class T2 extends T1 { int x = 2; } class T3 extends T2 { int x = 3; void test() { System.out.println("x="+x); System.out.println("super.x="+super.x); System.out.println("((T2)this).x="+((T2)this).x); System.out.println("((T1)this).x="+((T1)this).x); System.out.println("((I)this).x="+((I)this).x); } } class Test { public static void main(String[] args) { new T3().test(); } }
  • 20. Static import Statement This statement is used in situations where there is a need of frequent access to static final fields (constants) and static methods from one or two classes. Prefixing the name of these classes over and over can result in cluttered code. The static import statement gives a way to import the constants and static methods so as to avoid to prefix the name of their class.
  • 21. The java.lang.Math class defines the PI constant and many static methods, including methods for calculating sines, cosines, tangents, square roots, maxima, minima, exponents, and many more. For example, public static final double PI 3.141592653589793 public static double cos(double a) Ordinarily, to use these objects from another class, you prefix the class name, as follows. double r = Math.cos(Math.PI * 2);
  • 22. Use the static import statement to import the static members of java.lang.Math so that you don't need to prefix the class name, Math. The static members of Math can be imported either individually: import static java.lang.Math.PI; or as a group: import static java.lang.Math.*; Once they have been imported, the static members can be used without qualification double r = cos(PI * 2);
  • 23. Enumerations With JDK 5.0 , Java restrict a variable to having one of only a few predefined values – in other words, one value from enumerated list By using this simple declaration enum CoffeeSize { BIG, HUGE, OVERWHELMING} you can guarantee that the compiler will stop you from assigning anything to coffeeSize except BIG, HUGE, OVERWHELMING. Statement like this CoffeeSize cs = CoffeeSize.LARGE; will give compile time error.
  • 24. Enumerations • It’s a list of named constants. • Enumerations were added to Java language beginning with JDK 5.0 • In Java enumeration defines a class type. • An enumeration is created using enum keyword enum Apple{ Jonathan, GoldenDel, RedDel, Winesap, Cortland } Here enumeration list various Apple varieties. Example EnumDemo
  • 25.
  • 26.
  • 27. Enums Declaration Outside class Example CoffeeTest1.java Inside class Example CoffeeTest2.java What would be the output public class CoffeeTest1 { public static void main(String[] args) { enum CoffeeSize { BIG, HUGE, OVERWHELMING } Coffee drink = new Coffee(); drink.size = CoffeeSize.BIG; } }
  • 28. Answer Compile time error, cannot declare enums in method. Note • Semicolon at the end of enum declaration is optional. • enums are not Strings or ints, each of the enumerated CoffeeSize types are actually instance of CoffeeSize.
  • 29. enum is a kind of class which look something like this class CoffeeSize { public static final CoffeeSize BIG =new CoffeeSize("BIG", 0); public static final CoffeeSize HUGE =new CoffeeSize("HUGE", 1); public static final CoffeeSize OVERWHELMING = new CoffeeSize("OVERWHELMING", 2); public CoffeeSize(String enumName, int index) { // stuff here } public static void main(String[] args) { System.out.println(CoffeeSize.BIG); } }
  • 30.
  • 31. values() and valueOf() Methods • All enumerations automatically contain two predefined methods values() and valueOf() • The values() method returns an array that contains a list of enumeration constants. • valueOf() method returns the enumeration constant whose value correspond to the string passed in str. Example EnumDemo2
  • 32. Java Enumerations are Class Types Although its not possible to instantiate an enum using new,but it has the same capabilities as other classes. Each enumeration constant is an object of its enumeration type.So if a constructor is defined for an enum,the constructor is called when each enumeration constant is created. Example EnumDemo3
  • 33. Enumerations Inherit Enum Its not possible to inherit a superclass when declaring an enum, All enumerations automatically inherit one: java.lang.Enum Three commonly used methods of Enum class final int ordial() This is used to obtain a value that indicates an enumeration constant’s position in the list of constants. final int compareTo(enum-type e) Used to compare the ordinal value of two constants. equals() To compare for equality of an enumeration constant with any other object.
  • 34. Wrapper Classes Java use the simple data type such as int or char,these data types are not part of object hierarchy. At times its needed to create an object representation for one of these simple types. For example Data structures implemented by Java operate on objects which means these cannot be used to store primitive types.
  • 35. Wrapper Classes and their Constructor Arguments
  • 36.
  • 37. valueOf() Provide an approach to creating wrapper objects. Float f2 = Float.valueOf("3.14f"); // assigns 3.14 to the Float object f2 xxxValue() When you need to convert the value of a wrapped numeric to a primitive, use one of the many xxxValue() methods. Integer i2 = new Integer(42); byte b = i2.byteValue(); short s = i2.shortValue();
  • 38. parseXxx() Both parseXxx() and valueOf() take a String as an argument. The difference between the two methods is • parseXxx() returns the named primitive. • valueOf() returns a newly created wrapped object of the type that invoked the method. double d4 = Double.parseDouble("3.14"); // convert a String to a primitive result is d4 = 3.14 toString() toString() method allow you to get some meaningful representation of a given object. Double d = new Double("3.14"); System.out.println("d = "+ d.toString() );
  • 39. In summary, the essential method signatures for Wrapper conversion methods are primitive xxxValue() - to convert a Wrapper to a primitive primitive parseXxx(String) - to convert a String to a primitive Wrapper valueOf(String) - to convert a String to a Wrapper
  • 40. Boxing The process of encapsulating a value within an object is called boxing. Integer iOb= new Integer(100); Unboxing The process of extracting avalue from a type wrapper is called unboxing. int i = iOb.intValue();
  • 41. Autoboxing/unboxing With JDK 5, Java added two important features: autoboxing and auto-unboxing. Autoboxing is a process by which a primitive type is automatically encapsulated into its equivalent type wrapper whenever the object of that type is needed. Auto-unboxing is a process by which the value of a boxed object is automatically extracted from a type wrapper when its value is needed. There is no need to call a method as intValue() or doubleValue().
  • 42. The modern way to construct an Integer object that has the value 100 Integer iOb=100; To unbox an object, assign that object reference to a primitive type variable int i=iOb; Example AutoBox.java Autoboxing with method parameters and return values Example AutoBox2.java
  • 43.
  • 44.
  • 45. Overloading with Boxing class AddBoxing { static void go(Integer x) { System.out.println("Integer"); } static void go(long x) { System.out.println("long"); } public static void main(String [] args) { int i = 5; go(i); // which go() will be invoked? } } The answer is that the compiler will choose widening over boxing, so the output will be long
  • 46.
  • 48. Nested and Inner Class It is possible to define a class within another class; such classes are known as nested classes . The scope of a nested class is bounded by the scope of its enclosing class. Thus, if class B is defined within class A, then B is known to A, but not outside of A. A nested class has access to the members, including private members, of the class in which it is nested. However, the enclosing class does not have access to the members of the nested class.
  • 49.
  • 50. Static Nested class A static nested class is one which has the static modifier applied. Because it is static, it must access the members of its enclosing class through an object. That is, it cannot refer to members of its enclosing class directly. Because of this restriction, static nested classes are seldom used.
  • 51.
  • 52. Non Static Nested Class (Inner Class) The most important type of nested class is the inner class . An inner class is a non-static nested class . It has access to all of the variables and methods of its outer class and may refer to them directly in the same way that other non-static members of the outer class do. Thus, an inner class is fully within the scope of its enclosing class.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57. Local class Class defined inside methods Nested classes can be declared in any block, and that this means you can define a class inside a method. Points to consider 1.Anything declared inside a method is not a member of the class, but is local to the method. The immediate consequence is that classes declared in methods are private to the method and cannot be marked with any access modifier; neither can they be marked as static. 2.A method-local inner class can be instantiated only within the method where the inner class is defined. 3. The method-local inner class object can access enclosing (outer) class object private members. Example MyOuter2.java
  • 58. The only modifiers you can apply to a method-local inner class are abstract and final, but as always, never both at the same time. Remember that a local class declared in a static method has access to only static members of the enclosing class, since there is no associated instance of the enclosing class. If you're in a static method, there is no this, so an inner class in a static method is subject to the same restrictions as the static method. In other words, no access to instance variables.
  • 59.
  • 60. We define two classes, Popcorn and Food. * Popcorn has one method, pop(). * Food has one instance variable, declared as type Popcorn. That's it for Food,Food has no methods. The Popcorn reference variable refers not to an instance of Popcorn, but to an instance of an anonymous (unnamed) subclass of Popcorn .
  • 61. Let's look at just the anonymous class code: 2. Popcorn p = new Popcorn() { 3. public void pop() { 4. System.out.println("anonymous popcorn"); 5. } 6. }; Line 2 says Declare a reference variable, p, of type Popcorn. Then declare a new class that has no name, but that is a subclass of Popcorn. And here's the curly brace that opens the class definition…
  • 62.
  • 63.
  • 64. Annotations (Metadata) Annotations are used to embed supplemental information into a source file, this does not change the action of a program. The term Metadata is also used to refer to this feature. Some API’s require “side files” to be maintained in parallel with programs. JavaBeans requires a BeanInfo class to be maintained in parallel with a bean. Enterprise JavaBeans (EJB) requires a deployment descriptor . It would be more convenient and less error-prone if the information in these side files were maintained as annotations in the program itself.
  • 65. Transient modifier is an ad hoc annotation indicating that a field should be ignored by the serialization subsystem, and the @deprecated javadoc tag is an ad hoc annotation indicating that the method should no longer be used. With the release of JDK5.0 the platform has a general purpose annotation, that permit you to define and use your own annotation types.
  • 66. Annotations have a number of uses, among them: Information for the compiler — Annotations can be used by the compiler to detect errors or suppress warnings. Compiler-time and deployment-time processing — Software tools can process annotation information to generate code, XML files, and so forth. Runtime processing — Some annotations are available to be examined at runtime.
  • 67. Declaring Annotation public @interface RequestForEnhancement { int id(); String synopsis(); String engineer(); String date(); } Once an annotation type is defined, use it to annotate declarations.
  • 68.
  • 69. Marker Annotation An annotation type with no elements is termed a marker annotation type, for example: public @interface Preliminary { } It is permissible to omit the parentheses in marker annotations, @Preliminary public class TimeTravel { ... }
  • 70.
  • 71. Example : Test,Foo,RunTests import java.lang.annotation.*; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Test { } The annotation type declaration is itself annotated. Such annotations are called meta-annotations . Here @Retention(RetentionPolicy.RUNTIME) indicates that annotations with this type are to be retained by the VM so they can be read reflectively at run-time. @Target(ElementType.METHOD) indicates that this annotation type can be used to annotate only method declarations.
  • 72. Annotation Examples Meta.java This example uses reflection to display the annotation associated with a method. Meta1.java This example uses reflection to display the annotation associated with a method having arguments. Meta2.java This example demonstrate how to obtain all annotations That have RUNTIME retention that are associated with an item. Meta3.java This example demonstrate the use of default values in an annotation.