All declaration problem
If int greater than size we got error->error: integer number too large
int x=2147483648;
error: integer number too large
int x=-2147483649;
error: incompatible types: boolean cannot be converted to int
int x=true;
error: incompatible types: int cannot be converted to boolean
boolean x=10;
error: incompatible types: possible lossy conversion from double to long
long x=10.88;
error: cannot find symbol
boolean x=True;
^
symbol: variable True
: error: incompatible types: int cannot be converted to boolean
if(x){
^
: error: incompatible types: int cannot be converted to boolean
while(x){
Above the last both error valid in c and C++ but error in java
Size of char in java 2 byte because java is unicode based but c and c++ are ascii code based language
System.out.println(Character.BYTES);//2byts
error: incompatible types: possible lossy conversion from long to int
int z=10l;
incompatible types: possible lossy conversion from double to float
float a=233.0;
^
: error: incompatible types: possible lossy conversion from double to float
float b=33.0333;
Because after decimal value consider as double
Ans-> suffix with f or F both
double d=22.333333D; this convention no required because double is considered already double
Double is valid for only decimal values not for octal and hexadecimal.
Double x=0234.34555;
Output is->234.34555
It is consider as decimal not as octal value;
error: malformed floating point literal
double e=0x234.3444;
Double 03432; is valid because here not (.) floating point it is consider as octal
double e=0234;
System.out.println(e);
Output is 256
If
Double e=0345.0;
Consider as integer here floating point is present;
Output is 0345.0
Double e=0xface;
Is valid because here not a floating point
double e=0xface;
System.out.println(e);
Output is ->64206
error: malformed floating point literal
double e=0xface.0;
Because hexadecimal not consider double
error: cannot find symbol
char a=x;
Ans-char a=’x’;
error: incompatible types: String cannot be converted to char
char a="x";
Ans-char a=’x’
error: unclosed character literal
char a='ab';
^
: error: unclosed character literal
char a='ab';
^
: error: not a statement
char a='ab';
error: ';' expected
char a='a''b';
Char lateral enclosed in single inverted comma only on character at a time.
char c=0xface; valid
char c=01245;valid
char c='\u0061';we can use char literal in unicode representation ‘\u 4digit hexadecimal number’;
Every escape character is char literal;