Hi, I was hoping if anyone could help me really quickly. A section of my program needs to discern between java primitives. I've had to make regular expressions which look for the different characteristics between each primitive, but I don't know what some of them are. Below are all the primitives that I need to tell apart. The bolded ones are the ones I know. I was hoping if anyone could tell me what a byte or short is. Or what the differences between a long, float and double are. Sorry for the HELP! in the title, but this program is due at 12:00am sharp, and it's 10:21pm where I am =(

boolean
byte
short
int
long
float
double
char

Recommended Answers

All 2 Replies

In a nut shell...

byte is a single byte, signed, no decimal places
double and float have decimal places, signed, double is just a bigger form of float
long, short, int are signed, NO decimal places. Long is the biggest, then int, then short, byte is pretty much in this group too
char holds a char
boolean holds a true/false

Hi everyone,

I am not sure if your program is due yet but here i go

A section of my program needs to discern between java primitives

After many years of programming, i can say if you have such a need in your program, your program is designed badly. You need to redesign it.

Think of it this way, you can only cast it if you know its primitive or else you can never know its value.

You can do what alot of C++ programmers do and that is create you own primitive parsing classes using array strings

For example

Like this

String[2] str1 = new String[2];
int po = 5;

str1[0] = "Integer";
str1[1] = Integer.toString(po);

Using the above technique you can read any primitive from a serialized string array form or anywhere else but beware doing this can make your program very complicated and i would stay away from this if i were you

Richard West
*****************************************************

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.