(int) object syntax Java [duplicate] - java

This question already has answers here:
What does a 'int' in parenthesis mean when giving a value to an int?
(7 answers)
Closed 2 years ago.
What does the second line in the following code represent?
long longNumber = Integer.MAX_VALUE;
int intNumber = (int) longNumber;
I've created a longNumber and assigned it MAX_VALUE. What does the second line mean?
Thanks in advance.

Writing "(Generic Type) VariableName" mean that you are changing the type of "VariableName"
this syntax is called "CASTING"
In this case you are converting a Long variable to an Int variable.
Casting is not always a secure method becouse if the LONG number is higher than Integer.maxvalue the number will NOT be converted in the correct way (becouse LONG type has more bits than normal INT)

Related

i tried to declare and initialsie a auxillary string but got these errors [duplicate]

This question already has answers here:
Unexpected Type errors
(3 answers)
Closed 2 years ago.
String b="";
b.length()=n;
^
required: variable
found: value
revstring.java:22: error: unexpected type
b.charAt(i)=str.charAt(n-i-1);
^
required: variable
found: value
2 errors
In Java, when you use an = you are assigning a variable on the left side to the value on the right side. In your issue, you have the line b.length() = n;. Here you are telling java to assign the method b.length() to the value of n, which doesn't make sense to java (not to mention that n doesn't exist).
I'm not really sure what an auxiliary string is, but if you are trying to store the value of b.length() into a variable n. To do that you need to write int n = b.length();.
If you are having problems at this level, I suggest you take a basic course on java. Sites like codecademy have pretty good free ones. Good luck!

Why cannot I assign value to a long variable that is between 2^64 and 2^32? [duplicate]

This question already has answers here:
Why can't I assign a 'long' a value of 4 billion? [duplicate]
(6 answers)
The literal xyz of type int is out of range
(5 answers)
Closed 5 years ago.
I am trying to test the difference between int and long data types and I've learned that int has 32 bits whereas long has 64 bits. According to this, long data type's maximum value is 9,223,372,036,854,775,807. I am only using a 13-digit number however I am getting this error:
error: integer number too large: 2147483645234
long exceedLong = 2147483645234;
I thought a long variable should be able to handle that value. I'm using JDK and JRE version 8 and I'm compiling and running the code in command prompt, using javac and java.

how to declare a long long array in Java? [duplicate]

This question already has answers here:
Java equivalent of unsigned long long?
(10 answers)
Closed 6 years ago.
A simple question:
Can someone help me declare a long long array in Java?
I've tried to cast it, but no luck:
(long long)[] sum = new (long long)[10];
Also, I searched across the internet and didn't really find anyone who uses long long to define an array
Any help please?
I do not know a type called "long long".
Are you sure the code you read was written in Java? Maybe it was a JNI routine that was called into?
it isn't also listed here: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
There is no long long type in Java.
If you need an arbitrarily-long integer type, you can use BigInteger, but this is a reference type, and has no "convenient" operators like +.
long long is not a valid type in java
using a big integer would make more sense in this case...
BigInteger[] sum = new BigInteger[10];

Integer i = 23; versus Integer i = new Integer(23); Previous answers not satisfactory [duplicate]

This question already has answers here:
what is difference between integer a = 5 and new Integer(5)?
(5 answers)
Closed 8 years ago.
I understand that an identical question has been asked before-
what is difference between integer a = 5 and new Integer(5)?
However, none of the answers is satisfactory to me-
My question is simply this-
If I say Integer i = 23; it is clearly creating an object i of type Integer. All the Integer methods are available to it. So why is it different from an explicit instantiation- Integer i = new Integer(23) ?
Any insight into this will be much appreciated.
If I say Integer i = 23; it is clearly creating an object i of type Integer.
No, it returns a reference to an object of type Integer. Whether a new one is created or an existing one (from the JVM's constant pool) is re-used is at the discretion of your JVM.
For int literal values from the range –128 to 127 it is even required that Integer constants are pooled and a new instance never be created.

What is the equivalent of "integer" from java in javascript? [duplicate]

This question already has answers here:
What is JavaScript's highest integer value that a number can go to without losing precision?
(21 answers)
Closed 8 years ago.
I have this in java:
int minimo = Integer.MAX_VALUE;
how would it look in javascript? Is there an equivalent of n"integer" in javascript?
var minimo = Integer.MAX_VALUE;
?
JavaScript has only one number type Number. It automatically switches between floats and integers as needed.
Use Number.MAX_SAFE_INTEGER to get the max integer value and Number.MAX_VALUE to get the max float value.
For me these are 9007199254740991 and 1.7976931348623157e+308

Categories

Resources