Found 34494 Articles for Programming

Python program to change the value of a dictionary if it equals K

Niharika Aitam
Updated on 19-Oct-2023 14:38:42

39 Views

Dictionary is one of the data structure available in python to store any datatype of data in the format of key and value pair. It is denoted by {} curly braces. The key in the dictionary is unique and the values in the dictionary can be repeated. The key and values pairs are separated by using the semi colon ‘:’. It is mutable i.e. once the dictionary created, we can modify the data. Dictionaries are versatile and widely used in Python for mapping and storing data where quick access to values based on keys is required. The dictionary is unordered ... Read More

Difference between Inheritance and Interface in Java

Rudradev Das
Updated on 19-Oct-2023 13:22:02

1K+ Views

Inheritance is a Method to create a hierarchy between multiple classes by replicating some properties from others. There are various types of inheritance present in Java, such as single inheritance, multiple inheritance, multilevel inheritance, hybrid inheritance, and hierarchical inheritance. Interface is the blueprint of a particular class which consists of the constant and abstract class. The interface class allows a machine to apply some specific properties on an object or a class. It is totally an abstract method which helps to perform the Java abstraction on a collection by specifying the behavior of a class. Now the task ... Read More

Python program to calculate gross pay

Niharika Aitam
Updated on 19-Oct-2023 14:36:00

177 Views

Basically Gross pay is the total amount paid to an employee for the total time he/she worked, i.e. this is the full amount of salary of an employee before the taxes and deductions. The Gross pay also includes the bonuses, overtime or reimbursements from an employer on top of the salary pay. Mathematically the formula for the gross pay is as follows. Hours worked * pay per hour = gross pay per period For example, if an employee worked for 200 hours in a given period and earned Rs.300/- for an hour then the gross pay will be ... Read More

Difference Between IdentityHashMap, WeakHashMap, and EnumMap in Java

Rudradev Das
Updated on 02-Nov-2023 17:58:08

233 Views

The IdentityHashMap is a special type of hash class by which we handle the rare cases related to the reference-equality. This map compares the keys by using a " = = " operator where the normal hashmap uses the " equals " method for this. A Weak HashMap is a type of map interface where the hash table merges its keys with the weak reference type of values. This type of map class can not be used further just because of the lack of reference pointers. An enum map is a special type of map class which contains only the ... Read More

Python program to calculate square of a given number

Niharika Aitam
Updated on 19-Oct-2023 14:27:05

421 Views

Square is the defined as the multiplication of the number by itself. The square of a number n is given as n2. Mathematically we can implement square of the number as follows. $\mathrm{n^{2}=n*n}$ In the same way we can calculate the square of a given number by using python language too. There are few approaches in python to find the square of a number, let’s see them one by one. Using exponential operator (**) The exponential operator is the operator which is used to perform the exponent arithmetic operation. It is denoted with the symbol **. Syntax The ... Read More

Difference Between Hashtable and Synchronized Map in Java

Rudradev Das
Updated on 02-Nov-2023 18:18:26

196 Views

A HashTable is a compact abstract data set which converts the keys of a map to the values by computing the indexes into an array of slots to enable faster data access. On the other hand, a synchronized map is a Java collection class which is mainly used to synchronize a particular map to make it a thread safe collection and can be applied on a whole object. The map does not contain any null value. Input [ ARB, RDD, KOL, DHKA ] Output Insertion Order of objects in HashTable : [ ARB, RDD, KOL, DHKA ] Insertion Order of objects in Synchronized Map : [ ... Read More

Difference between HashMap and IdentityHashMap in Java

Rudradev Das
Updated on 02-Nov-2023 18:20:39

127 Views

HashMap and IdentityHashMap are the key value data sets which are used to access the key data pairs. More specifically. A HashMap is a Java collection framework which provides the functionality of a proper hash table data set. The map stores the element value as a key or pairs which are the unique identifiers in nature. This map also permits the null values as a non synchronized class. The IdentityHashMap is a special type of hash class by which we handle the rare cases related to the reference-equality. This map compare the keys by using a " = = " operator ... Read More

Difference and similarities between HashSet , LinkedHashSet and TreeSet in Java

Rudradev Das
Updated on 02-Nov-2023 17:50:59

172 Views

The HashSet, LinkedHashSet and TreeSet are the set interface class mainly used to store the elements. HashSet − A HashSet is a container instance which stores the unique elements only in a non synchronized manner to handle the high-performance operations involving with the set. The set allows the null values which does not follow the order of insertion. LinkedHashSet − The LinkedHashSet is a cloned data structure which have the both facilities of a hashtable and linked list as a set interface. The ordered version of a LinkedHashSet always works as a doubly linked list on over the input elements. TreeSet ... Read More

Python program to calculate Date, Month and Year from Seconds

Niharika Aitam
Updated on 19-Oct-2023 14:23:07

287 Views

Generally, time is given in hours or minutes or seconds and from the given seconds, we can calculate the number of days, months and years. There are different modules and functions available in python such as datetime, time and divmod() which helps us to calculate the date month and year from seconds. Using Datatime module Datetime module offers classes to manipulate the dates and times. This module provides various functions and methods such as date, time, datetime, timedelta, minyear, maxyear, UTC etc. In the datetime method of datetime module we have the function utcfromtimestamp() which takes the seconds as ... Read More

Python program to calculate age in year

Niharika Aitam
Updated on 19-Oct-2023 14:20:56

6K+ Views

Generally, the age of a person is calculated by subtracting the birth year with the current year then the age of the person will be generated in years. In the same way we can calculate the age of a person by using the python modules datetime, dateutil and timedelta. General Calculation of Age in years Current year - Birth year Example In this example we are implementing the general way of calculating the age using pythn language by passing the current year and birth years as the inputs to created function age_calculator() then the total age will be generated ... Read More

Advertisements