saving . . . saved Other numerical datatypes in Java has been deleted. Other numerical datatypes in Java has been hidden .
Other numerical datatypes in Java
Title
Question
Other numerical datatypes in Java

Java Numerical-Datatypes 03-04 min 0-10 sec 06-10-23, 11:22 p.m. Pritesh12378i

Answers:


<a aria-label="Menu" class="tnb-menu-btn w3-bar-item w3-button bar-item-hover w3-padding-16 ga-top ga-top-menu" role="button" style="box-sizing: inherit; color: inherit; border: none; display: block; padding: 8px; vertical-align: middle; overflow: hidden; text-align: center; cursor: pointer; user-select: none; float: left; width: 76px; outline: 0px;" title="Menu">
<span aria-hidden="true" class="fa fa-caret-down" style="box-sizing: inherit; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-stretch: normal; font-size: 15px; line-height: 1; font-family: fontawesome; text-rendering: auto; -webkit-font-smoothing: antialiased; transform: translate(0px, 0px);"></span></a>
<svg fill="none" viewBox="0 0 17 16" xmlns:xmlns="http://www.w3.org/2000/svg"><path d="M11.8153 10.3439C12.6061 9.2673 13.0732 7.9382 13.0732 6.5C13.0732 2.91015 10.163 0 6.57318 0C2.98333 0 0.0731812 2.91015 0.0731812 6.5C0.0731812 10.0899 2.98333 13 6.57318 13C8.01176 13 9.3412 12.5327 10.4179 11.7415L10.4171 11.7422C10.4466 11.7822 10.4794 11.8204 10.5156 11.8566L14.3661 15.7071C14.7566 16.0976 15.3898 16.0976 15.7803 15.7071C16.1708 15.3166 16.1708 14.6834 15.7803 14.2929L11.9298 10.4424C11.8936 10.4062 11.8553 10.3734 11.8153 10.3439ZM12.0732 6.5C12.0732 9.53757 9.61075 12 6.57318 12C3.53561 12 1.07318 9.53757 1.07318 6.5C1.07318 3.46243 3.53561 1 6.57318 1C9.61075 1 12.0732 3.46243 12.0732 6.5Z" fill="currentColor"></path></svg>

