Wednesday, 11 July 2012

(July 3' 2012 - July 10' 2012)

After going through so many websites and a huge search manually, I finally had chosen a topic for my project. Yes, finally..!! I decided to code for a Client- Server Chat Application. 
        After having learnt the graphical aspects of java, i began with JTextfields, JButtons , JLabels, JTextAreas, etc etc and started designing the project. It took me about 2-3 days to complete the basic architectural structure of the project.

                     The difficult part was yet to begin..! My technical trainer told me, that i need to know some topics of advanced Java (apart from my core Java course) in order to complete this project. I was a bit frightened , learning the time duration that i had was very little. But within this time, i got to know that vacations were extended , so i again started with my project with full zeal and by this time my 4th semester result was also out and thankfully to God, i cleared the 2nd year of my degree too.
                   Coming back to project discussion..!! So the toughest part regarding this project was the Socket Programming. After inter-linking all the classes to the main class, i began working with socket programming. Though it was quite tough, but in the end, all efforts proved to be fruitful .I cant explain the feeling that i went through when i saw that messages were actually getting transferred from client to server and vice-versa.
             Since now i am almost done with the basic part (excluding improvements to make it more appealing), so here i am posting some snapshots of how this project looks .













































Well, thats the happy ending of this memorable learning experience . !! 

Monday, 2 July 2012

Monday (July 2' 2012)

These being the last 2 days for our theory classes, we were taught about Database Management. We were briefly introduced with MS Access and SQL. SQL stands for Structured Query Language and is a standard language for accessing databases. Now we know how to handle or manipulate data in MYSQL , SQL Server, ACCESS, etc.
           A database most often contains one or more tables. Several commands are used to handle queries or to insert, delete or show the entries in a table.

Example:-

The INSERT INTO Statement

The INSERT INTO statement is used to insert a new row in a table.

SQL INSERT INTO Syntax-


INSERT INTO table_name VALUES (value1, value2, value3,...)

and the MySQL Command Line Client looks like ->

















Sunday, 1 July 2012

(June 27' 2012 & June 30' 2012)

Continuing with the Graphical aspects, now we were taught about Swings. Swing is built on the foundation of the AWT. It has lightweight components and a pluggable look and feel. A Swing GUI consists of two key items: components and containers. The main package is javax.swing. This package must be imported into any program that uses Swing. It  the classes that implement the basic Swing components, such as push buttons, labels, and check boxes.


Example: demonstrating how to change font of JTextField's text using Java Swing JTextField class.


import java.awt.FlowLayout;
import java.awt.Font;
import javax.swing.JApplet;
import javax.swing.JTextField;

public class TextFieldTest extends JApplet{
      
        public void init(){
                this.getContentPane().setLayout(new FlowLayout());
                JTextField field = new JTextField("JTextField Change Font",30);
              
                Font font = new Font("Courier", Font.BOLD,12);
                field.setFont(font);

                add(field);
        }
}


OUTPUT:- 





Tuesday, 26 June 2012

(June 25' 2012 & June 26' 2012)

We were taught about Applets these days. I was quite bored  writing the codes and seeing the  output on the console and dancing with joy that the code actually worked, but now began the interesting part when we started with the graphical side of java.
                An applet is a special kind of Java program that is designed to be transmitted over the Internet and automatically executed by a Java-compatible web browser. Applets use the AWT.
     Applet provides all necessary support for applet execution, such as starting and stopping. It also provides methods that load and display images, and methods that load and play audio clips.

      Example :  A simple example that shows colored text using java applet and color classes.

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;


public class ColorHello extends Applet{
      
        public void paint(Graphics g){
              
                g.setColor(Color.blue);
             
                g.drawString("Hello World...",30,180);
        }
}


OUTPUT:-








Friday, 22 June 2012

(June 18' 2012 - June 22' 2012)

First 3 days of this week we learned about Generics & Collections and on 21st-22nd, we had tests and brush-up sessions.TheA collection is a group of data manipulate as a single object. term generics means parametrized types. Using generics, it is possible to create
a single class that automatically works with different types of data.

Example:

import java.util.ArrayList;
import java.util.List;
public class GenericList {
   
public static void main(String[] args) {
     
List list=new ArrayList();
         list
.add("aaa");
         list
.add("bbb");
         list
.add("fff");
         list
.add("ccc");
         list
.add("ddd");
         
System.out.println(list);
   
}
}
 
Output:

[aaa, bbb, fff, ccc, ddd]


Collections A collection is a group of data manipulate as a single object. These are similar to C++'s Standard Template Library (STL) and contain only Objects (reference types).

Example:-

import java.util.HashSet;
import java.util.Collections;

public class Collection{

  public static void main(String[] args) {
 
    HashSet hashSet = new HashSet();
  
    hashSet.add(new Long("92"));
    hashSet.add(new Long("42"));
    hashSet.add(new Long("23"));
    hashSet.add(new Long("32"));
  
    Object obj = Collections.min(hashSet);
  
    System.out.println("Minimum Element of Java HashSet is : " + obj);
  }
}


OUTPUT:

Minimum Element of Java HashSet is : 23





Friday, 15 June 2012

(June 14' 2012 - June 15' 2012)

We discussed the concept of Threads these 2 days. Java uses threads to enable the entire environment to be asynchronous. This helps reduce inefficiency by preventing the waste of CPU cycles. Also threads exist in several states such as running, ready to run, suspended, resumed, blocked.

          Creating a Thread: This can be do.ne by instantiating an object of type Thread. For this we can,
i) Implement the Runnable interface ,or
ii) Extend the Thread class itself.

