Featured Article

Monday, 17 June 2013

multithreading

saturday we had our class from 9-12:30
we were taught  multithreding 
multithreading ----------it is a conceptual programing where a program is divided into two or more sub programing which can  be implemented at the same time in parallel
in most our computers we have single processor and therefore i reality the processor is doing only one thing at a time however the processor switches between the processes so fast that it appears us that all the processes are processing at the  same time
:::multithreading in java is done in two ways
*by using thread class
*by using runnable interface


some examples 
1)using thread class

class First extends Thread
{
public void run()
{
for (int i=0;i<5;i++)
{
System.out.println("value of i"+i);
}}}
class Second extends Thread
{
public void run()
{
for (int j=0;j<5;j++)
{
System.out.println("value of j"+j);
}}}
class Third extends Thread
{
public void run()
{
for (int k=0;k<5;k++)
{
System.out.println("value of k"+k);
}}}
class Threads
{
public static void main(String arg[])
{
First thread1=new First();
Second thread2=new Second();
Third thread3=new Third();
thread1.start();
thread2.start();
thread3.start();
}}




2)using runnable class

 class First implements Runnable
{
public void run()
{
for (int i=0;i<5;i++)
{
System.out.println("value of i "+i);
}}}
class Second implements Runnable
{
public void run()
{
for (int j=0;j<5;j++)
{
System.out.println("value of j"+j);
}}}
class Third implements Runnable
{
public void run()
{
for (int k=0;k<5;k++)
{
System.out.println("value of k "+k);
}}}
class Testrunnable
{
public static void main(String arg[])
{
First fobj=new First();
Second sobj=new Second();
Third tobj=new Third();
Thread thread1=new Thread(fobj);
Thread thread2=new Thread(sobj);
Thread thread3=new Thread(tobj);
thread1.start();
thread2.start();
thread3.start();
}}
 

:::life cycle of a thread
during the life time of a thread there are different states in which the thread passes
1)new born state
2)runnable state
3)running state
4)dead state


1)new born state--------when we create a new process it enters this state
2)runnable state --------it means the process is ready to use  and is waiting for resources
if two threads have equal priority then are given time slots
3)running state  --------running means that  the  processor has given its time to the thread   




after this we had a gd session and we discussed some topics and got  a lot to learn

Friday, 14 June 2013

STRING BUFFER

in this discussion we will discuss about buffer string buffer
 [12:30-3:30]--PROGRAM USING STRING BUFFER.....which includes
----)buff.delete(2,3 );////////////////////to delete char from 2-3
-----)buff.deleteCharAt(i );///////////delete the char at position i
-----)buff.capacity( );////////////////////length+16
-----)buff.append();//////////////////////append
-----)buff.reverse();/////////////////////to reverse a string
-----)buff.setLength();
-----)buff.insert(0," xknakgs");/////////////////////to insert  any string at position 0

import java.io.*;
import java.lang.*;
class Using_buffer

{
public static void main(String arg[])
{
StringBuffer buff=new StringBuffer("manu");
System.out.println("buffer = "+buff);//////////////////////////manu
buff.delete(1,2);
System.out.println("buffer after delete func = "+buff);////////mnu
buff.append(" manpreet ").append(" kaur ").append(" arora ");
System.out.println("buffer = "+buff.toString());/////////////////////////////mnu manpreet kaur arora
buff.setLength(20);
System.out.println("buffer = "+buff);///////////mnu manpreet kaur ar
buff.setLength(15);
System.out.println("buffer = "+buff);///////////mnu manpreet kau
buff.delete(0,3);
System.out.println("buffer="+buff);///////////manpreet kau
buff.insert(0,"hello");
System.out.println("buffer = "+buff);////////hello manpreet kau
System.out.println("buffer capacity="buff.capacity());///////36

}}


