Data types and variables in java

Publié le: 23 janvier 2020
sur la chaîne: Axe break saw
6
1

Data Types

So far, the only data our programs have used are Strings of characters contained within double quotes, like "Hello, world!". Computers process many different types of data: numbers, pictures, sound, etc. Java is very strict about defining exactly what type of data it is using at all times.

Java defines a few very simple and efficient primitive data types. There are eight of these in total, but we’re going to focus on just four of them:

Integer

Integers represent whole numbers. You may be familiar with integers from algebra class. Integers are numbers that are not fractions nor have decimals, for example, 422, -13 and 0. Java refers to these as type int. As computer memory is not infinitely big there is a limit to how big an integer you can store. The largest int that Java can represent is actually 2,147,483,647, and the smallest is -2,147,483,648. This is big enough for most purposes, but note that it’s only about ¼ the population of Earth, so there will be situations in which using an int won't work.

Double

Doubles are real numbers like 3.14159, -2.718, and 2145.2731. You can also write these in a form of scientific notation; for example, 1.23e2 is the same as 123, and 921e-1 is 92.1. For historical reasons, Java calls these typedouble. These can represent much bigger and smaller numbers, but they are in general only approximations, not exact values as they can only hold so many decimal places. This can lead to rounding errors when you might not expect them!

Character

Characters are single characters such as letters, symbols and spaces. These are not just limited to english, but all languages. For example, A, X, 0, z, ?, and =, but also Ω, ä, Я, and many more! Each of these is a char in Java. When you define a char, enclose it in single quotes, like 'a'. String objects are made up of char characters. NOTE: 'a' is NOT the same as "a": the first is a char, the second is a String that contains a single char.

Boolean

Booleans are a type of data that can only have either two values: True or False. Booleans are the building block for logic based decisions, you can think of them as representing yes or no, on or off, positive or negative, etc... Java calls these boolean values, in honor of George Boole who created a theory of algebra for numbers with only two values.


Sur cette page du site, vous pouvez voir la vidéo en ligne Data types and variables in java durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Axe break saw 23 janvier 2020, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 6 fois et il a aimé 1 téléspectateurs. Bon visionnage!