Facing Issues On IT

Search
Skip to content
  • Tutorials
  • Springboot & REST
  • Issues & Solutions
  • Sample Code
  • Interview Preparation
Java

Java: Package Class

17 Sep 2019 Saurabh Gupta Leave a comment

The Package Objects contains version information about the implementation and specification of Java Package. This information stored in the manifest and distributed among classes. It can be loaded by ClassLoader that loads the classes.

Information can be retrieved like:

  • Specification Title
  • Version number
  • Vendor
  • Check compatibility with a particular package.

Methods of Java Package Class

Modifier and Type Method and Description
A getAnnotation(Class annotationClass) Returns this element’s annotation for the specified type if such an annotation is present, else null.
Annotation[] getAnnotations() Returns annotations that are present on this element.

A[] getAnnotationsByType(Class annotationClass)
Returns annotations that are associated with this element.

A getDeclaredAnnotation(Class annotationClass)
Returns this element’s annotation for the specified type if such an annotation is directly present, else null.
Annotation[] getDeclaredAnnotations() Returns annotations that are directly present on this element.
A[] getDeclaredAnnotationsByType(Class annotationClass) Returns this element’s annotation(s) for the specified type if such annotations are either directly present or indirectly present.
String getImplementationTitle() Return the title of this package.
String getImplementationVendor() Returns the name of the organization, vendor or company that provided this implementation.
String getImplementationVersion() Return the version of this implementation.
String getName() Return the name of this package.
static Package getPackage(String name) Find a package instance by pacakge name in the callers ClassLoader instance.
static Package[] getPackages() Return array of packages currently known for the caller’s ClassLoader instance.
String getSpecificationTitle() Return the title of the specification that this package implements.
String getSpecificationVendor() Return the name of the organization, vendor, or company that owns and maintains the specification of the classes that implement this package.
String getSpecificationVersion() Returns the version number of the specification that this package implements.
boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) Returns true if an annotation for the specified type is present on this element, else false.
boolean isCompatibleWith(String desired) Compare this package’s specification version with a desired compatible version.
boolean isSealed() Returns true if this package is sealed.
boolean isSealed(URL url) Returns true if this package is sealed with respect to given code source url.

Package Class Example

public class PackageDetailInfo {

	public static void main(String args[]) {

		String packageName="java.lang";

       System.out.println("=========Package Detail Info :"+"============");
		Package p = Package.getPackage(packageName);

		System.out.println("Package name: " + p.getName());

		System.out.println("Specification Title: " + p.getSpecificationTitle());
		System.out.println("Specification Vendor: " + p.getSpecificationVendor());
		System.out.println("Specification Version: " + p.getSpecificationVersion());

		System.out.println("Implementaion Title: " + p.getImplementationTitle());
		System.out.println("Implementation Vendor: " + p.getImplementationVendor());
		System.out.println("Implementation Version: " + p.getImplementationVersion());
		System.out.println("Is sealed: " + p.isSealed());

	}
}

Output


=========Package Detail Info :============
Package name: java.lang
Specification Title: Java Platform API Specification
Specification Vendor: Oracle Corporation
Specification Version: 1.8
Implementaion Title: Java Runtime Environment
Implementation Vendor: Oracle Corporation
Implementation Version: 1.8.0_191
Is sealed: false

References

  • https://docs.oracle.com/javase/8/docs/api/java/lang/Package.html

Share this post with others:

  • More
  • Tweet

Like this:

Like Loading...

Related

Java ClassLoaderJava menifest fileJava package class exampleJava Package DetailJava Package metadataJava SpecificationJava version Number

Post navigation

Previous PostJava: Method SignatureNext PostJava: Method Overloading

You must log in to post a comment.

Blogs By Category

Advertisements

Top Posts & Pages

  • [Solved] javax.crypto.AEADBadTagException: Tag mismatch
  • [Solved] Java UnsupportedClassVersionError : Compiled by a more recent version of the Java Runtime (class file version X), this version of the Java Runtime only recognizes class file versions up to Y
  • [Solved]: Maven Error "Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project XYZ: There are test failures."
  • [Solved] Spring Data JPA :QueryCreationException: Could not create query for public abstract method XYZ
  • [Solved] SQLServerException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
Advertisements

Recommendations

  • Java: Coding & Review Best Practices
  • JDBC Coding Best Practices
  • Spring Boot + REST Tutorial
