Java Flashcards
How to create a char array from a String?
String str = “123445”;
char[] arr = str.toCharArray();
How to get an String from a value of a different type?
String str = String.valueOf(1234);
or
Integer.toString(int i, int radix); Integer.toString(int i);
What are the bitwise operations in Java?
& (bitwise and) | (bitwise or) ^ (bitwise XOR) ~ (bitwise compliment) >>> (Fill with zero left) >> (fill with highest bit on the left - sign)
How to isolate the lowerst bit that is 1 in X?
x &~(x-1)
x= 00101100 ;
y = x &~(x-1);
y = 0000100;
What are the primitive data types in java?
byte, short, int, long, float, double, boolean, char
What are the sizes of the primitive java types?
byte = 8 bit signed short = 16 bit signed int = 32 bit signed (Unsigned too in Java 8) long = 64 signed (Unsigned too in Java 8) float = 32 bit IEEE 754 precisions double = 64 bit IEEE 754 precisions boolean = Not defined char = 16 bit unicode
How can integer literals be represented in java?
// The number 26, in decimal int decVal = 26; // The number 26, in hexadecimal int hexVal = 0x1a; // The number 26, in binary int binVal = 0b11010;
How can Floating-Point Literals be represented in java?
double d1 = 123.4; // same value as d1, but in scientific notation double d2 = 1.234e2; float f1 = 123.4f;
How to separate long numbers in java 7?
You can use underscore:
long creditCardNumber = 1234_5678_9012_3456L;
long socialSecurityNumber = 999_99_9999L;
float pi = 3.14_15F;
long hexBytes = 0xFF_EC_DE_5E;
long hexWords = 0xCAFE_BABE;
long maxLong = 0x7fff_ffff_ffff_ffffL;
byte nybbles = 0b0010_0101;
long bytes = 0b11010010_01101001_10010100_10010010;
How to get the absolute number in java?
Math.abs(value)
It’s static and works for long, int, float and double
How to get a logarithm base 10?
Math.log10(double value)
How to get the maximum between 2 values?
Math.max(value)
It’s static and works for double, long, float and int
How to get the minimum between 2 values?
Math.min(value)
It’s static and works for double, long, float and int
How to raise a to a power in java?
Math.pow(double a, double b)
How to get the square root of a number in java?
Math.sqrt(double a)