primitive

Which one to use, int or Integer

ε祈祈猫儿з 提交于 2019-11-27 10:51:13
I need to create a data transfer object, which I will use for storing the records retrieved from database. In this data transfer object, I need to declare a numeric field. For that which one is better - int or Integer If I am defining the field as Integer, will there be any performance impact because of 'Integer' type if I am going to retrieve more than 2000 records from DB!? Thanks in advance. Integer is a better option, as it can handle null ; for int , null would become 0 , silently, if resultSet.getInt(..) is used. Otherwise, it might throw some exception, something like, "Unable to set

How many primitives does it take to build a LISP machine? Ten, seven or five?

偶尔善良 提交于 2019-11-27 10:10:17
On this site they say there are 10 LISP primitives. The primitives are: atom, quote, eq, car, cdr, cons, cond, lambda, label, apply . http://hyperpolyglot.wikidot.com/lisp#ten-primitives Stevey reckons there are seven (or five): Its part of the purity of the idea of LISP: you only need the seven (or is it five?) primitives to build the full machine. http://steve-yegge.blogspot.com/2006/04/lisp-is-not-acceptable-lisp.html What is the minimum number of primitives to build a LISP machine (ie something that can run an eval/value function on LISP code)? (And which ones are they?) (I can understand

Inconsistent behavior on java's ==

青春壹個敷衍的年華 提交于 2019-11-27 09:29:45
Consider this code: class test { public static void main(String[] args) { test inst_test = new test(); int i1 = 2000; int i2 = 2000; int i3 = 2; int i4 = 2; Integer Ithree = new Integer(2); // 1 Integer Ifour = new Integer(2); // 2 System.out.println( Ithree == Ifour ); inst_test.method( i3 , i4 ); inst_test.method( i1 , i2 ); } public void method( Integer i , Integer eye ) { System.out.println(i == eye ); } } It prints: false true false I understand the first false , the == operator only checks if two references are working on the same object, which in this case aren't. The following true and

Is it possible to use a primitive type (int) in as a generic type in Java?

岁酱吖の 提交于 2019-11-27 09:24:19
Specifically, with a SortedMap<Vector<String>, int> I get "dimensions expected after this ( int ) token." Help! No, this is not possible. Use Integer instead. Autoboxing takes care of the rest (i.e. for most purposes you can program as if you had actually used int because Java converts to and from Integer automatically for you). Konrad is correct. Alternately, you can use the trove class TObjectIntHashMap to map Objects to primitive ints. 来源: https://stackoverflow.com/questions/414408/is-it-possible-to-use-a-primitive-type-int-in-as-a-generic-type-in-java

When changing the value of a variable in C, is a new primitive created or is the current primitive mutated?

依然范特西╮ 提交于 2019-11-27 07:56:50
问题 I know that 'mutable' and 'immutable' are terms that should be used to describe the ability for objects to change value in object oriented languages such as Java and Objective C. However, I would like to bring it up because it relates to my question regarding primitives data. I know that when I change the value of a variable holding immutable object, I am in fact creating a new object. I wonder, however, if primitives data in C behave similarly to immutable objects. By that I mean, when I

Using int vs Integer

流过昼夜 提交于 2019-11-27 06:47:55
I came across a class using Integer variables to capture size to be used in a for loop. Is this good practice or should we use the int primitive data type? Integer size = something.getFields().size(); for (Integer j = 0; j < size - 1; ++j) the Integer class is provided so that values can be boxed/unboxed in a pure OO manner. use int where appropriate unless you specifically need to use it in an OO way; in which case Integer is appropriate. Java Int vs Integer However, very different things are going on under the covers here. An int is a number; an > Integer is a pointer that can reference an

Why == operator and equals() behave differently for values of AnyVal in Scala

我的未来我决定 提交于 2019-11-27 05:45:16
问题 In the scaladoc of scala.Any , the operator == (or, method == ) is explained: The expression x == that is equivalent to if (x eq null) that eq null else x.equals(that) http://www.scala-lang.org/api/current/#scala.Any For objects of subclasses of AnyRef , I can understand it easily, and I didn't see any strange things. However, for values of AnyVal , (I mean Int , Double , Long , and so on,) the above definition is somewhat tricky ( 1 eq null ? This does not compile if we do not convert 1 to

object vs. primitive

强颜欢笑 提交于 2019-11-27 05:20:01
问题 Recently had an interviewer ask to define the difference between objects and primitives. Seemed like an odd question considering that all languages begin with a primitive. How would you have answered this question? I should also note that this interview was for a front-end development position so the language (I assume) he was referring to was JavaScript. 回答1: A primitive is a data type that is composed of no other data types and can not be broken down any further. It is like the atoms in the

Comparing float and double primitives in Java

▼魔方 西西 提交于 2019-11-27 05:10:29
I came across a strange corner of Java.(It seems strange to me) double dd = 3.5; float ff = 3.5f; System.out.println(dd==ff); o/p: true double dd = 3.2; float ff = 3.2f; System.out.println(dd==ff); o/p: false I observed that if we compare any two values (a float and a double as I mentioned in the example) with .5 OR .0 like 3.5, 234.5, 645.0 then output is true i.e. two values are equal otherwise output is false though they are equals. Even I tried to make method strictfp but no luck. Am I missing out on something. Take a look at What every computer scientist should know about floating point

Java: how much time does an empty loop use?

牧云@^-^@ 提交于 2019-11-27 04:54:13
I am trying to test the speed of autoboxing and unboxing in Java, but when I try to compare it against an empty loop on a primitive, I noticed one curious thing. This snippet: for (int j = 0; j < 10; j++) { long t = System.currentTimeMillis(); for (int i = 0; i < 10000000; i++) ; t = System.currentTimeMillis() - t; System.out.print(t + " "); } Every time I run this, it returns the same result: 6 7 0 0 0 0 0 0 0 0 Why does the first two loops always take some time, then the rest just seem to be skipped by the system? In this answer to this post, it is said that Just-In-Time compilation will be