Sunday, 7 October 2012

EVOLVING FROM C++ TO JAVA-2


TUTORIAL -2

Hi guys,this is my second tutorial in evolving from c++ to java,in my first i said about main function and file naming.In this one i will explaining you how to get AN INPUT AND TO DISPLAY IT.  

Some basic characteristics of java regarding input and output:

Java reads and write inputs as bytes.Java uses I/O streams for input and output operations. Since this is a beginners tutorial i don't want to explain fully about streams.For know you can consider stream's as a buffer ,which can store the data and connect two end points.Since java read's and write as bytes ,we must convert the bytes into different forms during reading data and convert the data that we are going to write into bytes.Java provides different streams for this conversion.For now since you are beginning in java programming i will be explaining you just how to get input and display output,as we go for further.in forth coming  tutorials i will explain you how streams work.

How to get INPUT in java?

I will explain two ways of reading a input in a java program.First i will explain you using BufferedReader.

USING BUFFEREDREADER:

 When we use bufferedreader method it reads the input as line and store it in a string.Even when we read a integer or float value it will take it as string.So when we are reading a integer or float value we must convert the string into regarding values using parse methods.
  • Step 1:Create a object to bufferreader class.Lets for example we can take that object as "in".
in=new BufferedReader(new InputStreamReader(System.in));
  • Step 2:how to use the buffereader object?
TO READ A STRING VALUE:
  • Create a string object and use readLine() or read() method.
String m;
m=in.readLine();
OR
m=in.read();
 read():It reads the string till there is a space.It wont read space,and it wont read after the space.
readLine():It reads including space,till the string we enter ends.
TO READ A INTEGER OR FLOAT OR DOUBLE VALUE
  • Create a string object and read the input using readLine() or read() method.
  • Now using parse method convert the string into your data type.


String m;
m=in.readLine();
int i=Integer.parseInt(m); //converts the string into integer value and assign it to i
Float f=Float.parseFloat(m);//converts the string into float value and assign it to f
Double d=Double.parseDouble(m);//converts the string into double value and assign it to d

Using Scanner class

I prefer to use scanner class,because its simple and easy to use.
  • Step1:Create a object for scanner class.Let the object be"in".
Scanner in=new Scanner(System.in);
  • Step2:Now just call the scanner methods to read value.
TO READ INTEGER:
int i=in.nextInt();//Reads a integer value and assign it to i

TO READ FlOAT:
Float f=in.nextFloat();//Reads a float value and assign it to f

TO READ DOUBLE:
Double d=in.nextDouble();//Reads a double value and assign it to d

TO READ STRING:
String str=in.nextLine();//Reads a string value and assign it to str.

How to display output in java?

The output method to display the result in java is similar to c++ and c.Here we use "System.out.print("") to display the output which is similar to cout and printf.
  • To add more than one data variables ,use + symbol in between them. 
  • To concatenate the data variables to a string,we can use +symbol.
System.out.println("hai");//prints the string hai in a new line.
System.out.print("hai");//prints the string hai in the same line.
System.out.println("hai"+i);//prints the string hai and variable i in a new line.
System.out.print(i+str);//prints the variable i and str in a line.It dose not perform addiction between them.

Note:

There are various method to perform input and output operations.I have just explained some basic methods to read data and display it on screen.




Saturday, 6 October 2012

