What’s the difference between primitive and reference types?

From book OCA JAVA SE 7 Just as men and women are fundamentally different (according to John Gray, author of Men Are from Mars, Women Are from Venus), primitive variables and object reference variables differ from each other in multiple ways. The basic difference is that primitive variables store the actual values, whereas reference variables … Read more

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

Basic Predicates/F-functions McCarthy’s Elementary S-functions and Predicates were: atom Which was necessary because car and cdr are defined for lists only, which means you cannot count on any sort of answer to indicate what was happening if you gave car an atom. eq For testing equality between atoms. car For returning the first half (address) … Read more

How can you pass multiple primitive parameters to AsyncTask?

Just wrap your primitives in a simple container and pass that as a parameter to AsyncTask, like this: private static class MyTaskParams { int foo; long bar; double arple; MyTaskParams(int foo, long bar, double arple) { this.foo = foo; this.bar = bar; this.arple = arple; } } private class MyTask extends AsyncTask<MyTaskParams, Void, Void> { … Read more

How to cast Object to boolean?

If the object is actually a Boolean instance, then just cast it: boolean di = (Boolean) someObject; The explicit cast will do the conversion to Boolean, and then there’s the auto-unboxing to the primitive value. Or you can do that explicitly: boolean di = ((Boolean) someObject).booleanValue(); If someObject doesn’t refer to a Boolean value though, … Read more

In Java, is the result of the addition of two chars an int or a char?

The result of adding Java chars, shorts, or bytes is an int: Java Language Specification on Binary Numeric Promotion: If any of the operands is of a reference type, unboxing conversion (ยง5.1.8) is performed. Then: If either operand is of type double, the other is converted to double. Otherwise, if either operand is of type … Read more

Why do people still use primitive types in Java?

In Joshua Bloch’s Effective Java, Item 5: “Avoid creating unnecessary objects”, he posts the following code example: public static void main(String[] args) { Long sum = 0L; // uses Long, not long for (long i = 0; i <= Integer.MAX_VALUE; i++) { sum += i; } System.out.println(sum); } and it takes 43 seconds to run. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)