import java.lang.*;
public class Stringbuffer1
{
public static void main (String arg[])
{
StringBuffer buff=new StringBuffer("jasleen kaur");
System.out.println("buffer="+buff);
buff.delete(4,9);
System.out.println("after deletion"+buff);
System.out.println("after deletion"+buff.deleteCharAt(4));
System.out.println("capacity is"+buff.capacity());
buff.setLength(5);
System.out.println("buffer is"+buff);
buff.append("hello").append("java");
System .out.println(buff.toString());
StringBuffer buff1=new StringBuffer();
buff1.insert(0,2012);
buff1.insert(0,"java");
buff1.insert(0,"hello");
System.out.println("buffer is"+buff1);
System.out.println("reverse is"+buff1.reverse());

}
}


[3:30-6:30]-Than we had studied about EXCEPTION HANDLING

ERROR-Its is a condition in the program which may produce wrong result or interrupt the program.
three types of error..
1)compile time error-which include syntax error.
2)logical error-(eg. using greater than sign instead of less sign)
3)runtime error-(eg.divide by 0)
EXCEPTION HANDLING-In prog.lang some time our prog. compile or execute successfully but it compile
successfully and fail to execute the prog. such type of error interrupt the program and run time environment of the lang. automatically trow appropriate exception.

TYPES OF EXCEPTION CLASSES
1)builtin-which are already define  within the lang.
5 RESERVE KEYWORD
-try
-catch
-throw
-throws
-finally
some of the inbuilt exceptions are..........
-Arithmetic Exception
-ArrayIndexOutOfBoundException
-ArrayStoreException
-ClassCastException
-IllegalArguementException etc....
2)user defined exception-it can be created by user itself..
some of the user defined exceptions are
-Throwable FillInStackTrace()
-)Throwable GetCause()
-String GetLocalizeMessage()
-String GetMessage()
-Void PrintStackTrace()



Wednesday, 12 June 2013

string handling

today we had a class on string handling it was great ok now we will discuss about it

String a="Manpreet kaur";
 String s1=new String(a);------------------passing a string to constructor 
String s2=new String(s1);------------------                       ,,


a.concat(b)----------------------------to cocatinate two strings
a.toUpperCase()---------------------convert all the characters to upper case
a.toLowerCase()---------------------convert all the characters to lower case
b.trim()--------------------------------trim is to remove extra spaces in the string
a.equals(c)----------------------------compare if two strings are equal or not its case sensitive
a.length()------------------------------to calculate the length of the string like in string "manpreet"=8
a.startsWith("M")--------------------passes true or false checking if the string is starting from M case                                                            sensitive
a.charAt(4)----------------------------gives the character present on 4th position (starting from 0)
 a.equalsIgnoreCase()----------------compare the two string without concerning lower or upper case
a.indexOf('e')--------------------------search for the e occurring for the first time and ans the position                                                             (starting from 0)
a.lastIndexOf('e')---------------------searching for the last occurrence of e and return its position
                                                        (count starts fronm starting and starting from 0)


ONE  EXAMPLE 


import java.lang.String.*;
import java.io.*;
class String_fun
{
public static void main(String arg[])
{
try
{String num=new String("welcome");

String a="Manpreet kaur";
char ch[]=new char[7];
String s1=new String(a);
String s2=new String(s1);
System.out.println(s1);
System.out.println(s2);
String b=" jasleen kaur ",c="MANPREET KAUR";
System.out.println(a+" first string");////////////////////////////Manpreet kaur first string
System.out.println(b+" second string");////////////////////////    jasleen kaur   second string
System.out.println(c+" third string");///////////////////////////MANPREET KAUR third string
System.out.println(a.concat(b)+"are friends");////////////////Manpreet kaur   jasleen kaur   are friends
System.out.println(a.toUpperCase()+"  to upper case");///MANPREET KAUR to upper case
System.out.println(a.toLowerCase()+" to lower case");//manpreet kaur to lower case
System.out.println(b.trim()+" trim");//////////////////////////jasleen kaur
System.out.println(a.equals(c)+" without ignore case");//true
System.out.println(a.length()+"  length of string");////////8
System.out.println(a.startsWith("M")+" string starting with M");//true
System.out.println(a.charAt(4)+" char at position 4");////////////////r
num.getChars(4,6,ch,0);
System.out.println(ch);//////////////////////////////////////////ree
}
catch(ArrayIndexOutOfBoundsException obj)
{}
}}

result day

