Different Between Package , Import and Interface in Java

package command in java tell compiler we going to save the source code in some directory .
Example :

package example;     /* This tell Java Compiler javac to save
                                         this file which is PackageImport.java
                                         in example directory
                                         */
public class PackageImport {
public static void main ( String[] argv) {
System.out.println (” example PackageImport is called “);
      }
}

To compile it run : javac -d directory PackageImport.java
example how to run compiled file is : java /destination/directory/PackageImport
Continue reading “Different Between Package , Import and Interface in Java”

Java Lesson Understanding Variable Scope

public class TestScope {
public static void main (String[] argv) {
               int x; // ———————-> X Exist until Closing bracket
               // Understanding Scope for x
              {
              char y;
               x = 15; // Notice we can access x here
               y = 65;
              System.out.println (“The Sum of x + y = “+ (x+y));
              } // —-> Y exist until curly or before bracket therefore it give error to print y
              // System.out.println(“The varable of y won’t exist any more in this scope” + y);
      } // ———————————> X exist before this curly bracket .
}
Explanation : variable scope is exist from first bracket { until the next matches closing bracket }
there are exception though example in for loop.

Continue reading “Java Lesson Understanding Variable Scope”