Day One : Starting Java
          In the classroom we have discussed the story of the development of the language Java. This webpage complements the lesson by providing in a nutshell, the concepts you learnt          class MyFirstProgram
         {
             public static void main(String[] args)
              {
                    System.out.println("My First Program !");
               }
           }

  
To Remember : -

         This program prints "My First Program !" on the screen. This is  done by the call to println method in the System class. You need not bother about the other statements till Day Two.

      
Data Types

           Data can be classified into various types depending on its content and storage requirements. Such classifications are called Data Types.

            Examples :- char, int, float .

       
Variables
                       
            In order to store data we need containers. These containers are called Variables. All variables have user defined names. The BLOCK SCOPE of a variable can be specified by the programer.

        
Example01.java

          public class Example01
          {
                public static void main(String[] args)
                {
                       int a=6;
                       int b=4;
                       int c=0;
  
                       c=a+b;
       
                       System.out.println("The sum is " + c);
                  }
             }

   
To Remember :-

      What happens in this program should not be difficult to understand. First we declare three variables of int data type and assign a number to each. We then add a and b and store the value in c. After that we again call the println method of System class to display the result. Please note the use of "+" operator. This way of using the "+" operator is called concatenation.

     
User Input :-

       Input from the user can be taken by using the Console class present in Corejava package.

     a = Console.readInt("Enter a number");

        Console is a very powerful and user friendly class and is best suited for the purpose of taking input from the user.

      

          
          In the classroom we have discussed the story of the development of the language Java. This webpage complements the lesson by providing in a nutshell, the concepts you learnt in my first lecture on Java.

          
First Program

         class MyFirstProgram
         {
             public static void main(String[] args)
              {
                    System.out.println("My First Program !");
               }
           }

  
To Remember : -

         This program prints "My First Program !" on the screen. This is  done by the call to println method in the System class. You need not bother about the other statements till Day Two.

      
Data Types

           Data can be classified into various types depending on its content and storage requirements. Such classifications are called Data Types.

            Examples :- char, int, float .

       
Variables
                       
            In order to store data we need containers. These containers are called Variables. All variables have user defined names. The BLOCK SCOPE of a variable can be specified by the programer.

        
Example01.java

          public class Example01
          {
                public static void main(String[] args)
                {
                       int a=6;
                       int b=4;
                       int c=0;
  
                       c=a+b;
       
                       System.out.println("The sum is " + c);
                  }
             }

   
To Remember :-

      What happens in this program should not be difficult to understand. First we declare three variables of int data type and assign a number to each. We then add a and b and store the value in c. After that we again call the println method of System class to display the result. Please note the use of "+" operator. This way of using the "+" operator is called concatenation.

     
User Input :-

       Input from the user can be taken by using the Console class present in Corejava package.

     a = Console.readInt("Enter a number");

        Console is a very powerful and user friendly class and is best suited for the purpose of taking input from the user.

      
Conditional Statements

         if(a == 2)
         {
              System.out.println("Saurabh is great !");
          }
          else
          {
               System.out.println("Saurabh is the greatest !");
           }

         The above statements should not be difficult for you to understand. Please note the use of "=" here. If you give only one "=" instead of "==" then the program will not compile.

        
Determinate Loops

          for(i=0;i<10;i++)
          {
                System.out.println("Value of i in loop now is " + i);
           }

          In this case the number of runs of the loop are predetermined by the programmer as in this case the loop will run ten times.

        
Indeterminate Loops
  
         while(ch == 3)
         {
               System.out.println("Saurabh is the best !");
                a = Console.readInt("Enter a number ");
          }

          As in the above case those loops of which the number of runs are not predetermined by the programmer are called Indeterminate loops.

        
Arrays

         int[] a = {2, 3, 4};

          Arrays are the way of a programming language to provide the programmer with the facility to store more data in the same variable. Arrays can be called a set of memory units(pockets) which store data.

         
FOR THE ARRAY SORTING PROGRAM REFER TO YOUR NOTEBOOK AND IF YOU HAVEN'T GOT IT CONTACT ME.




              

          
Hosted by www.Geocities.ws

1