yesterday our 4th sem result was out and we were so exited we  all got good marks and enjoyed the day . we enjoyed our day with a pizza party it was awesome
then we had a class on string i.e string handling
i m sharing some functions with u on stings
let String a="manpreet";String b="Manpreet"

String output=a.tolowerCase()
manpreet
String output=a.upperCase();
MANPREET
String output=a.replace('m','n');
nanpreet
String output=a. equals(b);
0
String output=a.length()
8
String output=a.charAt(5);
e
String output=a.indexOf('e');
8
String output=a.equalsIgnorecase(b);
1
 

Monday, 10 June 2013

GD &PI

yesterday we practiced some topics on GD and had some tips on PI  
GD &PI the important words for job    if u want a job u have to crack GD &PI ------------------
GD------- group discussion ----------in which a group is given a topic and u have to give your points on that topic but don,t argue with anyone there are many dos and don't s u should not say anyone that u r wrong  or i don't agree with u or no its not like this __________
u must speak your point loudly and confidently try to give more and more points but don't have point to point discussion i.e fight in two people on some point  ----
PI--------------------personal interview ----------in this u have to go in front of hr and represent yourself   first knock the door and go in wish the hr with a cute smile and don't sit until he says u sit and thanks him for offering the seat and then ans all the questions he ask try to admit if u don't know anything say it i don't know admit it its good u must know your strength and weakness and try to present your weakness in positive way like u are lazy u can say  i m lazy but to overcome this i set my goal and complete it on time and similarly u can say something positive with your weakness okkkk

Saturday, 8 June 2013

PACKAGES --INBUILT OR USER DEFINED

it was very good we were taught to create user defined packages it was interesting
PACKAGES ------->
Packages r java's way of grouping a variety of classes or interfaces together
in this we can create a package and use if again and again or u can say code re useability
like u use a import java.io. package (inbilt) we will use our own packages (user defined packages)
some points ----)two different packages can have classes of same name
------)they provide a way to provide classes for excidential   (chori) use
TYPES OF PACKAGES
as i told u above we have two types of packages inbuilt and user defined


inbuilt ---- java.io.............java.util...........java.awt..............java.lang........java.applet etc
user defined packages r -----like u created a package containing factorial class and then call it while writing a prog for factorial
these packages r stored in a new folder



and then save the classes created in this package

and then make your program using mypack



import mypack.*;
import java.io.*;
import java.util.*;
class Testmypack
{
public static void main(String arg[])throws IOException
{
DataInputStream dis= new DataInputStream(System.in);
System.out.println("enter the no whose factorial to be calculated");
int n=Integer.parseInt(dis.readLine());
Factorial obj=new Factorial();
int res=obj.fact(n);
System.out.println("factorial of"+n+" is"+res);
}}






PROG FOR CREATING PACKAGE IS

package mypack;
 public class Factorial
{
public int fact(int n)
{
int f=1;
for(int i=1;i<=n;i++)
{
f=f*i;
}
return(f);
}}


TRY THIS PROG U WILL SURELY GET HOW TO CREATE YOUR OWN PACKAGES



ONE MORE EXAMPLE

 package mypack;
 public class Reverse
{
public int rev(int n)
{
int r=0;
while(n>0)
{
r=(r*10)+(n%10);
n=n/10;
}
return(r);
}}


import mypack.*;
import java.io.*;
class Testreverse
{
public static void main(String arg[])throws IOException
{
DataInputStream dis= new DataInputStream(System.in);
System.out.println("enter the no whose reverse to be calculated");
int m=Integer.parseInt(dis.readLine());
Reverse obj=new Reverse();
int res=obj.rev(m);
System.out.println("reverse of"+m+" is"+res);
}}






Friday, 7 June 2013

inheritance

INHERITANCE-----> in java we have 3 types of inheritance
single level
multilevel
hierarchical

INHERITANCE ---------------------
class Abc
{int a;
void geta()
{
 a=5;
}
int input()
{
return(a);
}
}
class Xyz extends Abc
{int z;
void get()
{
 int x;
x=8;
 z=x;}
void display()
{
System.out.println(z);
}}

class Inherit
{
public static void main(String arg[])
{
Xyz a1=new Xyz();
a1.geta();
a1.get();
int l=a1.input();
System.out.println(l);
a1.display();
}}

