In programming and for databases, data types are used to specify the type of a variable. This also determines, for example, which operations can be performed with these variables and which lead to errors. For example, when storing a text, mathematical operations such as additions are not possible.
What are Data Types?
In computer science, one defines data types for which a certain set of operations is possible without problems. With all data, which belong to a data type, these operations can be accomplished and it is ensured that no error message occurs.
For example, for the “Integer” data type, the “Add” and “Subtract” operations are defined. This means that if we have any two elements of the “Integers” data type, then they can add or subtract and no error will occur. On the other hand, two objects of the “Text” data type cannot perform this operation because this is not defined for the data type.
What do you use Data Types for?
The use of data types makes it possible to perform certain operations between several variables in programming. For each data type, certain calculations or transformations are defined, which can be executed with another variable of the same data type without problems.
To make sure that runtime errors cannot occur during operations with multiple variables, one uses the so-called type system.
What is the Type System in Computer Science?
The Type System is the term used in computer science to describe the possibility of restricting the value ranges of a variable within a programming language. A programming language, which has a type system, is called typed. These systems can be classified into a total of three classes:
- Strong vs. Weak: This is about how strictly the respective programming language distinguishes the types. For example, strict type systems do not allow variables to be converted to another data type after the variable has been defined.
- Dynamic vs. Static: This dimension is about when the typing of the object takes place. For example, in Python, the variable itself does not have a data type, only the object that is assigned to the variable does. This is called dynamic typing. However, this also means that errors due to incompatible data types are not detected until the entire program is started. With static typing (for example in Java), the data type of the variables must be explicitly defined while writing the program.
- Explicit vs. Implicit: This dimension is closely interwoven with static/dynamic typing. It is a question of whether the data type of a variable is already explicitly specified during the definition, or is only implicitly recognizable via the assignment of the object.
General Data Types
Depending on the programming language or database, different data types are defined, which is why the names can also differ slightly. However, the general data types are very similar between different systems and programming languages.
Integers are used for numbers, i.e. for positive and negative numbers without decimal places, for example, -841 or +903.
Floating Point (Float)
The float data type is also used for numeric variables, but unlike integers, they also have decimal numbers, e.g. -130.45 or +923.58923.
The string in turn denotes textual variables whose values are stored in quotation marks, i.e. ” ” or ‘ ‘. In addition to character strings consisting of letters, the string can also store numbers or other symbols. However, these are not interpreted as numbers, which means that no arithmetic operations are possible with them.
Boolean data types are used when a variable can take exactly one of two possible values. In many cases either the value pairs, 0/1 or true/false is used.
The Datetime data type stores values that contain a date including a time, such as 2021-09-12 15:23:41, so the format used for this is YYYY-MM-DD hh:mm:ss.
The timestamp is another way to store temporal information in a variable. The most common is the so-called Unix Timestamp, which measures how many seconds (depending on the format also milliseconds) have passed since 01/01/1970.
This data type is used to store single letters, symbols, numbers, etc.. It is also possible to store a single space character.
This is what you should take with you
- Data types are used to define the type of a variable. This also determines which operations are possible with the variable and which are not.
- Typing is the ability to restrict the value ranges of a variable.
- In general, there are the data types Integer, Floating Point, String, Boolean, Datetime Timestamp, and Character. In addition, there are more defined data types, which can vary depending on the programming language or database.
Explanation of the Apache Hadoop Distributed File System with examples and benefits.
Other Articles on the Topic of Data Types
- On this page, you will find an overview of all data types in the Python programming language and useful commands on how to define or change them.