Skip to main content

Posts

Showing posts from November, 2013

How to create and execute stored procedure in linux mysql command? [ Linux Mysql: Create and execute stored procedures ]

Sql Scripts for creating stored procedures: mysql > delimiters // mysql > use userDB;           > select database();           > create procedure userdbprdt()           >  begin           >  select u.id,u.name,u.username,ur.product from usertbl u join userproduct ur where u.id=ur.id;             > end// Sql script for executing stored procedure mysql> call userdbprdt()//

Java Swing MySql JDBC: insert data into database

Program import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.sql.*; public class insertswing implements ActionListener {   JFrame fr;JPanel po;   JLabel l1,l2,main;   JTextField tf1,tf2;   GridBagConstraints gbc;   GridBagLayout go;   JButton ok,exit; public insertswing(){ fr=new JFrame("New User Data "); Font f=new Font("Verdana",Font.BOLD,24); po=new JPanel(); fr.getContentPane().add(po); fr.setVisible(true); fr.setSize(1024,768); fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); po.setBackground(Color.WHITE); go=new GridBagLayout(); gbc=new GridBagConstraints(); po.setLayout(go); main=new JLabel("Enter User Details "); main.setFont(f); l1=new JLabel("Name  :");tf1=new JTextField(20); l2=new JLabel("User Name  :");tf2=new JTextField(20); ok=new JButton("Accept"); exit=new JButton("Exit"); gbc.anchor=GridBagConstraints.NORTH;gbc.gridx=5;gbc.gridy=0; go.s...

MySql linux terminal Commands: Basic commands to create and drop databases commands

1. Login on mysql  command mysql -u root -h localhost -p 2. Check Status mysql> status 3. show databases mysql> show databases; 4. Show variables mysql> show variables; 5. Show processlist mysql> show processlist; 6. Using and selecting system already available mysql database mysql> use mysql; mysql> select database(); 7. select user table in mysql database mysql> select Host, User from user or mysql> select Host, User from mysql.user 8. Create database and display it mysql> create database tempDB; mysql> show databases; mysql> use tempDB; mysql> select database(); 9. Drop database  mysql> drop database tempDB;  mysql> show databases; 10. exit  mysql   mysql> exit  

Data Structure and Algorithms : Queue Program in Java

Program: public class queuepgm { private int maxSize; private long[] queArray; private int front; private int rear; private int nItems; public queuepgm(int s) { maxSize = s; queArray = new long[maxSize]; front = 0; rear = -1; nItems = 0; } public void enqueue(long j) { if(rear == maxSize-1) rear = -1; queArray[++rear] = j; nItems++; } public long dequeue() { long temp = queArray[front++]; if(front == maxSize) front = 0; nItems--; return temp; } public long peekFront() {     return queArray[front]; } public boolean isEmpty()       { return (nItems==0); } public boolean isFull() { return (nItems==maxSize); } public int size() { return nItems; } public static void main(String[] args) { queuepgm theQueue = new queuepgm(5); // queue holds 5 items theQueue.enqueue(10); theQueue.enqueue(20); theQueue.enqueue(30); theQueue.enqueue(40); System.out.println("Dequeue Values: FIFO"); while( !theQueue.isEmpty() ) ...

Data Structure and Algorithms : Stack Program in Java

Program public class stackpgm { private int maxSize; private long[] stackArray; private int top; public stackpgm(int s) { maxSize = s; stackArray = new long[maxSize]; top = -1; } public void push(long j) {     if(!isFull())     {       stackArray[++top] = j;     } } public long pop() {           return stackArray[top--];             } public long peek() { return stackArray[top]; } public boolean isEmpty() { return (top == -1); } public boolean isFull() { return (top == maxSize-1); } public static void main(String[] args) { stackpgm theStack = new stackpgm(10); theStack.push(1); theStack.push(2); theStack.push(3); theStack.push(4); System.out.println("Pop up values"); while( !theStack.isEmpty() ) { long value = theStack.pop(); System.out.print(value+"\n"); } } } Output

Head and Tail Commands in Linux

Head Command Description : prints output of first part of the file by default it will print first 10 lines Syntax : head filename examples: 1.  head upcasting.java it will print first 10 lines of the file upcasting.java by default. 2. head -n 50 upcasting.java  it will print first 50 lines of the file upcasting.java. 3. head upcasting.java downcasting.java it will print first 10 line of the 2 files upcasting.java and downcasting.java. 4. head *.java it will print all the java files first 10 lines. 5. head *.java *.class it will print all the java and class files first 10 lines. Tail Command: Description : prints output of last part of the file by default it will print last 10 lines Syntax : tail filename Examples: 1. tail upcasting.java it will print last 10 lines of the file upcasting.java by default. 2.  tail -n 50 upcasting.java  it will print last 50 lines of the file upcasting.java. 3.  tail ...

Linux Terminal Commands

Install Command sudo apt-get install <package-name> Example: Installing vlc media player sudo apt-get install vlc ls Command ls -l list folders and files with read write permissions and user groups ls -a This command shows hidden files and folders ls -al ls -la Clear Command clear this command clears the screen Manual Command man <command> this command shows manual of the commands example man ls shows manual command of ls q to quit the manual screen back to terminal commands ifconfig command ifconfig command ip network address details netstat command netstat command used to show network status like ip addresses of local and foreign; port, pid, network protocols cat Command   cat  command  concatenate files and print on the standard output.

Java Program: Down casting Inheritence

Program public class downcasting {    public static void main(String[] args)     {      fordd f;      benzz b;      BMWw bm;      carr c,cc,ccc;      c=new fordd();      cc=new benzz();      ccc=new BMWw();      f=(fordd)c; // downcasting or narrowing or specialization      b=(benzz)cc;      bm=(BMWw)ccc;      f.car();      b.car();      bm.car();     } } class carr {     void car()     {         System.out.println("This super class car method");     } } class fordd extends carr {     void car()     {         System.out.println("This sub class Ford car method");     } } class benzz extends carr {      void car() ...

Java Program: Up casting Program in inheritance

Program public class upcasting {    public static void main(String[] args)     {      car c,cc,ccc,o;      o=new car();      o.car(); //no casting      c=(car)new ford(); //upcasting ford sub class to super class      c.car();      cc=(car)new benz();//upcasting ford sub class to super class      cc.car();      ccc=(car)new BMW();//upcasting ford sub class to super class            ccc.car();         } } class car {     void car()     {         System.out.println("This super class car method");     } } class ford extends car {     @Override     void car()     {         System.out.println("This sub class Ford car method");     } } class benz extends car { ...

Java Program: Inheritance Super Keyword

Program class inheritance {  public static void main(String[] args)  {   apple a=new apple();   a.disp();  } } class fruit {  String f="fruit";  public void disp()  {   System.out.println("Base Class "+f);  } } class apple extends fruit {  String f="Apple";  public void disp()  {   System.out.println("Derived Class  "+f);   super.disp();   System.out.println("Super Class "+super.f);  } } Output

Java Program: File I/O Fileoutputstream to create file

Program import java.io.*; public class createfile {     public static void main(String[] args)     {         try         {         createfile();         }         catch(Exception ex)         {             System.out.println("File Exceptio occured");         }         }     public static void createfile() throws java.io.IOException     {         DataInputStream d=new DataInputStream(System.in);         FileOutputStream f=new FileOutputStream("jack.txt",true);         BufferedOutputStream b=new BufferedOutputStream(f,1024);         System.out.println("Enter $ at the end to finish text");         char c;         while((c=(c...

Java Program: AWT Frame Closing Event

Program import java.awt.*; import java.awt.event.*; public class awtexample extends Frame{     public static void main(String[] args)     {         Frame f= new Frame("New Frame");         f.setSize(400, 500);         f.setVisible(true);         f.addWindowListener(new WindowAdapter(){         public void windowClosing(WindowEvent e)         {         System.exit(0);         }      });     } } Output

Java Program: Multi Thread optimum way utilize CPU time using Thread(Runnable object, String thread_name)

Program i mport java.util.logging.Level; import java.util.logging.Logger; class ThreadRunnnable {     public static void main(String[] args)     {                new ThreadRun();        new ThreadRunn();        System.out.println("Main Thread Starts");         for(int i=1;i<=5;i++)         {             System.out.println(i);             try {                 Thread.sleep(1500);             } catch (InterruptedException ex) {                 Logger.getLogger(ThreadRun.class.getName()).log(Level.SEVERE, null, ex);             }         }                     ...

Java Program: Thread using Runnable interface program

Program import java.util.logging.Level; import java.util.logging.Logger; class ThreadRunnnable {     public static void main(String[] args)     {              new ThreadRun();        new ThreadRunn();        System.out.println("Main Thread Starts");         for(int i=1;i<=5;i++)         {             System.out.println(i);             try {                 Thread.sleep(1500);             } catch (InterruptedException ex) {                 Logger.getLogger(ThreadRun.class.getName()).log(Level.SEVERE, null, ex);             }         }                 } } class ThreadRun imp...

Java Program: Thread in swing implements Runnable interface and SwingUtilities

Program import javax.swing.*; public class SwingThread extends JFrame {     public static void main(String[] args) {     SwingUtilities.invokeLater(new Runnable() {       @Override       public void run() {         final JFrame f = new JFrame("Swing using Thread Frame 1");         f.setSize(600, 400);         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         f.setVisible(true);               final JFrame fr = new JFrame("Swing using Thread Frame 2");         fr.setSize(600, 600);         fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         fr.setVisible(true);       }     });     }   } Output:

Java Program: Simple Thread Example

public class threadexample {     public static void main(String args[])     {         Thread t=Thread.currentThread();         System.out.println("Current Thread: "+t);         t.setName("Thread Example");         System.out.println("Current Thread Name changed as: "+t);     } } output

Java Program: Swap two numbers without temp variable

import java.io.*; public class Swapwithouttemp {     public static void main(String[] args) throws IOException     {         System.out.println("Enter first number");         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));         int x=Integer.parseInt(br.readLine());             System.out.println("Enter second number");         BufferedReader brr=new BufferedReader(new InputStreamReader(System.in));         int y=Integer.parseInt(brr.readLine());                 new swap(x,y);     } } class swap {       swap(int a, int b) throws IOException               {         System.out.println("Before swapped values a= "+a+"\tb= "+b );         a=a+b;     ...

Java Program: User defined input using BufferedReader, Checking Employee Age

import java.io.*; public class EmployeeAgeCheck {     public static void main(String[] args) throws IOException     {         EmployeeData e=new EmployeeData();         e.getdetails();         e.checkage();           } } class EmployeeData {     private String name;     private int age;     public void getdetails() throws java.io.IOException     {         // user defined input at runtime         BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));         System.out.println("Enter name");         name=buf.readLine();         System.out.println("Enter Age");         age=Integer.parseInt(buf.readLine());     }     public void checkage()     {   ...

Java Program : Default and Parameterized Constructor

public class constructorexample {     public static void main(String[] args)     {         personcon kumaran=new personcon();         kumaran.display();         personcon jannu=new personcon("Jannu",22);         jannu.display();     } } class personcon {     private String name;     private int age;     //default constructor     personcon()     {         name="kumaran";         age=23;     }    //parameterized constructor     personcon(String n,int a)               {         name=n;         age=a;     }     public void display()     {         System.out.println("Name: "+name+"\t Age: "+age);     } ...

How to download google chrome browser in linux using terminal command?

Step 1: Download Google Chrome For 32 bit version $ wget https://dl.google.com/linux/direct/google-chrome-stable_current_i386.deb For 64 bit version $ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb Step 2: Install .deb file For 32 bit version $ sudo dpkg -i google-chrome-stable_current_i386.deb For 64 bit version $ sudo dpkg -i google-chrome-stable_current_amd64.deb Issues: if you get any error while installing or downloading just use this below command to clear the issues 1. $ sudo apt-get update 2. $ sudo apt-get upgrade 3. $ sudo apt-get -f install After installation check it google chrome in linux dash home search:

How to check CPU usage in Linux OS?

Generally top is a command to check CPU usage on any OS. top command htop Command In Linux Terminal command to CPU usage htop is another to do the task but before install htop as:  Sudo apt-get install htop  in terminal then after use htop command other than iostat,  /proc/meminfo,mpstat are the commands to be used to check CPU  and memory usages