Skip to main content

Error in variable Declaration

  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;




Popular posts from this blog

Java

Codes With Java — Basics Codes With Java Java tutorials & fundamentals About Contact Privacy Basic Fundamentals Java source file structure Import Statement Static Import Packages Data Type Variables Final Variable Declaration and Access Modifier Inner classes applicable modifiers Static Modifier Synchronized Native Transient Volatile Interface Introduction Interface Declaration and Implementation Interface methods and variables Naming Conflicts Interface Marker interface and Ad...

Short Circuite Operators part 4

                                                             Short Circuit Operators In  Java logical operators , if the evaluation of a logical expression exits in between before complete evaluation, then it is known as  Short-circuit . A short circuit happens because the result is clear even before the complete evaluation of the expression, and the result is returned. Short circuit evaluation avoids unnecessary work and leads to efficient processing. 1-: AND(&&) 2-:OR(||) these are exactly same as bitwise operators (&,|) except the following differences. Single Short Circuit Operator(&,|) Both arguments Should be evaluated always. relatively performance is low. Applicable for both boolean and Integral types. Double Short Circuit Operator(...

Final Variable

Final Instance Variable If the value of a variable changes from object to object, such a variable is called an instance variable . For every object, a separate copy of the instance variable will be created. Instance variables do not require explicit initialization; JVM always provides default values. Example: class Test { int x; // instance variable public static void main(String... args) { Test t = new Test(); System.out.println(t.x); // output: 0 } } If the instance variable is declared as final , then explicit initialization is mandatory. JVM will NOT provide default values. Example: class Test { final int x; } Compile-time Error: variable x might not have been initialized. Rule: A final instance variable must be initialized before constructor completion . Possible places for initialization: 1. At the time of declaration class Test { final int x = 10; } 2. Inside an instance blo...