Advertisements

Interview Questions and Answers

  • Elasticsearch Interview Questions and Answers
  • Java: Interview Questions and Answers
  • JDBC Interview Questions And Answers
  • Spring Boot + REST Tutorial
  • [100+] Frequently Asked Java Program
Advertisements
Advertisements

“Learn From Others Experience"

Java Tutorial

Java Tutorial


Java :Overview and Setup
  • Java Overview
  • Java Evaluation
  • Environment Setup
  • Upgrade JDK in Eclipse
  • "Hello World" Program
  • Program Execution
  • Execution Steps
  • main() Variations
  • JIT,JDK,JRE,SDK,JVM

Java Keywords
Java Data Types
  • Primitive Type
  • Non-Primitive Type

Java Variable & Literals
Java Idnetifiers
Java Statements
  • Blocks
  • Empty Statements
  • Declaration Statements
  • Expression Statements
  • Control Flow Statement
    • Decision Making
      • if
      • if-else
      • if-else if
      • switch
    • Looping
      • for loop
      • while loop
      • do-while loop
      • for-each loop
    • Branching
      • break
      • continue
      • return
Reachability of Statements
Java Operators
  • Unary Operators
  • Arithmatic Operators
  • Relational Operators
  • Conditional Operators
  • Bitwise Shift Operators
  • Logical Operators
  • Assignment Operators
  • Instanceof Operators
  • Boolean Operators
  • Ternary Operators
  • Operators Precedence

Java Comments
Java Documentation
Java OOPS Concepts
  • Naming Convention
  • Java Object
  • Java Class
  • Object Cretaion Ways
  • Type of Classes
  • Constructor
  • static keyword
  • this keyword

Java Inheritance
  • Inheritance(IS-A)
  • Aggregation(HAS-A)
  • Aggregation Vs Composition
  • super keyword
  • Constructor Chaining

Java Polymorphism
  • Method Overloading
  • Compiletime Polymorphism
  • Method Overriding
  • Runtime Polymorphism
  • Overloading vs Overriding
  • Covariant Return Type
  • Instance Initializer Block
  • final Keyword
  • Dynamic Binding
  • instanceof Operator

Java Abstraction
  • Abstract Class
  • Interface
  • Nested Interface
  • Marker Interface
  • Abstract Vs Interface

Java Encapsulation
  • Package
  • Import
  • Access Modifiers

OOPS Misll.
  • Java Object Class
  • Object Cloning
  • Shallow Vs Deep Cloning
  • Wrapper Class
    • Byte
    • Short
    • Integer
    • Long
    • Float
    • Double
    • Boolean
    • Character
    • Number
  • strictfp keyword

Java :Array

Java :String Handling

Java :Exception Handling

Java :Collection

Java :Date & Time

Java :IO

Java :Conversion

Java :JDBC

Java :New Features

Java :Interview Questions

Java :Logging

Java :JSON Handling

Java :YAML Handling

Java : Testing

Java :Masking
Masking Tutorial

Log4j Masking
XML Masking
Java Object Masking
Java logs Masking

Web Page Masking


  • SPI
  • Aadhar Number
  • Account Number
  • Credit Card
  • CVV/CVC
  • Date Of Birth
  • Driving License
  • IP
  • ITIN
  • Rounting Number
  • SSN
  • Passport
  • Pincode/Zipcode
JSON Tutorial

JSON Overview
JSON Data Type & Syntax
JSON Java Parsers
JSON + JACKSON
  • JSON to/from Java
  • JSON to/from Java Map
  • JSON Exclude fields
  • JSON file to/from List
  • Dynamic JSON

JSON + GSON
  • GSON Installation
  • JSON Formatting
  • JSON Null Serialization
  • JSON to/from Java

JSON + YAML
  • YAML Vs JSON
  • YAML to/from JSON
  • YAML to/from JSON List

JSON SPI Masking
Log4j JSON Configuration
JSON Issues Solutions
YAML Tutorial

YAML Introduction
YAML Supporting Language and Tools
Enable YAML Editor in Eclipse
YAML Syntax
YAML Validation Online Tools
YAML & JSON
  • YAML to JSON
  • YAML to JSON List
  • JSON vs YAML