TORTOISE AND HARE ALGORITHM(Floyd's Cycle Finding Algorithm)

Floyd's Cycle Finding Algorithm

Floyd's cycle finding algorithm is also know as TORTOISE AND HARE ALGORITHM.It is used for two different purposes in data structures.
  • To Find Cycles in graphs.
  • To Find Cycles in  linked list.

Algorithm:

I like to explain the algorithm by means of a singly linked list.We construct a singly linked list with one data member and an address location.The algorithm consist of two pointer,we take them as X and Y
  • LET X BE TORTOISE 
  • LET Y BE HARE

AT STARTING:

  •  LET X BE IN FIRST POSITION 
  • AND Y BE IN Kth POSITION(lets take k as 3rd position).

TRAVERSAL OF  HARE AND TORTOISE

  • Increment the Tortoise position by ONE.(X+1)
  • Increment the Hare position by TWO(Y+2)

IN CASE OF A CYCLE

  • THE TORTOISE AND HARE WILL MEET.
  • OR WHEN THE HARE OVER TAKES THE TORTOISE.


IN CASE IF THERE IS NO CYCLE

  • THE HARE WILL REACH THE END OF THE LINKED LIST.

DISADVANTAGE

  • It has a time complexity of O(length of loop to be find+first node of equal value).

Friday, 5 October 2012

Data Structure Tutorial-1-Singly linked list

Data Structure:

Data can be stored in different ways in a computer system.Data structure explains different ways of storing the data in the computer so that it can be used efficiently. 

Singly linked list:

The most simplest form of data structure is singly linked list.Its simple and it is used to implement other data structures like stack,queue.

ARRAYS VS SINGLY LINKED LIST

  • The single linked list is similar to ARRAYS.It over comes the disadvantage of arrays.
  • The main disadvantage of ARRAYS is, it is difficult to insert or delete an element in it.Singly linked list gives solution to it.
  • In most of the cases arrays size are not dynamic.In some cases array size is insufficient while in others there is lots of memory space get wasted.In singly linked list we have no need to declare the size of it at starting of the program.We can increase the size when ever we need it.So there is no memory wastage in it.

Structure of Singly Linked list:

  1. Head node
  2. Data nodes

HEAD NODE

 The basic structure of linked list is very similar to arrays.The HEAD node consist of the starting address of the first data node in the linked list.Its points to the address of the first data node.

DATA NODE

It consist of two section.The Data section and Address section.The Data section is used to store the data of the node and the Address section is used to point the next data node address.The last data node is called as tail node whose address section is empty.

Traversal

Using the head node we can find the first node.From the head node we can travers through the node using the address pointer.

OPERATIONS IN SINGLY LINKED LIST

  • INSERTION
  • DELETION 
  • SEARCHING

Insertion

  • To insert THE NODE IS LAST POSITION.Create the node and give the tail node address pointer to the new node and make the address section of new node as empty.Thus making the new node as tail node.
  • To insert THE NODE IN BETWEEN THE NODES.Create the node.Traverse through the list and find the node after which the node as to be inserted,lets call that node as X.First copy the address pointer of the X node to the new node.So now the new node will be pointing to next node of the X node.Now change the address pointer of X node to the newly created node.
  • To insert THE NODE AS THE FIRST NODE.Create the node.Now copy the address pointer of head node to new node.Then change the address pointer of the head node to point to the new node.

Deletion 

  • To delete the node in LAST.Traverse through the list and find the node that's before to the last node.Make the address pointer of that node as empty.
  • To delete the node in FIRST position.Copy the address pointer of the first node to the head node.Then make the address pointer of first node to NULL.
  • To delete the node IN MIDDLE.Traverse through the list,find the node that is previous to the node that as to be deleted.Copy the address pointer of the node that as to be deleted to its previous node and make the address pointer of the node to NULL.

Searching

  • Traverse through the node and find the data in a sequential manner.

Advantages of Singly linked list

  • Less memory wastage
  • We can insert and delete nodes to our wish.

Disadvantages of Singly linked list

  • It takes time to search through the list
  • We cannot traverse back through the list.We can traverse in only one way.

Sunday, 30 September 2012

EVOLVING FROM C++ TO JAVA-1

TUTORIAL -1

In this tutorial, i will be saying how to transform from c++ programming to java programming.Since this is the first tutorial,I WILL BE EXPLAINING ABOUT JAVA FILE NAMING AND MAIN SECTION.

JAVA FILE NAMING:

In c++ we can name the program file as we wish.But in java WE MUST NAME THE PROGRAM FILE WITH THE NAME OF THE CLASS THAT CONTAINS THE MAIN FUNCTION or else WHILE RUNNING WE MUST RUN WITH THE CLASS NAME THAT CONTAINING THE MAIN FUNCTION.This helps the compiler to understand that there is a class in the name of the file and it contains main function.The compiler will start reading from that class,staring it from the main function.And another thing we must care about it is, There can be ONLY ONE PUBLIC CLASS FUNCTION IN A JAVA PROGRAM.We cannot have more than one public class in java. 

For example:

A c++ program:

public class A
{
       .......
       ........
}
public class B //more than one class can be public
{
     ....................
     ....................
}

 public void main()// the main function can be out of the class
        {
             ..................
             .................
             .................
         }
FILE NAME: example.cpp

A java program:

public class A   //must name the file name with this class name
{
     public static void main(String args[]) // main function must be inside the class
     {
        ...............
        ...............
        ...............
      }
}
class B    //only one class can be public
{
    ................
    ................
}
FILE NAME: A.java

JAVA MAIN FUNCTION:

Syntax: public static void main(String args[])

We must declare THE MAIN FUNCTION AS STATIC because it helps the compiler to call the main function without any object.A STATIC MAIN FUNCTION DOESN'T NEED A OBJECT TO BE CALLED.TheString args[] parameter helps to pass the value from command line.The value passed are stored in string args array.We must declare the main function as public too.

Saturday, 10 December 2011

CLOUD COMPUTING

Hi guys,actually i just reed a article in paper that almost 91% of IT people don't know whats cloud computing where as two third of business people know about it.So i decide to give some basic information about cloud computing in this post.To say in simple words cloud computing is resource sharing technology,we are living in IT age where software products are very costly and difficult to buy but we need it as a part of our life.Cloud provides a way that they will allow us to use the software for a limited period of time in basis of rent.Instead of buying the whole software that we use them for a short period of time, we can use the software for a small rent,we can do our work in our personal system but the program will be installed in server and we save and retrieve the data from the server.And we use cloud computing service in day to day activities without knowing that these are some application of cloud computing technology.For example all the e-mail service providers ,for example gmail,yahoo,hotmail etc use cloud computing technology ,our e-mail accounts are stored in the server and we use the data from the server when ever we need.When come to IT companies they use cloud computing technology for software sharing purposes.All software's are uploaded and stored in server when a customer needs it ,can use at user end without knowing the other details,its like our household electricity board that we use power but we don't know from where it comes and how it is generated.Cloud computing as made revolution in software technology.It made us to use all software in a very easy way and less expensive way.

I series processors by INTEL

Hi guys.They say this is the year of 2nd generation processors.Intel is the one of the leading processors company in world have introduced there I series range processors namely i3,i5,i7.I am gonna explain some of the features between these three processors.These processors are first can be classified based on there using purposes, the i3 are for the low performance computers and i5 are for the medium range performance computers.The i7's are the high performance processors that are available in market in current date.When we compare in bases of cores, i3 &i5 have 2-4 cores while i7 have 4 core processors.In basis of threads i3&i5 have 4 threads and i7 have 8threads.All three processors namely i3,i5,i7 have hyper threading  which is used for efficient use of processor resources. In case of cache memory i3 have 3-4mb memory while i5 & i7 have 3-8mb and 4-8mb respectively .In case of heat reduction technology i3 processors are better than i5.But i5 and i7 have turbo boost mode which turns off the core when its not in use.I3 uses 32 nm silicon while i5 and i7 uses 32nm-45nm silicon .So i think that i have listed out most of the difference between this three processors.So when you are going to buy a computer choose the right one based on your need.I can't say which is the best processor out of this three but i can say each processors are designed to do a particular job and they are best in it.

Friday, 9 December 2011

PHP

PHP-PHP hypertext processor .Php is a very powerful language used for web and internet purposes.Here i am gona give a short information about php for beginners.Php is a simple language it is a object oriented language .Php in most case is embedded into HTML code.A php code starts from <? and it as a end tag ?> .But HTML code cannot be used inside php tag.Php looping statements and control statements are similar to object oriented programming language statement.We can reed values from a user using html forms from website and process it using php program.We can transmit values from html forms to php program in two ways they are POST and GET.In POST the data is secure but in GET the data is visible to to others .This are the some of the basic information you need to know about php language.ALL THE BEST