Friday, 1 June 2012

Friday (June 1' 2012)

This was one of the hottest and the most tiring day since my training started. We had an Objective Type Test today to check if we had so far understood the concepts of Java or not. It consisted of ten questions, covering topics like constants, variables, data types, operators, expressions , decision making and branching. It had some tricky questions, but went well finally. I would be posting the result as soon as we get the marks. In the evening, i left for my home(Ludhiana) . Reached by 9:45 p.m , and finally slept after having dinner.

Thursday, 31 May 2012

Thursday (May 31' 2012)

As it was declared India Bandh today, So most of the educational institutes stayed close. No classes for this day, except for few hours of self programming practice and some search on the Google about Project topics.

Wednesday, 30 May 2012

Wednesday (May 30 '2012)

Today, @HCL  i was taught STRINGS in java. At the end of today's class, i was able to do String Manipulation, which is the most common part of many Java programs. Now, i know which package is imported to perform String related functions in a Java program, and how to use functions like- Concatenation of 2 strings, changing case of strings, replacing a part or whole of the string with another set of characters, how to display a sub-string , finding the length of a string and comparison of 2 strings.

Examples:

1. Concatenation of 2 strings.

              import java.lang.String;
            public class String1
               {
                 public static void main(String args[])
                    {
                      String S = " Java " ;
                      String R = " Core " ;
                      String T = (S.concat(R));
                 System.out.println(T);
                     }
                }

OUTPUT: Java Core


2. Replacing characters in a string.

                    
import java.lang.String;
            public class String2
               {
                 public static void main(String args[])
                    {
                      String S = "Hydrophobia" ;
                      R = S .replace ("o" , "a");
                  System.out.println(R);
                     }
                }
 
OUTPUT: Hydraphabia

3. Displaying a Sub-string.
     
                      import java.lang.String;
            public class String3
               {
                 public static void main(String args[])
                    {
                      String S = "Hydrophobia" ;
                      R = S .substring (1,5);
                  System.out.println(R);
                     }
                }

 OUTPUT: ydro
          



                    
  

Tuesday, 29 May 2012

Tuesday (May 29' 2012)

Today , ARRAYS were discussed in the class. An Array is a group of contiguous or related data items that share a common name.  It enables us to develop concise and efficient programs. Arrays can be of any variable type. This lecture covered - Creating arrays, Declaration of arrays, Initialization of arrays , One Dimensional arrays, Multidimensional arrays , etc.


Examples:

1. Java code for finding the Largest & Smallest number in an Array

   import java.util.*;
    public class test1
    {
        public static void main(String [ ] args)
        {
            int i;
            int numbers []=new int[]{4,65,89,34,71,70,49,22,56,13};
            int smallest= numbers[0];
            int largest= numbers[0];
                    for(i=0;i<numbers.length;i++)
                    {
                        if(numbers[i]>largest)
                             largest = numbers[i];
                     
                          else if(numbers[i]<smallest)
                             smallest=numbers[i];
                           
                      }      
System.out.println("The largest number in this array is:" + largest);
 System.out.println("The smallest number in this array is:" + smallest);
        }
    }




  OUTPUT:
The largest number in this array is:89
The smallest number in this array is:4

Saturday, 26 May 2012

(May 21' 2012 - May 25' 2012)

This whole week, we had brush up sessions to revise all that was done previously  and among the new topics covered, they were Classes and Methods.
             As we know,the class is at the core of Java. It is the logical construct upon which the entire Java
language is built because it defines the shape and nature of an object. As such, the class forms the basis for object-oriented programming in Java. Any concept you wish to implement in a Java program must be encapsulated within a class.
              It defines a new data type. Once defined, this new type can be used to create objects of that type.
Thus, a class is a template for an object, and an object is an instance of a class.
             When we create a class, we will specify the code and data that constitute that class. Collectively, these elements are called members of the class. Specifically, the data defined by the class are referred to as member variables or instance variables. The code that operates on that data is referred to as member methods or just methods.


Example:


public class ClassMethod{
  private String name;
    public void setName(String n){
     
        name = n;
    }
   
    public String getName(){
      
        return name;
    }
   public static void main(String args[]){
   ClassMethod javaClass = new ClassMethod();
      javaClass.setName("Visitor");
      
        System.out.println("Hello " + javaClass.getName());      
   
    }

}




OUTPUT:-


Hello Visitor











Saturday, 19 May 2012

(May 17' 2012 - May 18' 2012)

These two days, we studied Control Statements used in Java. These were similar to those that we used in C++.  Java’s program control statements can be put into the following categories: selection, iteration, and jump. Selection statements allow your program to choose different paths of execution based upon the outcome of an expression or the state of a variable. Iteration statements enable program execution to repeat one or more statements (that is, iteration statements form loops). Jump statements allow your program to execute in a nonlinear fashion.
                 
Java supports two selection statements: if and switch.Java’s iteration statements are for, while, and do-while.Java supports three jump statements: break, continue, and return. All these Control Statements together provide great flexibility to our programs and are really very powerful. The rest is all about their syntax. 

Wednesday, 16 May 2012

(May 14'2012 - May 16'2012)

Its the second week of my training and believe me, the first three days, really had developed an urge and curiosity in me to learn Java. This past weekend, i had searched the Internet extensively to know more about Java.
      Our week started with detailed study of Data Types valid in Java and within first three days of this week, we covered VariablesOperators used in java too, along with the previously mentioned topic.

Java defines eight primitive types of data: byte, short, int, long, char, float, double, and boolean.These can be put in four groups:-

• Integers This group includes byte, short, int, and long, which are for whole-valued signed numbers.

• Floating-point numbers This group includes float and double, which represent numbers with fractional precision.

• Characters This group includes char, which represents symbols in a character set, like letters and numbers.
• Boolean This group includes boolean, which is a special type for representing true/false values.
               The rest of the things we already know as we have studied in C++ , so i think that would be enough about data types. About Variables, they are defined by the combination of an identifier, a type, and an optional initializer. 
Example: int a, b, c; // declares three ints, a, b, and c.
and, char x = 'x'; // the variable x has the value 'x'.


         Similarly, we also know well about operators. Those used in java are Arithmetic, Logical, Assignment, Relational, Bit-wise, Increment/Decrement, Shift, Ternary, Compound Assignment and Typecasting.