<a aria-label="Login to your account" class="user-anonymous tnb-login-btn w3-bar-item w3-btn bar-item-hover w3-right ws-light-green ga-top ga-top-login" href="https://profile.w3schools.com/log-in?redirect_url=https%3A%2F%2Fmy-learning.w3schools.com" style="box-sizing: inherit; background-color: rgb(4, 170, 109); color: rgb(255, 255, 255); border: none; display: block; padding: 8px 16px; vertical-align: middle; overflow: hidden; text-align: center; cursor: pointer; text-wrap: nowrap; user-select: none; float: left; width: 93px; outline: 0px; margin: -20px 10px 56px 100px; position: relative; height: 40px; top: 28px; border-radius: 25px; line-height: 1.5; z-index: 4;" title="Login to your account">
</a><a aria-label="Sign Up to Improve Your Learning Experience" class="user-anonymous tnb-signup-btn w3-bar-item w3-button w3-right ws-green ws-hover-green ga-top ga-top-signup" href="https://www.w3schools.com/signup/index.php" style="box-sizing: inherit; border: none; display: block; padding: 8px 16px; vertical-align: middle; overflow: hidden; text-align: center; cursor: pointer; user-select: none; float: left; width: 93px; outline: 0px; margin: -20px -39px 56px 0px; position: relative; height: 40px; top: 28px; border-radius: 25px; line-height: 1.5; z-index: 5; background-color: rgb(4, 170, 109) !important; color: white !important;" title="Sign Up to Improve Your Learning Experience">Sign Up</a><a aria-label="W3Schools Certificates" class="user-anonymous tnb-certificates-btn w3-bar-item w3-button w3-right w3-white ga-top ga-top-certificates" href="https://campus.w3schools.com/collections/course-catalog" style="box-sizing: inherit; border: none; display: block; padding: 8px 16px; vertical-align: middle; overflow: hidden; text-align: center; cursor: pointer; user-select: none; float: left; width: auto; outline: 0px; margin: -20px 10px 56px 0px; position: relative; height: 40px; top: 28px; border-radius: 25px; background-color: rgb(255, 255, 255) !important; color: rgb(0, 0, 0) !important;" target="_blank" title="W3Schools Certificates"><svg aria-hidden="true" height="1em" viewBox="0 0 576 512" xmlns:xmlns="http://www.w3.org/2000/svg"><path d="M24 0C10.7 0 0 10.7 0 24S10.7 48 24 48H69.5c3.8 0 7.1 2.7 7.9 6.5l51.6 271c6.5 34 36.2 58.5 70.7 58.5H488c13.3 0 24-10.7 24-24s-10.7-24-24-24H199.7c-11.5 0-21.4-8.2-23.6-19.5L170.7 288H459.2c32.6 0 61.1-21.8 69.5-53.3l41-152.3C576.6 57 557.4 32 531.1 32h-411C111 12.8 91.6 0 69.5 0H24zM131.1 80H520.7L482.4 222.2c-2.8 10.5-12.3 17.8-23.2 17.8H161.6L131.1 80zM176 512a48 48 0 1 0 0-96 48 48 0 1 0 0 96zm336-48a48 48 0 1 0 -96 0 48 48 0 1 0 96 0z" fill="currentColor"></path></svg> Certificates</a><a aria-label="Get Your Own Website With W3Schools Spaces" class="user-anonymous tnb-spaces-btn w3-bar-item w3-button w3-right w3-white ga-top ga-top-spaces" href="https://www.w3schools.com/spaces/index.php" style="box-sizing: inherit; border: none; display: block; padding: 8px 16px; vertical-align: middle; overflow: hidden; text-align: center; cursor: pointer; user-select: none; float: left; outline: 0px; margin: -20px 10px 56px 0px; position: relative; height: 40px; top: 28px; border-radius: 25px; background-color: rgb(255, 255, 255) !important; color: rgb(0, 0, 0) !important; width: auto !important;" title="Get Your Own Website With W3Schools Spaces"><svg aria-hidden="true" height="1em" viewBox="0 0 640 512" xmlns:xmlns="http://www.w3.org/2000/svg"><path d="M392.8 1.2c-17-4.9-34.7 5-39.6 22l-128 448c-4.9 17 5 34.7 22 39.6s34.7-5 39.6-22l128-448c4.9-17-5-34.7-22-39.6zm80.6 120.1c-12.5 12.5-12.5 32.8 0 45.3L562.7 256l-89.4 89.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l112-112c12.5-12.5 12.5-32.8 0-45.3l-112-112c-12.5-12.5-32.8-12.5-45.3 0zm-306.7 0c-12.5-12.5-32.8-12.5-45.3 0l-112 112c-12.5 12.5-12.5 32.8 0 45.3l112 112c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L77.3 256l89.4-89.4c12.5-12.5 12.5-32.8 0-45.3z" fill="currentColor"></path></svg> </a><a class="ga-nav" href="https://www.w3schools.com/datascience/default.asp" style="letter-spacing: 1px; text-wrap: nowrap; box-sizing: inherit; color: inherit; display: inline-block; width: auto; line-height: 1.5; margin: 0px !important; padding: 5px 15px !important; font-size: 15px !important;" title="Data science Tutorial"> SCIENCE</a><span style="background-color: rgb(40, 42, 53); color: rgb(241, 241, 241); font-size: 0px; letter-spacing: 1px; text-wrap: nowrap;"> </span>
<a style="box-sizing: inherit; color: inherit; display: inline-block; width: 50px; line-height: 1.5; visibility: hidden; margin: 0px !important; padding: 5px 15px !important; font-size: 15px !important;"></a>
<iframe aria-label="Advertisement" data-google-container-id="1" data-load-complete="true" frameborder="0" height="50" id="google_ads_iframe_/22152718,16833175/sws-hb//w3schools.com//main_leaderboard_0" marginheight="0" marginwidth="0" name="google_ads_iframe_/22152718,16833175/sws-hb//w3schools.com//main_leaderboard_0" role="region" scrolling="no" style="box-sizing: inherit; border-width: 0px; border-style: initial; vertical-align: bottom;" tabindex="0" title="3rd party ad content" width="320"></iframe>
<a class="w3-right w3-btn" href="https://www.w3schools.com/java/java_data_types_numbers.asp" style="box-sizing: inherit; background-color: rgb(4, 170, 109); color: rgb(255, 255, 255); border: 1px solid rgb(4, 170, 109); display: inline-block; padding: 8px 19px; vertical-align: middle; overflow: hidden; text-align: center; cursor: pointer; text-wrap: nowrap; user-select: none; font-size: 18px; font-family: &quot;Source Sans Pro&quot;, sans-serif; border-radius: 5px; float: right !important;">
</a>

As explained in the previous chapter, a <a href="https://www.w3schools.com/java/java_variables.asp" style="box-sizing: inherit; color: inherit;">variable</a> in Java  be a specified data type:

