GetPackage Return for Primitive or Array in Unnamed Package in Java

Chandu yadav
Updated on 25-Jun-2020 14:01:22

166 Views

The package for a class can be obtained using the java.lang.Class.getPackage() method with the help of the class loader of the class.The getPackage() method returns null for a primitive or array in unnamed package. A program that demonstrates this is given as follows −Example Live Demopublic class Main {    public static void main(String[] argv) throws Exception {       Package pack1 = int.class.getPackage();       System.out.println(pack1);       Package pack2 = int[].class.getPackage();       System.out.println(pack2);    } }Outputnull nullNow let us understand the above program.The getPackage() method is used to obtain the package for the class. ... Read More

Find the Package of an Object in Java

Arjun Thakur
Updated on 25-Jun-2020 14:00:45

1K+ Views

The package for an object of a class can be obtained using the getPackage() method with the help of the class loader of the class. If there is no package object created by the class loader of the class, then null is returned.A program that demonstrates this is given as follows −Example Live Demoimport java.util.ArrayList; import java.util.LinkedList; import java.util.HashSet; public class Main {    public static void main(String[] args) {       System.out.println("The package is: " + new ArrayList().getClass().getPackage().getName());       System.out.println("The package is: " + new LinkedList().getClass().getPackage().getName());       System.out.println("The package is: " + new HashSet().getClass().getPackage().getName());   ... Read More

Check for the Availability of a Package in Java

Ankith Reddy
Updated on 25-Jun-2020 13:59:35

716 Views

The availability can be checked using the method java.lang.Class.forName(). The class object associated with the class with the given string name can be returned using the method java.lang.Class.forName(String name, boolean initialize, ClassLoader loader), using the class loader that is used to load the class.A program that demonstrates this is given as follows −Example Live Demopublic class Main {    public static void main(String args[]) {       System.out.println(Availability("java.lang.String"));    }    public static boolean Availability(String name) {       boolean flag = false;       try {          Class.forName(name, false, null);         ... Read More

Python Support for Gzip Files

Arjun Thakur
Updated on 25-Jun-2020 13:58:33

13K+ Views

GZip application is used for compression and decompression of files. It is a part of GNU project. Python’s gzip module is the interface to GZip application. The gzip data compression algorithm itself is based on zlib module.The gzip module contains definition of GzipFile class along with its methods. It also caontains convenience function open(), compress() and decompress().Easiest way to achieve compression and decompression is by using above mentioned functions.open()This function opens a gzip-compressed file in binary or text mode and returns a file like object, which may be physical file, a string or byte object. By default, the file is ... Read More

MySQL Query to Select Records with a Particular Date and Time

Arjun Thakur
Updated on 25-Jun-2020 13:58:17

2K+ Views

You can use BETWEEN clause from MySQL to select records with a particular date and time. The syntax is as follows.select *from AllRecordsFromadate where AdmissionDate between 'yourDateTimeValue1 ' and ''yourDateTimeValue2';To understand the above syntax, let us first create a table. The query to create a table is as follows.mysql> create table AllRecordsFromadate -> ( -> Id int, -> Name varchar(100), -> Age int, -> AdmissionDate datetime -> ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command. The query to insert records is as follows.mysql> insert into AllRecordsFromadate values(101, 'John', 23, '2018-10-13'); Query OK, ... Read More

Insert NULL Value into INT Column in MySQL

Chandu yadav
Updated on 25-Jun-2020 13:55:09

23K+ Views

You can insert NULL value into an int column with a condition i.e. the column must not have NOT NULL constraints. The syntax is as follows.INSERT INTO yourTableName(yourColumnName) values(NULL);To understand the above syntax, let us first create a table. The query to create a table is as follows.mysql> create table InsertNullDemo -> ( -> StudentId int, -> StudentName varchar(100), -> StudentAge int -> ); Query OK, 0 rows affected (0.53 sec)Here is the query to insert NULL whenever you do not pass any value for column. Here this column is StudentAge. MySQL inserts null value by default. The query to ... Read More

Get Super Class of an Object in Java

George John
Updated on 25-Jun-2020 13:52:19

744 Views

The immediate superclass of any entity such as an object, class, primitive type, interface etc. can be obtained using the method java.lang.Class.getSuperclass(). This method contains no parameters.A program that demonstrates this is given as follows −Example Live Demopublic class Main {    public static void main(String[] args) {       Object obj1 = new String("Hello");       Object obj2 = new Integer(15);       Class c1 = obj1.getClass().getSuperclass();       System.out.println("Super Class = " + c1);       Class c2 = obj2.getClass().getSuperclass();       System.out.println("Super Class = " + c2);    } }OutputSuper Class = ... Read More

Python Context Manager Types

Chandu yadav
Updated on 25-Jun-2020 13:51:46

250 Views

In python, the runtime context is supported by the with statement. The context is defined by the context manager. Using the context manager, we can create user defined classes to define the runtime context. It enters into the task before executing the statement body, and when the statement body is completed, it ends.There are two different methods for context manager. These methods are −Method __enter__()The __enter__() method is used to enter into the runtime context. It will return either the current object or another related object. The returned value is bound to the identifier in as clause of the with ... Read More

Print All Distinct Elements of an Integer Array in Java

karthikeya Boyini
Updated on 25-Jun-2020 13:51:31

7K+ Views

All distinct elements of an array are printed i.e. all the elements in the array are printed only once and duplicate elements are not printed. An example of this is given as follows.Array = 1 5 9 1 4 9 6 5 9 7 Distinct elements of above array = 1 5 9 4 6 7A program that demonstrates this is given as follows.Example Live Demopublic class Example {    public static void main (String[] args) {       int arr[] = {1, 5, 9, 1, 4, 9, 6, 5, 9, 7};       int n = arr.length;   ... Read More

Python Exception Base Classes

Ankith Reddy
Updated on 25-Jun-2020 13:51:15

5K+ Views

Like other high-level languages, there are some exceptions in python also. When a problem occurs, it raises an exception. There are different kind of exceptions like ZeroDivisionError, AssertionError etc. All exception classes are derived from the BaseException class.The code can run built in exceptions, or we can also raise these exceptions in the code. User can derive their own exception from the Exception class, or from any other child class of Exception class.The BaseException is the base class of all other exceptions. User defined classes cannot be directly derived from this class, to derive user defied class, we need to ... Read More

Advertisements