What is difference between initialized variable and a literal in java? -


i learning java, while studying literals in java found literals can of datatype (int,boolean,char,etc.) , declared

int decval = 26;   //am declaring literal correctly? 

as far know, literal fixed value , above declaration similar initialization of variable of 'int' type. confirm, tried following code.

public class literalchecking {      public static void main(string[] args) {         int i=2;          for(i=2;i<5;i++)         {             system.out.println("i= "+i);         }     } } 

where, got output as:

i=2 i=3 i=4 

now confused between literal , initialization, both same? can 1 explain me difference?

am declaring literal correctly?

no, you're not declaring literal. you're declaring , initializing variable called decval. 26 integer literal.

i confused between literal , initialization

  • a literal value in program code. examples of literals include

    • "hello" -- string literal
    • true -- boolean literal
    • 26 -- integer literal
  • an initialization assignment, such int = ... ... value initialize i with.


Comments

Popular posts from this blog

node.js - How to mock a third-party api calls in the backend -

java - Could not locate OpenAL library -

Non Unique Username with ASP.Net Identity 2.0 -