Sample filebeat.yml
  • Filebeat Logging
  • Filebeat + Logstash
  • Filebeat + Stacktrace
  • Filebeat + Elasticsearch
  • Filebeat + Kafka
  • Filebeat+ Elasticsearch + Kibana

  • YAML Issues Solutions
JDBC Tutorial

JDBC Overview

Architecture Model

History and Features Evaluations

Drivers Types and Uses

Drivers for Databases

Connect with Database

Connect with Oracle

Connect with MySQL

Connect with Access

Driver Manager Class

Connection Interface

Exception Handling

JDBC : Stored Procedure

JDBC : Function

Differences
Statement Vs PreparedStatement Vs CallableSatement

executeQuery() Vs executeUpdate() Vs execute() method

Stored Procedure vs functions

JDBC Issues & Solutions
[Solved]ClassNotFoundException: org.hsqldb.jdbcDriver

[Solved]java.sql.SQLSyntaxErrorException: unexpected token: XYZ

[Solved]CommunicationsException: Communications link failure

[Solved] SQLException: No suitable driver

[Solved]SQLServerException: Invalid object name ‘dual’

[Solved]SQLSyntaxErrorException: Unknown database ‘database_name’

[Solved]SQLException: ORA-28000: the account is locked

[Solved] MySQLNonTransientConnectionException: Could not create connection to database server.

[Solved]SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near…

[Solved]SQLException: Can’t drop database ‘database_name’; database doesn’t exist


Maven Tutorial

Maven Overview

Maven Installation
  • Install On Window
  • Install On Linux

Add 3rd Party & external jar
Application Creation
  • Java Console Project
  • Dynamic Web Application + Eclipse
