value « primitive « Java Data Type Q&A





1. why can not the value of primitive type variable be changed?    stackoverflow.com

    public class testtype
{
  private   int a;
  private double b;

   testtype(int a,double b)
  {
    this.a=a;
    ...

2. How to overcome the fact that primitives are passed by value    stackoverflow.com

I have a long piece of code that calculates two values (doubles) for me, I use this piece of code in a few places - to stick with DRY principles I ...

3. How to concisely create a String that begins with a primitive value without using an empty double-quote?    stackoverflow.com

To get a newString value of "99 bottles":

int x = 99;
String fruit = " bottles";
To form a new String I do this:
String newString = "" + x + fruit;
since this is ...

4. Difference Max Value for primitive and primitve wrapper    stackoverflow.com

Good Afternoon I have java primitive int and its wrapper Integer ,do it mean that the int has the same Maximum value as Integer's maximum value ? thanks

5. Passing Obj Ref vs value and primitives    coderanch.com

Another Newbie one: Class Pi { double value = 3.14 public string toString() { Double d = new Double(value); return d.toString(); } } public class D { public static void main(String[] args) { Pi pi = new Pi(); System.out.println("before:" + pi); zero(pi); System.out.println("after:" + pi); } static void zero(Pi arg) { System.out.println("top:" + arg) arg.value = 0.0; System.out.println("middle:" + arg) arg ...

7. Primitive value    coderanch.com

Hi, Thanks for the reply.I was working on the above problem.When i do binary to decimal conversion of 16 bit of short 1011 1011 1111 1010-it gave the answer -48122 instead of giving the answer -17414.My answer is -48122 is not correct.-17414 is the correct answer.but i couldnit still figure out how to get the result.Please share your knowledge.

8. Clarification needed on max value of primitive data types...    coderanch.com

Hi All, I have a small doubt on the max value that a short(data type) variable can take. Short can accomodate 16 bits, of which the left most bit is a sign bit and the remaining 15 bits represent value. So the max value that can be accomodated by the short variable is (2^15-1). (^ represents the power symbol). Does Java ...

9. values in primitives    coderanch.com

hi what are the range of values that can be stored in primitives like int,char,byte,short,long,float,double. please specify the range in exact numbers. like i guess that a byte should be able to store 255 to the maximum because it has 8 bits. but the k&b book has a saying that 128 is quite big for a byte?? is it due to ...





10. Method that take all primitive values..?    coderanch.com

Ya i agree with you but taking as Object as a parameter will convert primitive to object . i want exactly like this in primitive Nope. Won't work. There is no option to have a single method take multiple primative types -- as primatives. If you want to provide this option to your callers, you have to do some work -- ...

12. Modifying values in primitive data types?    forums.oracle.com

When I pass an integer from my main method to another method, it passes by value and the original variable is left unchanged. My question is: How do you change the value of the original variable, and not just the 'copy' of that variable in my other method? I would also appreciate it if you could explain this in 'dumbed down' ...

13. do java primitives have defualt values    forums.oracle.com

I am trying to determine if java primateives (like an int) have default values. On sun's web page I read this: "It's not always necessary to assign a value when a field is declared. Fields that are declared but not initialized will be set to a reasonable default by the compiler. Generally speaking, this default will be zero or null, depending ...

14. corrupted value of primitive    forums.oracle.com

I have a variable of type long. This variable is accessible by more than one thread. I have threads that only read the value of that variable, and I have threads that read and also write the value. Suppose the value of the variable is being changed by a thread. This thread is changing the value from 1051 to 1055, in ...

15. Max Value of primitive long seems incorrect.    forums.oracle.com

I tried to calculate 2^62 iteratively, but at the end I get a negative value. You must have done something wrong but fixed the error because your current code gives 2^62 = 4611686018427387904, which is correct. To elaborate the above post, literal integer constants are, for some strange reason, implicitely of int type, and values outside of the int range are ...