java-cheat-sheet

Increment & decrement

 int a=5;
 a++; 

This will increase value of 'a' after end of statement by 1

int a=5;
++a;

This will increase value of 'a' at the end of statement by 1

if first condition true in a condition statement, next condition are ot checked

if(condition_1 || condition_2)

here if condition condition_1 true then condition condition_2 will not checked. And if not true then condition_2 will be checked.

Note : even if condition statement is false/true statement is compiled. Suppose we have conditional statement if(System.out.println("Hello") == null) "Hello" will be printed

Let take a simple example where first cindition is true

int a=5;
if(++a==6 || a++==6)
System.out.println(a);

So here when we use pre-increment on a it become 6 & so 6==6 will true hence post-increment of a i.e a++==6 ignored and at time of printing it prints 6 rather than printing 7

Let take a simple example where first cindition is false so we will check second condition

 int a=5;
 if(a++==6 || a++==6)
 System.out.println(a);

So here first condition a++==6 is false so we moved to second condition but our value increased because we ended with first condition statement now second condition is true and our output will printed as 7

Casting

  a=+b;  

a = (int) (a + b)

Integer/doubles to character
char ch = (char) 65.65;

Simply this will cast double value to char as per ASCII which is A

Character to integer
int i = (int) 'A';

Simply this will cast character A to inetger as per ASCII which is 65

Integer to string
int number = 456;
String str = number + "";

This will change integer to string

String to integer
String str = "456";
int number = Integer.parseInt(str);

This will parse string "456" to an integer value 456

Something about Characters in java

iCheck whether character is type of digit or not

Character.isDigit('9');

Or

char ch = '9';
Character.isDigit(ch);

This will return boolean true if ch is digit of character else return false

Here are others

Syntax meaning
Character.isLetter(ch); return boolean true if ch is letter of character else return false
Character.isLetterOrDigit(ch); return boolean true if ch is letter or digit of character else return false
Character.isLowerCase(ch); return true if character ch is lower case else false
Character.isUpperCase(ch); return true if character ch is upper case else false
Character.toLowerCase(ch); return lower case of character ch
Character.toUpperCase(ch); return upper case of character ch