Java Fundamentals

"It always seems impossible until it's done."





Subject: Java Fundamentals


Topics:
  1. Variables
  2. Declaration of Variables
  3. Assignment of Values to Variables
  4. Variables = Ability to store and manipulate values (Named Data Storage)
  5. Declaration and Assignment of Values in a single statement
  6. Naming Variables
    • Combination of Rules and Conventions.
    • Rules: Allows use of letters, numbers, $ and underscore
    • Convention: Only letters and numbers are used.
    • Rules: First character is not a number
    • Convention: First character is always a letter
    • Convention: Follow "Camel Casing"
      • First letter is lowerCase
      • Start of each word after first is UpperCase
      • All other letters are lower case.
  7. We can assign a value to variable and later modify it to other.
  8. Local Variables: 
    • Variables declared inside the main method
 public class Variables {  
      public static void main(String[] args) {  
           /**  
            * Declaring only the local variable and printing the variable.  
            *   
            * int myVar;  
            * System.out.println(myVar);  
            *   
            * Error during compilation:  
            * Exception in thread "main" java.lang.Error: Unresolved compilation problem:   
            * The local variable myVar may not have been initialized  
            * at Variables.main(Variables.java:8)  
            */  
           int myVar; //Declaring the local variable  
           myVar = 50; //Assigning the value to local variable  
           System.out.println("myVar=" + myVar);  
           int anotherVar = 100; //Declaring and assigning another local variable  
           System.out.println("anotherVar=" + anotherVar);  
           myVar = anotherVar ; //Assigning copy of value of anotherVar to myVar  
           System.out.println("myVar=" + myVar);  
           System.out.println("anotherVar=" + anotherVar);  
           anotherVar=200; //Assigning another value to anotherVar. As it is already declared earlier.  
           System.out.println("myVar=" + myVar);  
           System.out.println("anotherVar=" + anotherVar);  
      }  
 }  





    This entry was posted in . Bookmark the permalink.

    Leave a Reply