SlideShare a Scribd company logo
1 of 43
Unit 12 : Enumerations,
autoboxing, and annotations
Types of Beer
Disclaimer
•Disclaimer: This is not the promotion of
Beer. Just used for an educational purpose.
The author of image contains the full right of
the image. Uses of such product is injurious
to Health.
How to represent all Beers in Java?
• { ARNA, GORKHA, TUBOURG, MUSTANG,}
• - These all values are constant type.
• They are of same category
ENUM SHORTCUT FOR
ENUMERATION
When we want to represent a group of named
constants.
Ex: Represent month name with single variable.
enum Month {
JAN, FEB, MAR, …DEC;
}
[ ; is optional inside enum]
Main Objective | Use
• What is range of byte ?
[ - 128 to + 127 ]
Its Max Values : 256
Byte is a data type with max value : 256
Main Obective of enum:
• In month is our data type with 12 values allowed.
• Beer is my own data type with … values allowed
• Its Main Objective:
• To Define our own data types [ which is also known enumerated
data types]
Defining an Enum
• Use enum instead of the class keyword and name of enum.
• The constant values are listed in the enum’s body
• It is common to write the constants in all uppercase.
While compared to old languages enum it is
more powerful in java, that came in 1.5 V.
• It can also include normal variables, methods and constructors.
• Every enum constant is public static final.
the values() and valueOf() method
value and valueOf both are static methods of enum type
and can be used to access enum elements.
Here we are using both the methods to access the enum
elements.
Ex: enum
• The values() method returns an array of enum-type variables
containing all of the enumeration constants.
• Here is an example:
• The valueOf(String) method returns an enumeration constant whose
value corresponds to the string passed to it or
• throws an IllegalArgumentException if no constant with the specified
name was found.
• System.out.println(ProgramLanguages.valueOf("JAVA"));
Points to remember about Enumerations
Enumerations are of class type, and have all the capabilities that
a Java class has.
Enumerations can have Constructors, instance Variables,
methods and can even implement Interfaces.
Enumerations are not instantiated using new keyword.
enum with Inheritance
• The Java enum class is a special class that allows you to
create a group of constant values (also known as
enumerations)
• The enum class is compiled as a final class in Java, so you
can’t extend an enum class in your code:
Type Wrappers: character, Boolean, the numeric type
wrappers
• int a = 5 + 10;
• Primitive types, rather than objects, are used for these
quantities for the sake of performance.
Using objects for these values would add an unacceptable
overhead to even the simplest of calculations.
Type Wrappers: character, Boolean, the numeric type
wrappers
Thus, the primitive types are not part of the object hierarchy, and
they do not inherit the Object.
Despite the performance benefit offered by the primitive
types, :
- there are times when you will need an object representation.
wrappers
• many of the standard data structures implemented by Java
operate on objects,
• which means that you can't use these data structures to store the primitive types.
• To handle these and other situations, Java provides type
wrappers, which are classes that encapsulate a primitive type
within an object.
The type wrappers
• The type wrappers are Integer, Short, Double, Long, Float,
Byte, Character, and Boolean.
• These classes offer a wide array of methods that allow you to
fully integrate the primitive types into the Java's object
hierarchy.
• Let's examine each.
Character
• Character is a wrapper around a char. The constructor for
the Character is
•
• char charValue() returns char value.
• https://codescracker.com/java/java-type-wrappers.htm
Autoboxing
Autoboxing is the automatic conversion that the Java compiler
makes between the primitive types and their corresponding
object wrapper classes.
For example, converting an int to an Integer, a double to a
Double, and so on.
If the conversion goes the other way, this is called unboxing.
Example 1: For Autoboxing and Unboxing
• https://www.geeksforgeeks.org/autoboxing-unboxing-java/
Autoboxing/Unboxing in Expressions
• Java autoboxing and unboxing take place whenever a
conversion into an object or from an object is required.
• This applies to expressions.
• Within an expression, a numeric object is automatically
unboxed.
• The outcome of the expression is reboxed, if necessary.
•
Ex: Program below the Note
• https://www.demo2s.com/java/java-primitive-data-type-autoboxing-
unboxing-in-expressions.html
Both programs are valid in above link but you can go for 2nd program
and explain it a little.
Autoboxing/unboxing Boolean and character values
• http://www.java2s.com/Tutorial/Java/0040__Data-
Type/AutoboxingUnboxingBooleanandCharacterValues.htm
Benefits of Autoboxing / Unboxing
1.Autoboxing / Unboxing lets us use primitive types and Wrapper class
objects interchangeably.
2.It helps prevent errors, but may lead to unexpected results sometimes.
Hence must be used with care.
3.We don't have to perform Explicit typecasting.
4.Auto-unboxing also allows you to mix different types of numeric objects in
an expression. When the values are unboxed, the standard type
conversions can be applied.
Example:
Annotations
• Java annotations are metadata (data about data) for our
program source code.
They provide additional information about the program to the
compiler but are not part of the program itself.
These annotations do not affect the execution of the compiled
program.
• Its syntax is:
• @AnnotationName
• Ex:
Annotations start with @.
Ex : @Override
• The @Override annotation specifies that the method with this
annotation overrides the superclass method with the same method
name, return type, and parameter list.
• It is not mandatory to use @Override when overriding a method.
• However, if we use it, the compiler gives an error if something is
wrong (such as wrong parameter type) while overriding the method.
Example 1: @Override Annotation
Example
• https://www.programiz.com/java-
programming/annotations#:~:text=Java%20annotations%20are%20m
etadata%20(data,execution%20of%20the%20compiled%20program.
• Check example 1
Java Annotations Retention Policy
• A retention policy determines at what point an annotation is
discarded.
•
• Java defines three such policies,
• They are SOURCE, CLASS, and RUNTIME.
@Retention(retention-policy)
• A retention policy is specified for an annotation by using one of
Java's built-in annotations: @Retention.
•
SOURCE
• An annotation with a retention policy of SOURCE is retained
[engaged | activated] only in the source file and is discarded
during compilation.
CLASS
• An annotation with a retention policy of CLASS is stored in
the .class file during compilation.
• However, it is not available through the JVM during run time.
RUNTIME
• An annotation with a retention policy of RUNTIME is stored in
the .class file during compilation and is available through the
JVM during run time.
Thus, RUNTIME retention offers the greatest annotation
persistence.
• Here, retention-policy must be one of the previously discussed
enumeration constants.
• If no retention policy is specified for an annotation, then the
default policy of CLASS is used.
Obtaining Annotations at Run Time via Refle
ction
• If annotations specify a retention policy of RUNTIME, then they
can be queried at run time by any Java program through the
use of reflection.
•
• Reflection is the feature that enables information about a
class to be obtained at run time.
• Reflection is a feature in the Java programming language. It
allows an executing Java program to examine or "introspect"
upon itself, and manipulate internal properties of the program.
• The ability to examine and manipulate a Java class from within
itself may not sound like very much, but in other programming
languages this feature simply doesn't exist
Example 1:
• https://www.oracle.com/technical-
resources/articles/java/javareflection.html
References
• https://www.studytonight.com/java/enumerations.php#:~:text=Enu
merations%20are%20of%20class%20type,Enumerations%20by%20de
fault%20inherit%20java.

More Related Content

Similar to Enumerations in java.pptx

OCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardOCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardHari kiran G
 
Java annotations
Java annotationsJava annotations
Java annotationsSujit Kumar
 
Learning core java
Learning core javaLearning core java
Learning core javaAbhay Bharti
 
Java Basics Presentation
Java Basics PresentationJava Basics Presentation
Java Basics PresentationOmid Sohrabi
 
Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for seleniumapoorvams
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interviewKuntal Bhowmick
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_reviewEdureka!
 
Java Faqs useful for freshers and experienced
Java Faqs useful for freshers and experiencedJava Faqs useful for freshers and experienced
Java Faqs useful for freshers and experiencedyearninginjava
 
Top 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experiencedTop 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experiencedGaurav Maheshwari
 
Core Java Introduction | Basics
Core Java Introduction  | BasicsCore Java Introduction  | Basics
Core Java Introduction | BasicsHùng Nguyễn Huy
 
cs213Lecture_1 java programming oopsss.pptx
cs213Lecture_1 java programming oopsss.pptxcs213Lecture_1 java programming oopsss.pptx
cs213Lecture_1 java programming oopsss.pptxmshanajoel6
 

Similar to Enumerations in java.pptx (20)

Java
JavaJava
Java
 
Java annotations
Java annotationsJava annotations
Java annotations
 
OCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardOCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference Card
 
Java annotations
Java annotationsJava annotations
Java annotations
 
Learning core java
Learning core javaLearning core java
Learning core java
 
Java Basics Presentation
Java Basics PresentationJava Basics Presentation
Java Basics Presentation
 
Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for selenium
 
CONSTRUCTORS.pptx
CONSTRUCTORS.pptxCONSTRUCTORS.pptx
CONSTRUCTORS.pptx
 
Java Jive 002.pptx
Java Jive 002.pptxJava Jive 002.pptx
Java Jive 002.pptx
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interview
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
 
Md03 - part3
Md03 - part3Md03 - part3
Md03 - part3
 
Java Faqs useful for freshers and experienced
Java Faqs useful for freshers and experiencedJava Faqs useful for freshers and experienced
Java Faqs useful for freshers and experienced
 
Java basic
Java basicJava basic
Java basic
 
Top 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experiencedTop 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experienced
 
Core Java Introduction | Basics
Core Java Introduction  | BasicsCore Java Introduction  | Basics
Core Java Introduction | Basics
 
cs213Lecture_1 java programming oopsss.pptx
cs213Lecture_1 java programming oopsss.pptxcs213Lecture_1 java programming oopsss.pptx
cs213Lecture_1 java programming oopsss.pptx
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Apex code (Salesforce)
Apex code (Salesforce)Apex code (Salesforce)
Apex code (Salesforce)
 
Java_Interview Qns
Java_Interview QnsJava_Interview Qns
Java_Interview Qns
 

Recently uploaded

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 

Recently uploaded (20)

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 

Enumerations in java.pptx

  • 1. Unit 12 : Enumerations, autoboxing, and annotations
  • 3. Disclaimer •Disclaimer: This is not the promotion of Beer. Just used for an educational purpose. The author of image contains the full right of the image. Uses of such product is injurious to Health.
  • 4. How to represent all Beers in Java? • { ARNA, GORKHA, TUBOURG, MUSTANG,} • - These all values are constant type. • They are of same category
  • 5. ENUM SHORTCUT FOR ENUMERATION When we want to represent a group of named constants. Ex: Represent month name with single variable. enum Month { JAN, FEB, MAR, …DEC; } [ ; is optional inside enum]
  • 6. Main Objective | Use • What is range of byte ? [ - 128 to + 127 ] Its Max Values : 256 Byte is a data type with max value : 256
  • 7. Main Obective of enum: • In month is our data type with 12 values allowed. • Beer is my own data type with … values allowed • Its Main Objective: • To Define our own data types [ which is also known enumerated data types]
  • 8. Defining an Enum • Use enum instead of the class keyword and name of enum. • The constant values are listed in the enum’s body • It is common to write the constants in all uppercase.
  • 9. While compared to old languages enum it is more powerful in java, that came in 1.5 V. • It can also include normal variables, methods and constructors. • Every enum constant is public static final.
  • 10. the values() and valueOf() method value and valueOf both are static methods of enum type and can be used to access enum elements. Here we are using both the methods to access the enum elements.
  • 12. • The values() method returns an array of enum-type variables containing all of the enumeration constants. • Here is an example:
  • 13. • The valueOf(String) method returns an enumeration constant whose value corresponds to the string passed to it or • throws an IllegalArgumentException if no constant with the specified name was found. • System.out.println(ProgramLanguages.valueOf("JAVA"));
  • 14. Points to remember about Enumerations Enumerations are of class type, and have all the capabilities that a Java class has. Enumerations can have Constructors, instance Variables, methods and can even implement Interfaces. Enumerations are not instantiated using new keyword.
  • 15. enum with Inheritance • The Java enum class is a special class that allows you to create a group of constant values (also known as enumerations) • The enum class is compiled as a final class in Java, so you can’t extend an enum class in your code:
  • 16. Type Wrappers: character, Boolean, the numeric type wrappers • int a = 5 + 10; • Primitive types, rather than objects, are used for these quantities for the sake of performance. Using objects for these values would add an unacceptable overhead to even the simplest of calculations.
  • 17. Type Wrappers: character, Boolean, the numeric type wrappers Thus, the primitive types are not part of the object hierarchy, and they do not inherit the Object. Despite the performance benefit offered by the primitive types, : - there are times when you will need an object representation.
  • 18. wrappers • many of the standard data structures implemented by Java operate on objects, • which means that you can't use these data structures to store the primitive types. • To handle these and other situations, Java provides type wrappers, which are classes that encapsulate a primitive type within an object.
  • 19. The type wrappers • The type wrappers are Integer, Short, Double, Long, Float, Byte, Character, and Boolean. • These classes offer a wide array of methods that allow you to fully integrate the primitive types into the Java's object hierarchy. • Let's examine each.
  • 20. Character • Character is a wrapper around a char. The constructor for the Character is • • char charValue() returns char value.
  • 22. Autoboxing Autoboxing is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes. For example, converting an int to an Integer, a double to a Double, and so on. If the conversion goes the other way, this is called unboxing.
  • 23. Example 1: For Autoboxing and Unboxing • https://www.geeksforgeeks.org/autoboxing-unboxing-java/
  • 24. Autoboxing/Unboxing in Expressions • Java autoboxing and unboxing take place whenever a conversion into an object or from an object is required. • This applies to expressions. • Within an expression, a numeric object is automatically unboxed. • The outcome of the expression is reboxed, if necessary. •
  • 25. Ex: Program below the Note • https://www.demo2s.com/java/java-primitive-data-type-autoboxing- unboxing-in-expressions.html Both programs are valid in above link but you can go for 2nd program and explain it a little.
  • 26. Autoboxing/unboxing Boolean and character values • http://www.java2s.com/Tutorial/Java/0040__Data- Type/AutoboxingUnboxingBooleanandCharacterValues.htm
  • 27. Benefits of Autoboxing / Unboxing 1.Autoboxing / Unboxing lets us use primitive types and Wrapper class objects interchangeably. 2.It helps prevent errors, but may lead to unexpected results sometimes. Hence must be used with care. 3.We don't have to perform Explicit typecasting. 4.Auto-unboxing also allows you to mix different types of numeric objects in an expression. When the values are unboxed, the standard type conversions can be applied.
  • 29. Annotations • Java annotations are metadata (data about data) for our program source code. They provide additional information about the program to the compiler but are not part of the program itself. These annotations do not affect the execution of the compiled program.
  • 30. • Its syntax is: • @AnnotationName • Ex: Annotations start with @.
  • 31. Ex : @Override • The @Override annotation specifies that the method with this annotation overrides the superclass method with the same method name, return type, and parameter list. • It is not mandatory to use @Override when overriding a method. • However, if we use it, the compiler gives an error if something is wrong (such as wrong parameter type) while overriding the method.
  • 32. Example 1: @Override Annotation Example • https://www.programiz.com/java- programming/annotations#:~:text=Java%20annotations%20are%20m etadata%20(data,execution%20of%20the%20compiled%20program. • Check example 1
  • 33. Java Annotations Retention Policy • A retention policy determines at what point an annotation is discarded. • • Java defines three such policies, • They are SOURCE, CLASS, and RUNTIME.
  • 34. @Retention(retention-policy) • A retention policy is specified for an annotation by using one of Java's built-in annotations: @Retention. •
  • 35. SOURCE • An annotation with a retention policy of SOURCE is retained [engaged | activated] only in the source file and is discarded during compilation.
  • 36. CLASS • An annotation with a retention policy of CLASS is stored in the .class file during compilation. • However, it is not available through the JVM during run time.
  • 37. RUNTIME • An annotation with a retention policy of RUNTIME is stored in the .class file during compilation and is available through the JVM during run time. Thus, RUNTIME retention offers the greatest annotation persistence.
  • 38. • Here, retention-policy must be one of the previously discussed enumeration constants. • If no retention policy is specified for an annotation, then the default policy of CLASS is used.
  • 39.
  • 40. Obtaining Annotations at Run Time via Refle ction • If annotations specify a retention policy of RUNTIME, then they can be queried at run time by any Java program through the use of reflection. • • Reflection is the feature that enables information about a class to be obtained at run time.
  • 41. • Reflection is a feature in the Java programming language. It allows an executing Java program to examine or "introspect" upon itself, and manipulate internal properties of the program. • The ability to examine and manipulate a Java class from within itself may not sound like very much, but in other programming languages this feature simply doesn't exist