Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have been storing date records (Date().getTime()) in an SQLite database with an Integer type. I realize now that Date().getTime() is returning Long values, not Integer.
Is there any way I can rescue the date data that is already stored in the database? Going forward I can reduce the resolution of the time, to make it fit into an integer. (ie. divide by 1000, and cast to int)
I expect that forcing a long value into an integer space has truncated the most significant digits - which might work in my favour, as the dates in question have all occurred within the past 6 months, so can probably be calculated.
question
so, how exactly would the long representation of today's date map onto an integer, and how might I use that knowledge (combined with the restricted time range) to build these integers back into their original long values?
Any suggestions?
Turns out the SQLite database integer type is perfectly capable of storing long values. So the data rescue was unnecessary in the end.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I want to take a sum, quotient, remainder of two numbers using an array in java.
123456789012345+7654321, 123456789012345/7654321. What is a simplest way to calculate it using Java?(I am new to Java.)
Since you are new to java I recommend reading up on some tutorials. As it seems you are not familiar with java in general. An example, which I have not used myself, is http://www.javaworld.com/blog/java-101. It may be worth your time to read this over.
As for your actual question, you would create a variable in java. Then assign your first number to this variable. After doing this, you can perform some operations on the number.
An example in sudo code to give you an idea while not doing the work for you.
void method
var number = 100
number = number + 200
number = number / 20
print("result" . number)
If you plan to use an array its the same process in a loop.
http://www.tutorialspoint.com/java/java_loop_control.htm
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
Why is the scale field of a BigDecimal not a BigInteger? I assume currently it makes maybe no sense because calculations with that many decimal places are likely never performed, but wouldn't it make sense for the future to rather use a BigInteger?
The scale of a BigDecimal is the number of digits it stores to the right of the decimal point. It is an amount of memory in that those digits are actually stored, and it is an amount of work in that most operations on a BigDecimal will have to do work on all of those digits.
It is never going to be a good idea to use a BigDecimal that takes an amount of memory or work that doesn't fit into an int, so an int is used for scale. That's the same reason int is used for string lengths and collection sizes, etc.
In the rare cases that a reasonable amount of memory or work doesn't fit into an int, it certainly fits into a long. Longs are used for file sizes and position, for example. A BigInteger is never required.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a column in a MySQL table calleddead_heat_flag which data type is smallint,
and I want to represent this column as one attribute in my Java class.
What data type should I use?
As per the comment below, for MySQL's smallint, java's short should cover that value range. Of course, you could also use an int, but keep in mind that it allows many values that the database column does not.
I believe the datatype equivalent would be a short based on what I found here for java and here for a db that uses smallint. They both address the same range of values.
Short in java is equivalent to small int as there range is same.It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive).
Refer this
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html for java
https://docs.oracle.com/cd/E19501-01/819-3659/gcmaz/ for database
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Why do most programmers avoid using the float and long data types in their video tutorials?
Is it only to avoid the "0000f" and "0000L" notation?
I avoid float has it has poor precision. I would rather use double (or long with fixed precision or if I have to BigDecimal).
I suspect long is not often used as int is usually enough and many Java APIs only accept int values. e.g. array sizes and Collection/Map size() must be int.
And why should they use them? Perhaps the one reason is to avoid writing a letter indicating that the float/long type is used.
However if you don't need any special precision, why use double instead of float or long instead of int?
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I need to store certain id's , and check if one exists there.
Either i can use concatenated string or array/List, which of them is a better and faster way.
This is how actually data is organized :
Year 1
Month 1
Day 1
Day 2
Day 3
Month 2
Day 6
Day 2
Day 3
Year 2
Month 3
Day 1
Day 3
Day 7
Month 6
Day 6
Day 2
Day 3
I would definitely use a collection of some form. If you only care about containment, you should use a Set<String> of some kind (e.g. HashSet<String> or LinkedHashSet<String>, which will both give O(1) complexity unless you have a significant number of hash collisions) but for goodness' sake don't use a concatenated string.
Your data isn't naturally a concatenated string - it's a collection of strings. Always keep your data in the most natural representation unless you have really good evidence that some alternative form (such as a single string) will bring you a meaningful benefit. Keeping your data in a natural representation almost always leads to clearer code which is easier to work with - and easier to optimize later, when you've found where the real bottlenecks are.
Create a HashSet a use contains method. String or ArrayList will have O(n) complexity where as HashSet will be O(1) complexity.