Jump to content

Java questions reguarding data types

Go to solution Solved by Satlen,

Unless you need extreme accuracy when doing calculations the main two you will be using is int and double. Integers for when you are working with whole numbers, double with fractions/decimals. 

 

Here is the java doc for different data types http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

 

More info on bits and bytes https://web.stanford.edu/class/cs101/bits-bytes.html

So I am learning java, and I have a few questions

So I understand that int is 32-bit, short is 16-bit and byte is 8-bit,

but what exactly do the bits mean? Is it how much space it can hold or how many characters or what.

Also, why would I use short or byte when I could use int, it holds more in some fashion, and is slightly easier to type.

 

Also why float over double/ vice versa

 

 

Link to comment
https://linustechtips.com/topic/326227-java-questions-reguarding-data-types/
Share on other sites

Link to post
Share on other sites

Unless you need extreme accuracy when doing calculations the main two you will be using is int and double. Integers for when you are working with whole numbers, double with fractions/decimals. 

 

Here is the java doc for different data types http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

 

More info on bits and bytes https://web.stanford.edu/class/cs101/bits-bytes.html

Link to post
Share on other sites

Unless you need extreme accuracy when doing calculations the main two you will be using is int and double. Integers for when you are working with whole numbers, double with fractions/decimals. 

 

Here is the java doc for different data types http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

 

More info on bits and bytes https://web.stanford.edu/class/cs101/bits-bytes.html

 

"Extreme accuracy" is a bit misleading, as it's far more likely that you'll stumble into a situation where int or even long simply aren't large enough. Something as simple as the 100th Fibonacci number is already well into BigInteger at nearly 20 times the maximum value of long.

 

But yes, as the java doc points out, the smaller types are mostly used for conserving memory when dealing with large arrays.

I own and use, sorted from newest to oldest: SteelSeries 6Gv2. Microsoft SideWinder X4. Mionix Naos 7000. Zowie EC1 Evo. Microsoft SideWinder X8. Microsoft IntelliMouse Explorer 3.0. Dell U2414H. Samsung P2270H. AKG K273 Pro. Sennheiser HD555. Razer Goliathus Speed Medium. Func 1030 L. Qpad CT Medium.

I used to own: Razer DeathAdder 3G. Razer Krait. IntelliMouse Optical 1.1. SteelSeries QcK.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×