Example:

          public class Threads{
  public static void main(String[] args){
  Thread th = new Thread();
  System.out.println("Numbers are printing line by line after 2 seconds : ");
  try{
  for(int i = 1;i <= 5;i++)
    {
  System.out.println(i);
  th.sleep(2000);
  }
  }
  catch(InterruptedException e){
    System.out.println("Thread interrupted!");
  e.printStackTrace();
  }
  }
}


OUTPUT-

Numbers are printing line by line after 2 seconds :
1
2
3
4

5



   Similarly, our program can spawn as many threads as it needs.

Wednesday, 13 June 2012

(June 9' 2012 - June 13' 2012)

All these days, we had tests and brush-up sessions. Our trainers focused on making strong our previously done Java concepts. I also had decided about my project by now and have started researching about it. We will be starting new concepts from tomorrow onwards and hopefully will start working on my project this week..!!

Friday, 8 June 2012

Friday (June 8' 2012)

Today, we were taught about Exception Handling. An exception is a run-time error. Exception Handling is managed by 5 keywords - try, throw, throws, catch and finally. All exception types are subclass of built-in class "Throwable". This concept has 2 advantages:-
*We can fix errors ourselves.
*It prevents programs from automatically terminating.

Example:-

public class ExceptionHandling {
    public static void main(String args[])
    {
        int a,d;
        try{
            d=11;
            a=d/0;
            System.out.println("This wont be printed.");
        }
        catch(ArithmeticException e)   
        {
            System.out.println("Division by Zero");
        }
            System.out.println("This is an after Catch statement");
    }
    
}




OUTPUT:




Division by Zero
This is an after Catch statement




Tuesday, 5 June 2012

Tuesday (June 5' 2012)

Today we were taught "How to Import a Package in ECLIPSE?" and about Interfaces . We can create as many classes in a package as we want and then by using that package in a separate class, we can call all those classes that have been previously created. Creating our own package saves memory, as the package stores all those classes inside it a separate buffer memory.
                                                         Using the keyword interface, you can fully abstract a class’ interface from its implementation.That is, using interface, you can specify what a class must do, but not how it does it.Using the keyword interface, you can fully abstract a class’ interface from its implementation.That is, using interface, you can specify what a class must do, but not how it does it.


Example:-

1.Creating a Package and Importing it in a separate class.

//Creating Package

package mypackage;
    public class Normal
{
        public void display()
        {
        System.out.println("Hello World");
        }
}

//Importing Package


import mypackage.*;
public class Myclass
{
    public static void main(String []args)
    {
        Normal n=new Normal();
        n.display();
    }
}
       

OUTPUT:
                    Hello World

Monday, 4 June 2012

Monday (June 4' 2012)

A whole new week starts. Got up at 6 a.m, was at the bus stand by 7a.m. and finally reached Chandigarh at about 9:30 a.m. Today, we were taught about the concepts of Vectors, String Buffer, Inheritance and use of Super keyword  in case of Java. Vector class can be used to create a generic dynamic array known as vector that can hold objects of any type and any number. While String creates strings of fixed length, String Buffer created strings of flexible length. Inheritance in Java has same concept as Inheritance in C++ , though Java do not support multiple and hybrid types of Inheritance.


Example:-

1. Java code showing use of Super keyword and also involving concept of Inheritance.


import java.util.*;
public class abc {
    int a,b;
    abc(int x,int y)
    {
        a=x;
        b=y;
    }
    void show()
    {
        System.out.println("A="+a);
        System.out.println("B="+b);
    }
}
    class Area extends abc
    {
        Area()
        {
            super(4,6);
        }
            void calarea()
            {
                int ar=a*b;
                System.out.println("Area="+ar);
            }
    }
class Alpha
{
    public static void main(String [] args)
    {
        Area obj=new Area();
        obj.show();
        obj.calarea();
    }
}



OUTPUT:-

   A=4
   B=6
   Area=24

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.


Saturday, 12 May 2012

First Week Of Training (May 9' 2012-May 11' 2012)

May 9'2012 -
Today was the first day of my 6 week Industrial Training. I had enrolled for the Core Java course at HCL CDC (Career Development Center) Chandigarh. We were introduced to our technical trainer Ms.Upasana Khare , our technical head Ms.Cheena and center head Mr.Ashish Koul. The first class started with an introductory session. We were told about the rules and regulations and a pre-plan of how the training will proceed.

May 10'2012 -
On the second day, our C++ concepts were brushed up and tested. We went through Polymorphism, Encapsulation, Inheritance, Abstraction, Classes, Objects and all the OOP concepts. After this, we were told about the Birth of Java and about the rest of its history and evolution. The class left me in anticipation and curiosity to learn more about this programming language.

May 11'2012 -
We were already told about Java's history and evolution. Today, i was taught the syntax for a basic java program and about java tokens in detail. I made my first program in java today. Initially we used Notepad and Command Prompt i.e without an Integrated Development Environment (IDE) to run the program, then we used Netbeans 7.1.2 i.e in an IDE.

Syntax for a simple java program:



public class Classname {
    public static void main(String args[ ])
    {
        System.out.println("Hello World");
    }
}

OUTPUT:-

Hello World