<h3 style="box-sizing: inherit; font-size: 24px; font-family: &quot;Segoe UI&quot;, Arial, sans-serif; margin: 10px 0px;">Example<a class="ws-black ws-hover-black spaces-tryit ga-featured" href="https://www.w3schools.com/spaces/" style="box-sizing: inherit; position: relative; margin-right: 0px; overflow: visible; margin-bottom: 5px; float: right; border-radius: 5px; font-size: 17px; font-family: &quot;Source Sans Pro&quot;, sans-serif; padding: 6px 18px; background-color: rgb(40, 42, 53) !important; color: white !important;" target="_blank" title="W3Schools Spaces">Get your own Java Server</a></h3><pre class="w3-white language-java" style="box-sizing: inherit; font-family: Consolas, &quot;Source Code Pro&quot;, Menlo, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; font-size: 1em; color: black; text-wrap: nowrap; word-spacing: normal; word-break: normal; overflow-wrap: normal; line-height: 1.5; tab-size: 2; hyphens: none; padding: 1em; margin-top: 1em; margin-bottom: 1em; overflow: auto; border-left-width: 4px; border-left-color: rgb(4, 170, 109); background: rgb(255, 255, 255) !important;" tabindex="0"><code class="language-java" style="box-sizing: inherit; font-family: Consolas, &quot;Source Code Pro&quot;, Menlo, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; font-size: 1em; color: black; background-image: none; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; text-wrap: nowrap; word-spacing: normal; word-break: normal; overflow-wrap: normal; line-height: 1.5; tab-size: 2; hyphens: none;"><span class="token keyword keyword-int" style="box-sizing: inherit; color: rgb(0, 119, 170);">int</span> myNum <span class="token operator" style="box-sizing: inherit; color: rgb(154, 110, 58);">=</span> <span class="token number" style="box-sizing: inherit; color: rgb(153, 0, 85);">5</span><span class="token punctuation" style="box-sizing: inherit; color: rgb(153, 153, 153);">;</span> <span class="token comment" style="box-sizing: inherit; color: slategray;">// Integer (whole number)</span> <span class="token keyword keyword-float" style="box-sizing: inherit; color: rgb(0, 119, 170);">float</span> myFloatNum <span class="token operator" style="box-sizing: inherit; color: rgb(154, 110, 58);">=</span> <span class="token number" style="box-sizing: inherit; color: rgb(153, 0, 85);">5.99f</span><span class="token punctuation" style="box-sizing: inherit; color: rgb(153, 153, 153);">;</span> <span class="token comment" style="box-sizing: inherit; color: slategray;">// Floating point number</span> <span class="token keyword keyword-char" style="box-sizing: inherit; color: rgb(0, 119, 170);">char</span> myLetter <span class="token operator" style="box-sizing: inherit; color: rgb(154, 110, 58);">=</span> <span class="token char" style="box-sizing: inherit; color: rgb(102, 153, 0);">'D'</span><span class="token punctuation" style="box-sizing: inherit; color: rgb(153, 153, 153);">;</span> <span class="token comment" style="box-sizing: inherit; color: slategray;">// Character</span> <span class="token keyword keyword-boolean" style="box-sizing: inherit; color: rgb(0, 119, 170);">boolean</span> myBool <span class="token operator" style="box-sizing: inherit; color: rgb(154, 110, 58);">=</span> <span class="token boolean" style="box-sizing: inherit; color: rgb(153, 0, 85);">true</span><span class="token punctuation" style="box-sizing: inherit; color: rgb(153, 153, 153);">;</span> <span class="token comment" style="box-sizing: inherit; color: slategray;">// Boolean</span> <span class="token class-name" style="box-sizing: inherit; color: rgb(221, 74, 104);">String</span> myText <span class="token operator" style="box-sizing: inherit; color: rgb(154, 110, 58);">=</span> <span class="token string" style="box-sizing: inherit; color: rgb(102, 153, 0);">"Hello"</span><span class="token punctuation" style="box-sizing: inherit; color: rgb(153, 153, 153);">;</span> <span class="token comment" style="box-sizing: inherit; color: slategray;">// Strin</span> </code></pre>


Data types are divided into two groups:

<ul style="box-sizing: inherit;"><li style="box-sizing: inherit;">Primitive data types - includes <code class="w3-codespan" style="box-sizing: inherit; font-family: &quot;Source Code Pro&quot;, Menlo, Consolas, monospace; font-size: 15.75px; color: crimson; background-color: rgba(222, 222, 222, 0.3);">byte</code>, <code class="w3-codespan" style="box-sizing: inherit; font-family: &quot;Source Code Pro&quot;, Menlo, Consolas, monospace; font-size: 15.75px; color: crimson; background-color: rgba(222, 222, 222, 0.3);">short</code>, <code class="w3-codespan" style="box-sizing: inherit; font-family: &quot;Source Code Pro&quot;, Menlo, Consolas, monospace; font-size: 15.75px; color: crimson; background-color: rgba(222, 222, 222, 0.3);">int</code>, <code class="w3-codespan" style="box-sizing: inherit; font-family: &quot;Source Code Pro&quot;, Menlo, Consolas, monospace; font-size: 15.75px; color: crimson; background-color: rgba(222, 222, 222, 0.3);">long</code>, <code class="w3-codespan" style="box-sizing: inherit; font-family: &quot;Source Code Pro&quot;, Menlo, Consolas, monospace; font-size: 15.75px; color: crimson; background-color: rgba(222, 222, 222, 0.3);">float</code>, <code class="w3-codespan" style="box-sizing: inherit; font-family: &quot;Source Code Pro&quot;, Menlo, Consolas, monospace; font-size: 15.75px; color: crimson; background-color: rgba(222, 222, 222, 0.3);">double</code>, <code class="w3-codespan" style="box-sizing: inherit; font-family: &quot;Source Code Pro&quot;, Menlo, Consolas, monospace; font-size: 15.75px; color: crimson; background-color: rgba(222, 222, 222, 0.3);">boolean</code> and <code class="w3-codespan" style="box-sizing: inherit; font-family: &quot;Source Code Pro&quot;, Menlo, Consolas, monospace; font-size: 15.75px; color: crimson; background-color: rgba(222, 222, 222, 0.3);">char</code></li><li style="box-sizing: inherit;">Non-primitive data types - such as <code class="w3-codespan" style="box-sizing: inherit; font-family: &quot;Source Code Pro&quot;, Menlo, Consolas, monospace; font-size: 15.75px; color: crimson; background-color: rgba(222, 222, 222, 0.3);"><a href="https://www.w3schools.com/java/java_strings.asp" style="box-sizing: inherit; color: inherit;">String</a></code>, <a href="https://www.w3schools.com/java/java_arrays.asp" style="box-sizing: inherit; color: inherit;">Arrays</a> and <a href="https://www.w3schools.com/java/java_classes.asp" style="box-sizing: inherit; color: inherit;">Classes</a> (you will learn more about these in a later chapter)</li></ul><hr style="overflow: visible; border-top-color: rgb(238, 238, 238); margin: 20px -16px;"><h2 style="box-sizing: inherit; font-size: 25px; font-family: &quot;Segoe UI&quot;, Arial, sans-serif; margin: 10px 0px;">Primitive Data Types</h2>

A primitive data type specifies the size and type of variable values, and it has no additional methods.

There are eight primitive data types in Java:

<table class="ws-table-all notranslate" style="box-sizing: inherit; width: 351.5px; border: 1px solid rgb(204, 204, 204); margin: 20px 0px;"><tbody style="box-sizing: inherit;"><tr style="box-sizing: inherit; border-bottom: 1px solid rgb(221, 221, 221);"><th style="box-sizing: inherit; padding: 8px 8px 8px 16px; vertical-align: top; width: 99px;">Data Type</th><th style="box-sizing: inherit; padding: 8px; vertical-align: top; width: 52.5px;">Size</th><th style="box-sizing: inherit; padding: 8px; vertical-align: top; width: 199px;">Description</th></tr><tr style="box-sizing: inherit; border-bottom: 1px solid rgb(221, 221, 221); background-color: rgb(231, 233, 235);"><td style="box-sizing: inherit; padding: 8px 8px 8px 16px; vertical-align: top;"><code class="w3-codespan" style="box-sizing: inherit; font-family: &quot;Source Code Pro&quot;, Menlo, Consolas, monospace; font-size: 15.75px; color: crimson; background-color: rgba(222, 222, 222, 0.3);">byte</code></td><td style="box-sizing: inherit; padding: 8px; vertical-align: top;">1 byte</td><td style="box-sizing: inherit; padding: 8px; vertical-align: top;">Stores whole numbers from -128 to 127</td></tr><tr style="box-sizing: inherit; border-bottom: 1px solid rgb(221, 221, 221);"><td style="box-sizing: inherit; padding: 8px 8px 8px 16px; vertical-align: top;"><code class="w3-codespan" style="box-sizing: inherit; font-family: &quot;Source Code Pro&quot;, Menlo, Consolas, monospace; font-size: 15.75px; color: crimson; background-color: rgba(222, 222, 222, 0.3);">short</code></td><td style="box-sizing: inherit; padding: 8px; vertical-align: top;">2 bytes</td><td style="box-sizing: inherit; padding: 8px; vertical-align: top;">Stores whole numbers from -32,768 to 32,767</td></tr><tr style="box-sizing: inherit; border-bottom: 1px solid rgb(221, 221, 221); background-color: rgb(231, 233, 235);"><td style="box-sizing: inherit; padding: 8px 8px 8px 16px; vertical-align: top;"><code class="w3-codespan" style="box-sizing: inherit; font-family: &quot;Source Code Pro&quot;, Menlo, Consolas, monospace; font-size: 15.75px; color: crimson; background-color: rgba(222, 222, 222, 0.3);">int</code></td><td style="box-sizing: inherit; padding: 8px; vertical-align: top;">4 bytes</td><td style="box-sizing: inherit; padding: 8px; vertical-align: top;">Stores whole numbers from -2,147,483,648 to 2,147,483,647</td></tr><tr style="box-sizing: inherit; border-bottom: 1px solid rgb(221, 221, 221);"><td style="box-sizing: inherit; padding: 8px 8px 8px 16px; vertical-align: top;"><code class="w3-codespan" style="box-sizing: inherit; font-family: &quot;Source Code Pro&quot;, Menlo, Consolas, monospace; font-size: 15.75px; color: crimson; background-color: rgba(222, 222, 222, 0.3);">long</code></td><td style="box-sizing: inherit; padding: 8px; vertical-align: top;">8 bytes</td><td style="box-sizing: inherit; padding: 8px; vertical-align: top;">Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807</td></tr><tr style="box-sizing: inherit; border-bottom: 1px solid rgb(221, 221, 221); background-color: rgb(231, 233, 235);"><td style="box-sizing: inherit; padding: 8px 8px 8px 16px; vertical-align: top;"><code class="w3-codespan" style="box-sizing: inherit; font-family: &quot;Source Code Pro&quot;, Menlo, Consolas, monospace; font-size: 15.75px; color: crimson; background-color: rgba(222, 222, 222, 0.3);">float</code></td><td style="box-sizing: inherit; padding: 8px; vertical-align: top;">4 bytes</td><td style="box-sizing: inherit; padding: 8px; vertical-align: top;">Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits</td></tr><tr style="box-sizing: inherit; border-bottom: 1px solid rgb(221, 221, 221);"><td style="box-sizing: inherit; padding: 8px 8px 8px 16px; vertical-align: top;"><code class="w3-codespan" style="box-sizing: inherit; font-family: &quot;Source Code Pro&quot;, Menlo, Consolas, monospace; font-size: 15.75px; color: crimson; background-color: rgba(222, 222, 222, 0.3);">double</code></td><td style="box-sizing: inherit; padding: 8px; vertical-align: top;">8 bytes</td><td style="box-sizing: inherit; padding: 8px; vertical-align: top;">Stores fractional numbers. Sufficient for storing 15 decimal digits</td></tr><tr style="box-sizing: inherit; border-bottom: 1px solid rgb(221, 221, 221); background-color: rgb(231, 233, 235);"><td style="box-sizing: inherit; padding: 8px 8px 8px 16px; vertical-align: top;"><code class="w3-codespan" style="box-sizing: inherit; font-family: &quot;Source Code Pro&quot;, Menlo, Consolas, monospace; font-size: 15.75px; color: crimson; background-color: rgba(222, 222, 222, 0.3);">boolean</code></td><td style="box-sizing: inherit; padding: 8px; vertical-align: top;">1 bit</td><td style="box-sizing: inherit; padding: 8px; vertical-align: top;">Stores true or false values</td></tr><tr style="box-sizing: inherit; border-bottom: 1px solid rgb(221, 221, 221);"><td style="box-sizing: inherit; padding: 8px 8px 8px 16px; vertical-align: top;"><code class="w3-codespan" style="box-sizing: inherit; font-family: &quot;Source Code Pro&quot;, Menlo, Consolas, monospace; font-size: 15.75px; color: crimson; background-color: rgba(222, 222, 222, 0.3);">char</code></td><td style="box-sizing: inherit; padding: 8px; vertical-align: top;">2 bytes</td><td style="box-sizing: inherit; padding: 8px; vertical-align: top;">Stores a single character/letter or ASCII values</td></tr></tbody></table>
06-10-23, 11:27 p.m. Pritesh12378i


Log-in to answer to this question.