Issues & Solutions
  • [Solved] Maven: No compiler is provided in this environment. Perhaps you are running on a JRE rather than a
  • Maven Connect Timeout from/to Central “https://repo.maven.apache.org/maven2”
  • [Solved] Could not transfer artifact org.springframework:XYZ from/to central (https://repo.maven.apache.org/maven2”
  • [Solved] Maven Error On Eclipse/STS : Could Not Calculate Build Plan Org.Apache.Maven.Plugins:maven-Jar-Plugin:jar:2.4
  • [Solved] Maven Error On Eclipse/STS : Failure To Transfer Org.Apache.Maven.Plugins:maven-Surefire-Plugin:pom:2.12.4
Gradle Tutorial


Gradle Overview
Ant vs maven
Maven Vs Gradle
Gradle : Installation
  • Gradle on Window
  • Gradle on Linux/Mac

Gradle : Eclipse/STS Integration
Gradle : Repository
Gradle : Dependency
Gradle : Tasks
Gradle : Logging
Logging Tutorial

Java :Logging
  • Log4j Overview
  • Log4j2 New Features
  • Compare Other Frameworks

Log4J XML Configuration
  • Log4j Dependency
  • Log4j Severity Levels
  • Log4j Log Formatting
  • Log4j Log Appenders
  • Log4j Rolling File Appenders

Log4J JSON Configuration
  • JSON Dependency
  • JSON Configuration

Centralize Logging
  • Integrate Filebeat, Kafka, Logstash, Elasticsearch and Kibana

Logs Masking
  • Mask Logs SPI
  • Mask XML SPI
  • Mask JSON SPI
  • Mask Java Object SPI

Log4J Issues & Solutions
  • [Solved] ClassCastException: SLF4JLoggerContext cannot be cast to org.apache.logging.log4j.core.LoggerContext
JUnit/Mockito Tutorial

  • Software Testing
  • Unit Testing
  • JUnit

JUnit 5
  • JUnit 5: Introduction
  • JUnit 5: Architecture
  • Junit 5: Env Setup
  • JUnit 5: Write Test Case

Mocking Frameworks
  • JUnit + Mockito
  • Exception Hierarchy

Code Coverage
  • JUnit : Code Coverage
  • Code Coverage Plugin

Issues & Solutions
  • Mockito Issues

Best Practices
  • JUnit : Best Practices
Advertisements
Advertisements
Advertisements

Java Tutorial


Java :Overview and Setup
  • Java Overview
  • Java Evaluation
  • Environment Setup
  • Upgrade JDK in Eclipse
  • "Hello World" Program
  • Program Execution
  • Execution Steps
  • main() Variations
  • JIT,JDK,JRE,SDK,JVM

Java Keywords
Java Data Types
  • Primitive Type
  • Non-Primitive Type

Java Variable & Literals
Java Idnetifiers
Java Statements
  • Blocks
  • Empty Statements
  • Declaration Statements
  • Expression Statements
  • Control Flow Statement
    • Decision Making
      • if
      • if-else
      • if-else if
      • switch
    • Looping
      • for loop
      • while loop
      • do-while loop
      • for-each loop
    • Branching
      • break
      • continue
      • return
Reachability of Statements
Java Operators
  • Unary Operators
  • Arithmatic Operators
  • Relational Operators
  • Conditional Operators
  • Bitwise Shift Operators
  • Logical Operators
  • Assignment Operators
  • Instanceof Operators
  • Boolean Operators
  • Ternary Operators
  • Operators Precedence

Java Comments
Java Documentation
Java OOPS Concepts
  • Naming Convention
  • Java Object
  • Java Class
  • Object Cretaion Ways
  • Type of Classes
  • Constructor
  • static keyword
  • this keyword

Java Inheritance
  • Inheritance(IS-A)
  • Aggregation(HAS-A)
  • Aggregation Vs Composition
  • super keyword
  • Constructor Chaining

Java Polymorphism
  • Method Overloading
  • Compiletime Polymorphism
  • Method Overriding
  • Runtime Polymorphism
  • Overloading vs Overriding
  • Covariant Return Type
  • Instance Initializer Block
  • final Keyword
  • Dynamic Binding
  • instanceof Operator

Java Abstraction
  • Abstract Class
  • Interface
  • Nested Interface
  • Marker Interface
  • Abstract Vs Interface

Java Encapsulation
  • Package
  • Import
  • Access Modifiers

OOPS Misll.
  • Java Object Class
  • Object Cloning
  • Shallow Vs Deep Cloning
  • Wrapper Class
    • Byte
    • Short
    • Integer
    • Long
    • Float
    • Double
    • Boolean
    • Character
    • Number
  • strictfp keyword

Java :Array

Java :String Handling

Java :Exception Handling

Java :Collection

Java :Date & Time

Java :IO

Java :Conversion

Java :JDBC

Java :New Features

Java :Interview Questions

Java :Logging

Java :JSON Handling

Java :YAML Handling

Java : Testing

Java :Masking

Tutorials

  • Data Structure and Programming Tutorial
  • Elasticsearch Tutorial
  • Filebeat Tutorial
  • Java : IO Tutorial
  • Java: Date and Time Tutorial
  • Java: Exception Handling Tutorial
  • JDBC Tutorial
  • JSON Tutorial
  • Junit 5 Tutorial
  • Kafka Tutorial
  • Logstash Tutorial
  • Maven Tutorial
  • Mockito + JUnit Tutorial
  • Spring Boot + REST Tutorial
  • TIKA Tutorial
  • YAML Tutorial

Issues Solutions

  • Camel Issues & Solutions
  • Eclipse/STS Issues & Solutions
  • Elasticsearch Issues
  • Filebeat Issues
  • Gradle Issues & Solutions
  • Hibernate Issues & Solutions
  • JAVA Issues and Solutions
  • JAXB Issues & Solutions
  • JDBC Issues and Solutions
  • JSON Issues Solutions
  • Junit/Mockito Issues & Solutions
  • Kafka and Zookeeper Issues
  • Logging/Log4j Issues & Solutions
  • Logstash Issues & Solutions
  • Maven Issues & Solutions
  • MySQL Issues & Solutions
  • OpenShift Issues & Solutions
  • Python Issues & Solutions
  • Spring Boot + REST Tutorial
  • Springboot Data/JPA Issues & Solutions
  • SQL Server Issues & Solutions
  • TIKA Issues and Solutions
  • Tomcat Issues & Solutions
  • YAML Issues

Interview Questions and Answers

  • Elasticsearch Interview Questions and Answers
  • Java: Interview Questions and Answers
  • JDBC Interview Questions And Answers
  • Spring Boot + REST Tutorial
  • [100+] Frequently Asked Java Program

Follow Our Blogs via Email

Enter your email address to follow this blog and receive notifications of our new posts by email.

Join 2,407 other subscribers

Recommendations

  • Java: Coding & Review Best Practices
  • JDBC Coding Best Practices
  • Spring Boot + REST Tutorial
Contact
%d bloggers like this: