Get Some Free Products at your Door Step. Just feed ur Address in dis Link...!!

Sunday, November 27, 2011

Multiple work through multithreading...!!

import java.util.logging.Level;
import java.util.logging.Logger;

class mthreading
{
public static void main(String ar[])
{
new work1();
System.out.println("Main");
new work2();
System.out.println("Main");
new work3();
System.out.println("Main");
}
}
class work1 implements Runnable
{
Thread wt;
work1()
{
wt = new Thread(this,"Work1");
wt.start();
}
public void run()
{
System.out.println("Work one is activated");
try {
wt.sleep(1000);
} catch (InterruptedException ex) {
Logger.getLogger(work1.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
class work2 implements Runnable
{
Thread wt2;
work2()
{
wt2 = new Thread(this,"Work2");
wt2.start();
}
public void run()
{
System.out.println("Work two is activated");
try {
wt2.sleep(1000);
} catch (InterruptedException ex) {
Logger.getLogger(work1.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
class work3 implements Runnable
{
Thread wt3;
work3()
{
wt3 = new Thread(this,"Work3");
wt3.start();
}
public void run()
{
System.out.println("Work three is activated");
try {
wt3.sleep(1000);
} catch (InterruptedException ex) {
Logger.getLogger(work1.class.getName()).log(Level.SEVERE, null, ex);
}
}

}

Tuesday, November 8, 2011

Overloading of Main in Java

public class mainOverload
{
public static void main(String a[])
{
System.out.println("hi");
mainOverload ov = new mainOverload();
ov.main(1);
}
public static void main(int a)
{
System.out.println("hello");
}
}

Font Handling Program in Java

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;

public class fontex implements ActionListener
{
JFrame f = new JFrame("Font");
JButton b = new JButton("Click me");
JTextArea jt = new JTextArea("Simple Text");

public static void main(String a[])
{
fontex fx= new fontex();
fx.design();
}
public void design()
{
f.getContentPane().add(BorderLayout.CENTER,jt);
f.getContentPane().add(BorderLayout.EAST,b);
b.addActionListener(this);
f.setSize(500,500);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
Font f =new Font("Arial",Font.BOLD|Font.ITALIC,25);
jt.setFont(f);
}
}

Java : Convert Ip address into domain

import java.net.InetAddress;
import java.net.UnknownHostException;

public class cnvrtIptodomain
{
public static void main(String ar[])
{
cnvrtIptodomain c = new cnvrtIptodomain();
c.start();
}
public void start()
{
try
{
InetAddress ia = InetAddress.getByName("www.google.com");
System.out.println("Address is:" +ia.getHostAddress());
InetAddress ib= InetAddress.getByAddress("74.125.236.81".getBytes());
System.out.println(ib.getHostName());
}
catch(UnknownHostException uhe)
{
System.out.println("Error:"+uhe);
}
}
}

FlowLayout type Frame in Java

import java.awt.Color;
import javax.swing.*;
public class FlowLayout
{
JFrame f = new JFrame("FlowLayout");
JPanel p = new JPanel();
JButton b1 = new JButton("button1");
JButton b2 = new JButton("button2");
JButton b3 = new JButton("button3");
public static void main(String ar[])
{
FlowLayout fl = new FlowLayout();
fl.show();
}
public void show()
{
p.add(b1);
p.add(b2);
p.add(b3);
p.setBackground(Color.BLUE);
f.getContentPane().add(p);
f.setSize(500,500);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}

Monday, November 7, 2011

Linux Common Commands u must know

LINUX COMMON USE COMMANDS

sudo dpkg -i package_name.deb
To install a package which is in debian package

who
show the current users have been logged on --> who
alias
make an alias name for any command like 'ls -l' → alias list='ls -l'
unalias
remove alias definition --> unalias list
whereis
gives address of binary, source and manual pages → whereis ls
whatis
display manual page description or tells short description
about any command --> whatis man
man
used 4 manual help/brief description of any command with options --> man ls
whoami
tells effective userid means your user id --> whoami
ls
list directory contents
dir
list directory contents
cdc
changing directory --> cd foldername
mkdir
make directory --> mkdir foldername
rmdir
remove directory -> removes directory
rm
remove file
apt-get install
search and install package direct form internet (for install netbeans on your pc) --> apt-get install netbeans-7.0.1-ml-javaee-linux.sh
aptitude
high level interface for package manager in terminal for checking all installed packages and available packages for new installation
aspell
spelling checker in file (here aspell and check are both keywords followed by filename)--> aspell check abc.txt
Ctrl + Z
/ Ctrl + D
for killing current process
read
read from keyboard for generally shell scripting files --> read x
cal
displays calender and date of Easter
cat
creating,viewing,concatenate of text file
chmod
changes the file permission for (read, write and execution)
--> chmod 755 filename
-rwxrwxrwx
drwxrwxrwx   -> - for file d for directory followed by (owner:3bits, group:3bits, others:3bits)
-------------------------------------------------------
Vi Editor

Modes of operation:
1. Command Mode: to take action on file
2. Insert mode: to insert texts into file.

#pressing escape turn command mode on.

Start vi

vi filename : opens given filename


command mode:
:q! - quit without saving
:wq! - quith with saving
---------------------------------------------------------
killall <<processName>> : kills the process
killall firefox




clear
clear screen
cmp
compare two files
cp
copy files from one location to another --> cd file1 /opt/file1
date
writes date and time
df
report free disk space
du
report about disk usage
free
report free spaces in diff disks.
diff
compare files line by line --> diff fileone filetwo
history
for viewing all different command used in terminal recently
echo
for showing any message it can be anything string, integer or float value --> echo "prem bharti"
ifconfig
getting all information about your network connection like
ipaddress,subnetmast, gateway etc
bg
runjobs in background
fg
runjobs in foreground
id
returns user identity
head
gives output given first part of file (for showing first 2
lines of file abd) --> head -2 abd
ln
create a linkfile for original file --> ln abc.sh $HOME/Desktop/abd.sh
more
display file on page by page basis
mv
moving a file to another location --> mv filename /otherdirectory/filename
ps
-Al
gives snapshot of current running processes
netstat
Print network connections, routing tables, interface statistics, masquerade
connections, and multicast etc.
pwd
gives present working directory
rmdir
removes given directory --> rmdir nameofdirectory
sleep
suspends given process for given time (we want to sleep mplayer music software for 10 sec --> sleep 10 ; mplayer foo.mp3
tail
output last part of files
wc
gives output in form of no. of lines, words, characters in a file --> wc filename
uniq
used for file and output doesn't contain repeated line --> uniq filename
touch
change a file's access and modification timestamps. Also
create a new empty file. --> touch filename
sudo shutdown now
Shutdown the computer at a time..
sudo reboot
reboots the computer.
echo $HOME
path of home
x=10; export x
save variable value to shell terminal
watch -n 5 “cat xyz”
display periodically xyz file after 5 seconds
echo $USERNAME
show username
passwd
change userpassword
eject -T
open tray of cdrom if it's closed and vice versa
fdformat
low level floppy disk format
arch
print machine architecture
iptraf
Interactive Colorful IP LAN Monitor (may need to install)
w username
i.e. w love → Find out who is logged in what is he doing..

tty
file name for the terminal
traceroute www.google.com
trace hostname from your system node by node
(u may hv to install – use sudo apt-get install traceroute)
ls>xyz
output of ls will be write into xyz named file
ls>>xyz
output of ls will be append into xyz named file

# GREP UTILITY --> prints line matching a pattern
grep “searchWord” filename
Display only those line containing string

grep -c “searchWord” filename

Display no. of matched Line (only Number)
grep -h “searchWord” filename
Display matched lines, but do not display filename
grep -i “searchWord” filename
Ignore case sensivity
grep -l “searchWord” filename
Display filenames, but do not display matched lines.
grep “.*xyz” filename
display lines containing only words ends with xyz
grep “[aeo]gg” filename
u want to search egg but not sure about first letter may be a,e,o but sure about gg next two words
grep “...ya” filename
if not sure about first three letters (may be tanya, divya)
grep “a*vinash” filename
after a appearance or a zero or more characters ex. aaaavinash and also can avinash
grep “^an” filename
match line begin with “an” → i.e. (anusha, anurag, anil)
grep “sh$” filename
match line ends with “sh” → i.e. (avinash, akash)
grep -n “searchWord” filename
Display matched line and their line numbers
grep -v “searchedWord” filename
Display all lines that do NOT match
grep -w “searchedWord” filename
Match Whole Word

# awk utility → pattern scanning and processing language.

egg order 4
cake good 10
cheese okay 4 filename → inventory
pen good 12
floppy good 5

*awt '/good/ {print $1 “ - “ $3}' inventory
: print searched word field 1 – field 3
output : cake – 10
pen – 12
floppy -5
*awk '/egg/ {print $0} /cake/ {print $0}' inventory
: print for two search words egg and cake & show all fields
output : egg order 4
cake good 10

Input
----------------------
"schoolID","schoolName","schoolCity","schoolState","schoolNick"
"abilchrist","Abilene Christian University","Abilene","TX","Wildcats"
"adelphi","Adelphi University","Garden City","NY","Panthers"
"adrianmi","Adrian College","Adrian","MI","Bulldogs"

Output
----------------------
schoolID    schoolName
abilchrist    Abilene Christian University
adelphi    Adelphi University
adrianmi    Adrian College

awk -F ',' '{print $1 "\t" $2}' Schools.csv |sed 's/"//g'

-F : it's for field seperator
','  : It's used for explicitly telling delimiter is comma, default is space
'{print $1 "\t" $2}' : print is to print, $1 is to show first column, "\t" to show tab space among first and second column.
Schools.csv : it's file name where input data is stored
sed 's/"//g' : it's for replacing , {s -> for substitute}, {/old char to replace/new char which will be substituted/}, {/g -> it's for substitute for all not only one occurance.}, Here replacing quote with nothing


Output
----------------------
adelphi    Adelphi University
adrianmi    Adrian College




awk -F ',' '/adelphi|adrianmi/{print $1 "\t" $2}' Schools.csv |sed 's/"//g'

#added pattern to get only those columns having adelphi and adrianmi





# sed utility → stream editor for filtering and transforming text
sed '/egg/s//chicken/g' inventory
Substitute(s) all occurrence of egg to chicken globally(g) for inventory file
sed -n [commands]
Suppress to display output of result

uptime
shows when last time os started.

#Adding cron on linux
__________
sudo gedit /etc/crontab

in cronTable add job i.e.

*/1 * * * * lovebharti mkdir /home/lovebharti/prem

containing 7 columns
*/1 for every one minute
lovebharti is user name
after that add command
and save
_____________________






_____________________________________
SVN
_____________________________________
svn list --verbose
    shows content of the svn directory
svn co repoPath downLoadPath
    takes checkout of repoPath at downLoadPath