Thursday, 6 June 2013

overloading

 it was a great day today weather was cool .............
i enjoyed today's lecture we did .....
OVERLOADING -----overloading is a way to perform multiple different different similar personality task with single object .its advantage is that user has to remember single object name...... basically  there are 2 types of overloading
1----->operator overloading
2----->function overloading
1-->operator overloading is technique to perform diff task with single operator based on type of argument
java does not allow the concept  of operator overloading
2-->when we define multiple methods with same name but either diff arguments or diff data types its called method overloading or function overloading



Wednesday, 5 June 2013

sorting

wow finally after silly errors i got it correct
i m sharing my sorting programs with u
import java.io.*;
class Ascending
{
public static void main(String arg[]) throws IOException
{
int a[]=new int[5];int j,i;
DataInputStream dis=new DataInputStream(System.in);
System.out.println("enter nos");
for(i=0;i<5;i++)
{
a[i]=Integer.parseInt(dis.readLine());
}
for(j=0;j<5;j++)
{
    for(i=j;i<5;i++)
    {
    if(a[j]>a[i])
    {
    int temp=a[j];
    a[j]=a[i];
    a[i]=temp;
    }
    }
}
for(j=0;j<5;j++)
{
System.out.print(" "+a[j]);
}
}}

------------------------------------------------------------------------------------------------------------------

import java.io.*;
class Descending
{
public static void main(String arg[]) throws IOException
{
int a[]=new int[5];int j,i;
DataInputStream dis=new DataInputStream(System.in);
System.out.println("enter nos");
for(i=0;i<5;i++)
{
a[i]=Integer.parseInt(dis.readLine());
}
for(j=0;j<5;j++)
{
    for(i=j;i<5;i++)
    {
    if(a[j]<a[i])
    {
    int temp=a[j];
    a[j]=a[i];
    a[i]=temp;
    }
    }
}
for(j=0;j<5;j++)
{
System.out.print(" "+a[j]);
}
}}

Tuesday, 4 June 2013

SOME BASIC PROGRAMS

today we were bored and exhausted practical time was good but theory was boring
we did casting conversions
run time input methods
array

 Q)MAKE A PYRAMID
*
**
***
****
ANS:

class Pyramid
{
public static void main(String arg[])
{int i,j;
for(i=0;i<4;i++)
{
for(j=0;j<=i;j++)
{System.out.print("*");
}
System.out.println("");
}}}



Q)CHECK IF NO IS PALINDROME
ANS:
class Palindrome
{
public static void main(String arg[])
{
int a,b,c,d;
a=Integer.parseInt(arg[0]);
b=Integer.parseInt(arg[1]);
c=Integer.parseInt(arg[2]);
d=Integer.parseInt(arg[3]);
if((a==d)&&(b==c))
{
System.out.println("no is palindrome");}
else
{
System.out.println("no is not palindrome");}
}}


Q)PRINT NO FROME 0 TO N
ANS:
class Print0ton
{
public static void main(String arg[])
{
int a;
a=Integer.parseInt(arg[0]);
for(int i=a;i>=0;i--)
{
System.out.println(i);
}
}}

Q)TO REVERSE A GIVEN NO
 ANS:
class Reverse
{
public static void main(String arg[])
{
int a,b,c,d;
a=Integer.parseInt(arg[0]);
b=Integer.parseInt(arg[1]);
c=Integer.parseInt(arg[2]);
d=Integer.parseInt(arg[3]);
System.out.print(" "+d+" "+c+" "+b+" "+a);
}}

Q) WAP IN JAVA TO FIND SMALLEST OF NO.S
ANS
class Smallest
{
public static void main(String arg[])
{
int a,b,c,d;
a=Integer.parseInt(arg[0]);
b=Integer.parseInt(arg[1]);
c=Integer.parseInt(arg[2]);
if((a<=b)&&(a<=c))
System.out.println("smallest no is "+a);
else if((b<=a)&&(b<=c))
System.out.println(" smallest no is"+b);
else
System.out.println("smallest no is "+c);
}}




Monday, 3 June 2013

