Lost Password?

  #1 (permalink)  
Old 12-09-2006, 09:55 AM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 19
Posts: 2,441
Last Blog:
Object Oriented Design...
Rep Power: 20
John has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud of
Send a message via AIM to John
Default Java:Tutorial - Data Types

This is not exactley a tutorial, but rather information you should know before you start using Java. I will be refering to in in future tutorials.

Unlike my favorite web-based programming language, PHP, Java requires you to declare your variable to a type.

int x = 0;
String y = “Hello World”;

Below are a list of all the data types in Java and a brief explanation of each.

char: Has the ability to hold a single letter. I’ve never once used this data type.
String: The data type string can hold any string including numbers, letters, and special characters. However you must note that the number 5 stored as a string is NOT evaluated as a number. Also for the longest time I always wondered why String was the only data type with a capital letter. I recently found out that String is a reference to a class. Its default value is evaluated to be “null.”

byte: This data type can hold any numeric integer from -128 to 127. Its default value is evaluated to be “0.”
short: This data type can hold any numeric integer from -32,768 to 32,767. Its default value is evaluated to be “0.”
int: The data type int can hold any numeric integer from -2,147,483,648 to maximum value of 2,147,483,647. Its default value is evaluated to be “0.”
long: The long data type can hold any numeric integer from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. Its default value is evaluated to be “0L.”


float: The float data type is used for decimals. I believe it is 32 bytes and has the ability to hold 754 floating points. Its default value is “0.0f”
double: The double data type is also used for decimals. It has more precision than float and is often referred to as double-precision, hence the name. It is 64 bytes and also holds 754 floating points. Its default value is “0.0d”.

boolean: This data type can either store true or false. It is very useful for state functions and is often used in loops. Its default value is “false”.


For the most part, this information applys to other programing languages, but for our porposes, these are the specific data types in Java.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 12-13-2006, 08:37 AM
castanza88 castanza88 is offline
Newbie
 
Join Date: Dec 2006
Posts: 5
Rep Power: 0
castanza88 is on a distinguished road
Default which one to pick

If not using large amounts of data, is it ok to not have to get an exact data type for your variable for basic needs?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-13-2006, 08:38 AM
castanza88 castanza88 is offline
Newbie
 
Join Date: Dec 2006
Posts: 5
Rep Power: 0
castanza88 is on a distinguished road
Default followup

I would usually pick an "int" for a basic data type for any number that I use...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 12-13-2006, 11:45 AM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 19
Posts: 2,441
Last Blog:
Object Oriented Design...
Rep Power: 20
John has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud of
Send a message via AIM to John
Default

Quote:
Originally Posted by castanza88 View Post
If not using large amounts of data, is it ok to not have to get an exact data type for your variable for basic needs?
for most programs it really dosnt matter, it would guess for large applications it would be more wise to use the "best" data types for the job. that way you dont allocate too much memory thats not being used. However with that said, ive only ever used boolean, String, int, and double
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 06-10-2007, 10:19 AM
rong889 rong889 is offline
Newbie
 
Join Date: Jun 2007
Posts: 2
Rep Power: 0
rong889 is on a distinguished road
Default

Quote:
Originally Posted by castanza88 View Post
I would usually pick an "int" for a basic data type for any number that I use...
Sometimes you need to use the accurate type.
__________________
Search For Programmer
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 07-02-2007, 08:57 AM
brian brian is offline
Newbie
 
Join Date: Jun 2007
Posts: 13
Rep Power: 0
brian is on a distinguished road
Default

Nice description of the datatypes.

One thing though is that these are just primitive data types and not objects. The nice thing about java is that it is object oriented, and so you create objects (which are like a more complex data type) and so you have virtually unlimited number of datatypes in reality....because you create them.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 07-02-2007, 09:16 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 19
Posts: 2,441
Last Blog:
Object Oriented Design...
Rep Power: 20
John has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud of
Send a message via AIM to John
Default

Quote:
Originally Posted by brian View Post
Nice description of the datatypes.

One thing though is that these are just primitive data types and not objects. The nice thing about java is that it is object oriented, and so you create objects (which are like a more complex data type) and so you have virtually unlimited number of datatypes in reality....because you create them.
Not all of them are actually primitive data types. In Java Strings are objects, more specifically, an Abstract Data Type [ADT] -- essentially an array of characters.

But yes, in OOP, there are unlimited ADT's.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Fetching Data from a Form Generated Website pclark2 General Programming 5 05-11-2007 06:24 AM
Please help me , Post Data & Store Data minusp PHP Forum 7 03-23-2007 07:00 PM
Abstract data types in C++ priorityone C and C++ 1 01-08-2007 11:43 AM
What Is A Union ravs2k6 C and C++ 2 07-08-2006 01:14 PM


All times are GMT -5. The time now is 07:49 PM.

Contest Stats

Xav ........ 164.00000
dargueta ........ 128.00000
John ........ 127.00000
gaylo565 ........ 18.00000
XaNaX ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

Ads