Found 34494 Articles for Programming

Time Functions in Java

karthikeya Boyini
Updated on 26-Jun-2020 06:19:02

679 Views

Java provides the Date class available in java.util package, this class encapsulates the current date and time. The time functions can be accessed from the java.util.Date class. This represents an instance of time with millisecond precision.One of the time function in Java is the getTime() function. It returns the number of milliseconds that have passed since January 1, 1970, 00:00:00 GMT. A program that demonstrates this is given as follows −Example Live Demoimport java.util.*; public class Example {    public static void main(String[] args) {       Date d = new Date(95, 7, 15);       long num = ... Read More

Python Support for bzip2 compression (bz2)

Ankith Reddy
Updated on 26-Jun-2020 06:20:36

2K+ Views

The bzip2 is an open source algorithm for compression and decompression of files. Python’s bz2 module provides functionality to implement bzip2 algorithm programmatically.The open() function is the primary interface to this module.Open()This function opens a bzip2 compressed file and returns a file object. The file can be opened as binary/text mode with read/write permission. The function performs compression based on compressionlevel argument between 1 to 9.write()When the file is opened in ‘w’ or ‘wb’ mode, this function is available to the file object. In binary mode, it writes compressed binary data to the file. In normal text mode, the file ... Read More

Python Support for gzip files (gzip)

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

12K+ 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

Multiplication of two Matrices using Java

Samual Sam
Updated on 26-Jun-2020 06:22:34

4K+ Views

Matrix multiplication leads to a new matrix by multiplying 2 matrices. But this is only possible if the columns of the first matrix are equal to the rows of the second matrix. An example of matrix multiplication with square matrices is given as follows.Example Live Demopublic class Example {    public static void main(String args[]) {       int n = 3;       int[][] a = { {5, 2, 3}, {2, 6, 3}, {6, 9, 1} };       int[][] b = { {2, 7, 5}, {1, 4, 3}, {1, 2, 1} };       int[][] ... Read More

Compression compatible with gzip in Python (zlib)

George John
Updated on 25-Jun-2020 14:02:35

696 Views

The zlib module provides Python’s implementation of Zlib compression library (http://www.zlib.net) which is a part of GNU project.This article discusses important functions defined in zlib module.compress()This function is the primary interface to this module along with decompress() function. This function returns byte object by compressing the data given to it as parameter. The function has another parameter called level which controls the extent of compression. It an integer between 0 to 9. Lowest value 0 stands for no compression and 9 stands for best compression. Higher the level of compression, greater the length of compressed byte object.decompress()This function does the ... Read More

Sort the words in lexicographical order in Java

karthikeya Boyini
Updated on 25-Jun-2020 14:03:52

2K+ Views

The words are sorted in lexicographical order or dictionary order. This means that the words are alphabetically ordered based on their component alphabets. An example of this is given as follows.The original order of the words is Tom Anne Sally John The lexicographical order of the words is Anne John Sally TomA program that demonstrates this is given as follows.Example Live Demopublic class Example {    public static void main(String[] args) {       String[] words = { "Peach", "Orange", "Mango", "Cherry", "Apple" };       int n = 5;       System.out.println("The original order of the words ... Read More

JSON encoder and decoder package in Python

Chandu yadav
Updated on 26-Jun-2020 06:42:28

2K+ Views

JSON stands for JavaScript Object Notation. It is a lightweight data interchange format. It is similar to pickle. However, pickle serialization is Python specific whereas JSON format is implemented by many languages. The json module in Python’s standard library implements object serialization functionality that is similar to pickle and marshal modules.Just as in pickle module, the json module also provides dumps() and loads() function for serialization of Python object into JSON encoded string, and dump() and load() functions write and read serialized Python objects to/from file.dumps()This function converts the object into JSON format.loads()This function converts a JSON string back to ... Read More

Merge two sorted arrays in Java

Samual Sam
Updated on 25-Jun-2020 14:09:13

8K+ Views

Two sorted arrays can be merged so that a single resultant sorted array is obtained. An example of this is given as follows.Array 1 = 1 3 7 9 10 Array 2 = 2 5 8 Merged array = 1 2 3 5 7 8 9 10A program that demonstrates this is given as follows.Example Live Demopublic class Example {    public static void main (String[] args) {       int[] arr1 = {11, 34, 66, 75};       int n1 = arr1.length;       int[] arr2 = {1, 5, 19, 50, 89, 100};       int ... Read More

Reverse words in a given String in Java

karthikeya Boyini
Updated on 25-Jun-2020 14:16:25

4K+ Views

The order of the words in a string can be reversed and the string displayed with the words in reverse order. An example of this is given as follows.String = I love mangoes Reversed string = mangoes love IA program that demonstrates this is given as follows.Example Live Demoimport java.util.regex.Pattern; public class Example {    public static void main(String[] args) {       String str = "the sky is blue";       Pattern p = Pattern.compile("\s");       System.out.println("The original string is: " + str);       String[] temp = p.split(str);       String rev = ... Read More

Reading and Writing CSV File using Python

Ankith Reddy
Updated on 25-Jun-2020 14:14:39

2K+ Views

CSV (stands for comma separated values) format is a commonly used data format used by spreadsheets. The csv module in Python’s standard library presents classes and methods to perform read/write operations on CSV files.writer()This function in csv module returns a writer object that converts data into a delimited string and stores in a file object. The function needs a file object with write permission as a parameter. Every row written in the file issues a newline character. To prevent additional space between lines, newline parameter is set to ‘’.The writer class has following methodswriterow()This function writes items in an iterable ... Read More

Advertisements