PROGRAM STARTER

yesterday was my first day of training it was great
i m sharing some programs
Q) TAKE A NO FROM USER AND PRINT THE CORRESPONDING WEEKDAY
class Weekdays
{
public static void main(String arg[])
{
int a;
a=Integer.parseInt(arg[0]);
switch (a)
{
case 1:
{
System.out.println("monday");break;
}
case 2:
{
System.out.println("tuesday");break;}
case 3:
{
System.out.println("wednesday");break;}
case 4:
{
System.out.println("thursday");break;}
case 5:
{
System.out.println("friday");break;}
case 6:
{
System.out.println("saturday");break;}
case 7:
{
System.out.println("sunday");break;}
default:
System.out.println("wrong choice");
}}}



Q)WAP TO CHECK WEATHER THE PROGRAM IS DIVISIBLE  BY 3 AND 5 AND 7
class Divisible357and
{
public static void main(String arg[])
{
int a;
a=Integer.parseInt(arg[0]);

if(((a%3==0)&&(a%5==0))&&(a%7==0))
System.out.println("yes diviseble by all 3 5 7");
else
System.out.println("not diviseble by all 3 5 7");
}
}



Q)WAP TO PRINT ALL THE FACTORS OF A NO
class Factor
{
public static void main(String arg[])
{
int n;int c;
n=Integer.parseInt(arg[0]);
for(int i=1;i<=n;i++)
{if(n%i==0)
System.out.println("factor of n is "+i);
}
}}





Q)WAP TO PRINT FIBONACCI SERIES

class Fibnoci
{
public static void main(String arg[])
{
int n;int a=0,b=1,c;
System.out.println(a);
System.out.println(b);
n=Integer.parseInt(arg[0]);
for(int i=1;i<=n-2;i++)
{c=a+b;a=b;b=c;
System.out.println(c);
}
}}


Q)WAP TO CHECK WHETHER THE YEAR IS LEAP OR NOT

class Leapyear
{
public static void main(String arg[])
{
int a;
a=Integer.parseInt(arg[0]);

if(a%4==0)

System.out.println("leap year");
else
System.out.println("not a leap year");
}
}

Q)WAP TO MULTIPLY N NOS OF SERIES

class Multiplyn
{
public static void main(String arg[])
{
int n,m=1;
n=Integer.parseInt(arg[0]);
for(int i=1;i<=n;i++)
{m=m*i;}
System.out.println("multiplication  of series "+m);

}}



Q)WAP TO PRINT TABLE OF N NO

class Tablen
{
public static void main(String arg[])
{
int n;int c;
n=Integer.parseInt(arg[0]);
for(int i=1;i<=10;i++)
{c=n*i;
System.out.println(n+" * "+i+" = "+c);
}
}}

Q)WAP TO SUM ODD NO OF SERIES

class Sumodds
{
public static void main(String arg[])
{
int n=13,sum=0;

for(int i=1;i<=n;i++)
{if(i%2!=0)
sum=sum+i;}
System.out.println("sum of series "+sum);

}}


Q)WAP TO PRINT OOD NO IN SERIES OF N NOS

class Oddseries
{
public static void main(String arg[])
{
int n;
n=Integer.parseInt(arg[0]);
for(int i=1;i<=n;i++)
{if(i%2!=0)
System.out.println(i);
}
}}


Q)WAP TO CALCULATE THE AREA OF CIRCLE

class Areacircles
{
public static void main(String arg[])
{
int a;double c;
a=Integer.parseInt(arg[0]);
c=3.14*a*a;

System.out.println("area of circle of is"+c);
}
}


Q)WAP TO PRINT GRADE TO CORRESPONDING PRECENTAGE



class Grading
{
public static void main(String arg[])
{
int n;
n=Integer.parseInt(arg[0]);
if(n>=80)
System.out.println("s grade");
if((n>=75)&&(n<80))
System.out.println("a grade");
if((n>=70)&&(n<75))
System.out.println("b grade");
if((n>=60)&&(n<70))
System.out.println("c grade ");       
if((n>=50)&&(n<60))
System.out.println("d grade");
if(n<50)
System.out.println("fail");
}
}