Friday, 31 July 2015

The java code to create a Singly Linked List

1)First create a class which has two data members,

package singly_linked_list;

public class NODE
{
int data;
NODE next;//self pointer
}

2)Then utilize the above class by using reference variables as pointers and to insert the data create a instance of it. I have created a class i.e "AscendingLinkedList" this class will insert the data in a ascending order.

package singly_linked_list;

import java.util.Scanner;

public class AscendingLinkedList
{

NODE head = null;
public static void main(String[] args)
{
AscendingLinkedList n1 = new AscendingLinkedList();
boolean conti =true;
while(conti)
{
System.out.println("singly linked list pgm started");
System.out.println("enter your choice");
System.out.println("1.insert");
System.out.println("2.display");

Scanner sc = new Scanner(System.in);
int choice = sc.nextInt();

switch (choice)
{
case 1: n1.insert();
break;
case 2: n1.display();
break;
default: System.exit(0);
break;
}
System.out.println("do you want to continue, if yes press 1 else 0");
int ch = sc.nextInt();
if(ch==1){conti = true;}else{conti  = false;}
}//end of while
System.out.println("sinlgy linked list pgm ended");
}//end of main

public void insert()
{
System.out.println("enter the number to insert");

Scanner sc1 = new Scanner(System.in);

int number  = sc1.nextInt();
NODE cur =null;
NODE new_node=null;

if(head==null)
{
System.out.println("The list is empty inserting the first element");
head =new NODE();
head.data= number;
head.next=null;
System.out.println("insertion successfull!!!!!!!!!");
}

else if(number<=head.data)
{
insert_front(number);
}
else
{
new_node = new NODE();

System.out.println("inserting at the rear");
cur = head;
while(cur.next!=null)
{
cur=cur.next;
}//end of while
cur.next = new_node;
new_node.data = number;
new_node.next = null;
System.out.println("insertion successfull!!!!!!!!!");
}
}//end of insert

public void insert_front(int number)
{
System.out.println("inserting at the front");
NODE cur =null;
NODE new_node=new NODE();

cur = head;
new_node.data = number;
new_node.next=cur;
head=new_node;
System.out.println("insertion successfull!!!!!!!!!");

}//end of inser_front

public void display()
{
NODE cur =null;
if(head.next==null)
{
System.out.print(head.data+"-->");
System.out.print("null");
}
else{
System.out.println("the content of the list are:");
cur=head;
while(cur.next!=null)
{
System.out.print(cur.data+"-->");
cur=cur.next;
}//end of while
System.out.print(cur.data+"-->");
System.out.println("null");
}//end of if_else
}//end of display
}//end of class Nodes

3) Create an another class by name "DescendingLinkedList" that should insert in a descending order.

Sunday, 19 July 2015

I will dedicate this blog to learn and discus "JAVA"




Many students have many doubts about java,even i have the same. But by practicing or by discussing the same with my lectures and with my friends i have cleared those. So in this blog will try to recollect those.

LESSON 1

STARTING WITH JAVA.

By seeing the word JAVA, in our mind so many questions arise,
those are:

1) what is java?
2) why we have to learn java?
3) If we learn java can we develop any thing?
4) If i want to learn java, whether i require the basics of C,C++ or not?

Now i am going to answer those questions:

1) what is java?
Java is programming language, developed by James Gosling.
but when he and his friends develop this programming language they were working in sun Micro system company, so to develop this language they have used the resources of that company that's why it was under the control of sun micro system.

Now coming to what is java, i said it is a programming language.
Now lets understand what is a programming language:
To understand programming language, first we have to understand what is a program.

PROGRAM
PROGRAM is a collection of instructions or set of instructions to the computer to achieve a particular task.

PROGRAMMING LANGUAGE
PROGRAMMING LANGUAGE, is a language which will help to write the program.
But why we have to write the program using programming language only?
The answer is, because when people wants to communicate they use the language, it acts as a communication medium, like that with the computer if we want to communicate we have to learn a programming language.

Like in our normal language, to construct a sentence how we use the grammar like that we have to use the syntax to construct a instruction.

There are several languages available :
C
C++
JAVA
PHP
HTML
.NET etc...

here JAVA comes into picture, so unlike any other programming languages, using java we can communicate with the computer.

Now why we have to use only java, because as i told so many other programming languages are there.

Because java has it's own advantages over other pgm languages.
They are:
1) It is developed based on OOPS concept, i.e everything in java is a object.
2) It is a platform independent pgmming language.
3) It supports WORA i.e Write Once Run Any where, that means  we can develop in one operating         system and we can run it on any operating system.
4) It is freely downloadable.
5) It supports data security by providing encapsulation.

In other programming languages, there are several disadvantages that's why people dont go for other than JAVA.

2) Why we have to learn JAVA?

If we want to compete with the fast moving world, and the whole world is running with java  and there are more than 40 billions of application running based on java.
The more important thing is JAVA has its own advantages against other languages. Thats why we have to learn java.


3) If we learn java can we develop any thing?
The answer to this question i am going to answer at the end of the discussion.


4) If i want to learn java, whether i require the basics of C,C++ or not?
No, C or C++ is not mandatory to learn.But if you know basic of C,C++ then you will be having a idea that how memory will be allocated to variables or objects all those things. If you dont know that also no problem then also we can learn java.





Today i.e on 19/7/2015 at 2055 hrs i have created my life's first blog. I am feeling very happy that even i have a blog.