DataTypes

  • casting a boolean to an int is illegal.
  • An octal number in Java is preceded by a 0.
  • The method with all double parameters is actually the only version of test() that the Java Virtual Machine can legally coerce the numbers to. The reason the other versions of test() are not invoked is that at least one of the parameters would have to be automatically coerced from a type with greater accuracy to a type with less accuracy, which is illegal.
class Test {

public static void main(String[] args) {

Test t = new Test();
t.test(1.0, 2L, 3);

}

void test(double a, double b, short c) {
System.out.println("1");
}
void test(float a, byte b, byte c) {
System.out.println("2");
}
void test(double a, double b, double c) {
System.out.println("3");
}
void test(int a, long b, int c) {
System.out.println("4");
}
void test(long a, long b, long c) {
System.out.println("5");
}
}

3 will be printed

  • You cannot assign an integer to a boolean—not even with casting. Also, the default type for a floating-point literal is double, and you cannot assign a double to a float without casting.
(int myInt = 0 > 3)

float myFloat = 40.0;

boolean b = (boolean)99;

are all illegal


  • The first yields false, the second is true and the others are not legal Java expressions (this is a wrapper type we’re using here…)


  1. b1 == b2
  2. b1.equals(b2)
  3. b1 & b2
  4. b1 | b2
  5. b1 && b2
  6. b1 || b2


  • How many bits are used to maintain a char data type? 16
  • The && operator works with which data types? The && operator combines two boolean expressions.
  • To place a 1 in the high-bit of an int named ref that’s set to 0x00000001, you can write: ref <<= 31; The << operator shifts the bits the given number of places to the left.
  • Int cannot be cast to string implictly.
  • Integer can be implicitly casted to Object. However Object needs explicit cast to Integer.
  • The compiler will implicitly do a narrowing conversion for an assignment statement if the right hand operand is a compile time constant of type byte, short, char, or int and the value falls within the range of the variable on the left and if the variable is of type byte, short, or char.
  • Max values are always odd numbers since its (2n-1) and min values are even numbers as they are 2n.
  • The first letter of an identifier can be any Unicode JLS 3.1 character that is a Java letter. The first letter can not be a number. For historical reasons, the dollar sign $ and underscore _ are considered Java letters along with many currency symbols in use in the world today.
int i1; // 1

int _i2; // 2
int i_3; // 3
int #i4; // 4
int $i5; // 5
int %i6; // 6
int i$7; // 7
int 8i; // 8

here 4, 6 and 8 are invalid.



Comments

Popular posts from this blog

jQgrid reload with new data

Rich Client based UI technologies- A Comparison of Thick Client UI tools

OSS and BSS Systems