Skip to main content

Posts

Showing posts from November, 2011

Java Sample: Concatenation of two file's content into another

import java.io.*; class jConcatFiles {     public static void main(String args[])     {         try         {                     FileInputStream file1=null;             FileInputStream file2=null;             SequenceInputStream file3=null;             file1=new FileInputStream("City.txt");             file2=new FileInputStream("Output.txt");             file3=new SequenceInputStream(file1,file2);             BufferedInputStream inBuffer=new BufferedInputStream(file3);             BufferedOutputStream outBuffer=new BufferedOutputStream(System.out);             int ch;             while((ch=inBuffer.read())!=-1)             {                 outBuffer.write((char)ch);             }        }catch(Exception e){}              } }

Java Sample: Reading & Writing Operation using a single file

import java.io.*; import java.math.*; class jReadWrite {   public static void main(String args[])     {         DataInputStream dis=null;         DataOutputStream dos=null;         File inFile=new File("rand.txt");         try //Writing Content into File         {             dos=new DataOutputStream(new FileOutputStream(inFile));             for(int i=0;i<=20;i++)             {                 dos.writeInt((int)i);             }         }catch(Exception e){}                  try //Reading Content from File         {             dis=new DataInputStream(new FileInputStream(inFile));             for(int i=0;i<=20;i++)             {                 int n=dis.readInt();                 System.out.print(n+" ");             }         }catch(Exception ex){}                  try // Closing File         {             dis.close();             dos.close();         }catch(Exception ey){}     } }

Sample: File Operation In JAVA

1. Transfer File Content One to Another Code>> import java.io.*; class jFile {     public static void main(String args[])     {         File inFile=new File("Input.txt");//Existing File         File outFile=new File("Output.txt");         FileReader ins=null;         FileWriter outs=null;         try         {             ins=new FileReader(inFile);             outs=new FileWriter(outFile);             int ch;             while((ch=ins.read())!=-1)             {                 outs.write(ch);             }                     }catch(Exception e)         {             System.out.println(e.getMessage());         }finally         {             try{                 ins.close();                 outs.close();             }catch(Exception ex)             {}         }     } } 2. Writing Bytes to FILE Code>> import java.io.*; class jBytes {     public static void main(String args[])     {         try{         byte

Manage Threading with PRIORITY in java

class A extends Thread { public void run() { System.out.println("Thread A Started"); for(int i=1;i<=4;i++) { System.out.println("\tForm Thread A : i="+i); } System.out.println("Exit From A"); } } class B extends Thread { public void run() { System.out.println("Thread B Started"); for(int j=1;j<=4;j++) { System.out.println("\tForm Thread B : j="+j); } System.out.println("Exit From B"); } } class C extends Thread { public void run() { System.out.println("Thread K Started"); for(int k=1;k<=4;k++) { System.out.println("\tForm Thread C : k="+k); } System.out.println("Exit From C"); } } class testThread_1 { public static void main(String args[]) { A t1=new A(); B t2=new B(); C t3=new C(); t3.setPriority(Thread.MAX_PRIORITY); t2.setPriority(1); t1.setPriority(6); //System.out.printl

Implementation of Hybrid inheritance in Java

Implementation of Hybrid inheritance in Java with the help of INTERFACE CODE>> class Student {     int rollNumber;     void getNumber(int n)     {         rollNumber=n;     }     void putNumber()     {         System.out.println("Roll No :: "+rollNumber);     }   } class Test extends Student {     float part1,part2;     void getMarks(float m1,float m2)     {         part1=m1;         part2=m2;     }          void putMarks()     {         System.out.println("Marks Obtained\n");         System.out.println("PART1: "+part1);         System.out.println("PART2: "+part2);     } } interface Sports {     float sportWt=6.0F;     void putwt(); } class Results extends Test implements Sports {     float total;     public void putwt()     {         System.out.println("Sports Wt="+sportWt);     }     void display()     {         total=part1+part2+sportWt;         putNumber();         putMarks(

Sample: An applet program with button class & ActionEvent

import java.awt.*; import java.awt.event.*; import java.applet.*; public class jevent extends Applet implements ActionListener {         String msg="";         Button yes,no,maybe;         public void init()         {                 yes=new Button("YES");                 no=new Button("NO");                 maybe=new Button("UNDECIDED");                 add(yes);add(no);add(maybe);                 yes.addActionListener(this);                 no.addActionListener(this);                 maybe.addActionListener(this);         }         public void actionPerformed(ActionEvent ae)         {                 String str=ae.getActionCommand();                 if(str.equals("YES"))                 {                         msg="YOU've Clicked On YES";                 }else if(str.equals("NO"))                 {                         msg="YOU've Clicked On NO";              

Sample: Java Applet {Popup menu creation}

import java.awt.*;     import java.applet.*;     import java.awt.event.*;     public class pms extends Applet implements ActionListener { PopupMenu popup; public void init() {                 MenuItem mi;    popup = new PopupMenu("Edit");             mi = new MenuItem("Cut");             mi.addActionListener(this);    popup.add(mi);             mi = new MenuItem("Copy");             mi.addActionListener(this);    popup.add(mi);    popup.addSeparator();             mi = new MenuItem("Paste");             mi.addActionListener(this);    popup.add(mi);    add(popup); // add popup menu to applet                         enableEvents(AWTEvent.MOUSE_EVENT_MASK);     resize(200, 200);         } public void processMouseEvent(MouseEvent e) {    if (e.isPopupTrigger()) {         popup.show(e.getComponent(), e.getX(), e.getY());    }    super.processMouseEvent(e);         }         public

Symmetric Multiprocessing

SMP lets multiple CPUs in a networking device share the same board, memory, I/O and operating system. Nonetheless, each CPU in an SMP system can act independently. While one CPU handles a database lookup, others can update the database and perform other tasks, dramatically increasing the ability of the device to handle today's increasingly complex networking tasks. SMP costs relatively little. When scaling from one CPU to two, only one processor board is needed. Processing power is doubled without paying for additional support chips and without taking up an additional slot in the chassis. Despite its benefits, SMP can only scale so far. Bottlenecks can occur when several CPUs on a board share a single memory bus. Rather than put too many CPUs on the same SMP board, designers of high-end network elements can distribute applications across a networked cluster of SMP boards, where each board has its own memory array, I/O and operating system. This approach has its challenges.

Windows network risks - NetBIOS, SMB and null sessions

Some of the biggest security risks through information leakage, affecting Windows computers is the Windows network itself, and the protocols used to share files and printers amongst local computers in a local Windows network, particularly SMB and NetBIOS, taking advantage of default hidden shares. Here we describe a discovery technique also known as null sessions, that can provide additional in-depth information about a remote computer, that can further be used to compromise it and take control over it. The Windows network implementation has a specific interface that can be queried via TCP-IP ports 139 and 445. The problem exists on many Windows installations due to the fact that default security configurations are allowing it. The first step an attacker would take, is to perform a TCP scan on your Windows computer. If improperly protected, your computer may have these ports open and they may expose a lot of information, through using the so called null sessions technique. What

Sample: Java Socket Programming

//The server import java.io.*; import java.net.*; public class Provider{ ServerSocket providerSocket; Socket connection = null; ObjectOutputStream out; ObjectInputStream in; String message; Provider(){} void run() { try{ //1. creating a server socket providerSocket = new ServerSocket(2004, 10); //2. Wait for connection System.out.println("Waiting for connection"); connection = providerSocket.accept(); System.out.println("Connection received from " + connection.getInetAddress().getHostName()); //3. get Input and Output streams out = new ObjectOutputStream(connection.getOutputStream()); out.flush(); in = new ObjectInputStream(connection.getInputStream()); sendMessage("Connection successful"); //4. The two parts communicate via the input and output streams do{ try{ message = (String)in.readObject(); System.out.println("client>" + message); if (mess

Comparison over Intel Core 2 duo & Intel Core i3 Processor

A comparison between processors was simple some years ago with a single core processor. All you had to look at was the clocking frequency and the cache size. The entry of multiple core chips changed it all and life became complicated. With dual, quad and even six core processors hitting the market, there are many more factors to be considered, than before. Intel's dual core and core 2 duo processors were the first ones to introduce multi-core processor based computing. The quad core processors created later have given rise to the quad core vs dual core debate, as well as the core i5 vs core i7 comparison which is something that high-end computing market consumers should think about. Prior to that, we only had the 32 bit vs 64 bit processors comparison to worry about. Today, Intel has gone through a lot of designing and planning, to introduce core i3 processors that are an improvement over the core 2 duo line. The following Intel core i3 vs core 2 duo processor comparison wil