Friday, September 28, 2012

Does Microsoft show us a Glimpse of the Future from the Metro Look

Microsoft has always known what its user needs and has attained massive success introducing products which full fills the trend and requirements.It has recently introduced the Windows 8 and  Outlook.Both these products have a common feature the Metro look.

So what is this Metro look and why have they used it?


File:Windows 8 start screen.png



The Metro is a User Friendly Minimalistic and Stylish Graphical User Interface(GUI) Unlike the predecessor Windows versions you can see that there is no Windows start Button and the detailed lists of icons.Everything is clean and minimal.This is a trend that has been absorbed from the growing Android Smartphone and Tablets Market.Windows 8 also aims the users who uses Mobile Devices with touchscreens.The Interface is good and is fluid.

Microsoft has also done a good job with their Online Mail Service,its also been ported to the Metro Look.
Live.com and Hotmail.com has been revamped to the simpler and user friendly Mail Service Outlook.com

These are all very good and the Outlook Mail service is very attractive,Expect it could have been much faster or it could show the loading screen like Gmail do when you open your Mail account.



These all are revolutions in the IT Era-User interfaces are becoming simpler and simpler by time,user hardly needs to do something,its becoming very easy for the naive user.But advanced users might find these simplicity a little annoying as they may be interested to explore Details of the System.

These all make up an Efficient and Intelligent approach  that makes Information Retrival and Information processing a Child's Play and the only doubts remains-Will a time come when computers do all the work that we think of ????

Thursday, August 30, 2012

Java Program to Write Lines of Text to a File + Source Code

To learn the Basics of file manipulation in java ,the best way to start is by writing simple code to write some text to file.The following is a sample program that writes text to file using BufferedWriter Class

It uses the File Class to open the File to the BufferedWriter Class,which writes some sample text to the file.The main class used is the Writer Class intended for writing stream data to files.

Below is the complete source Code to implement a Simple File Writer in Java


 import java.io.*;  
 public class FileWriter {  
  public static void main(String[] args)throws IOException{  
  String towrite = "Hello World";  
  Writer data = null;  
  File file = new File("myfile.txtt");  
  data = new BufferedWriter(new FileWriter(file));  
  data.write(text);  
  data.close();  
  System.out.println("Text Written");   
  }  
 }  

Wednesday, August 8, 2012

How to set the Java Compiler path for direct running from command Line

There is an easy way to set the Java Compiler Path(javac.exe) and Java Interpreter path(java.exe)without typing long lines of command.

The following are steps to set the JDK(Java Development Kit) path easily

1.Click on Start

2.Right Click on Computer>Properties

3.Click on Advanced System Settings

4.Click on Environmental Variables Button




5.Click on New



6.In the variable name field type PATH



7.In the variable value field enter the path in which JDK is installed (usually C:\Program Files\Java\jdk1.7.0_05\bin),include the bin folder.

8.Click on OK

9.Open CMD and type javac.exe or java.exe or the name of any executable,it will be launched.

See the video tutorial for more information



 
    

Friday, July 27, 2012

Simple Pencil Sketch Java Applet Example+Source Code


Java Applets are easy to Implement Web Programs that can be run on the browser without any installation or downloads. The only requirement is that Java Virtual Machine(JVM) Should be installed on the END User Machine. As you may know Java Applets are OS Independent it can be run on any system supporting Java.
Simple Pencil Sketch Applet in Java
The following is a simple Java Example Applet that draws Lines when a user clicks and Drags the mouse.
It uses mouseMoved, mousePressed events to Track mouse clicks by using the MouseAdapter Motion Listener Class.The following is the screenshot of the Applet


The following is the complete Example Source code for the Pencil Sketch Java Applet
 import java.applet.*;  
 import java.awt.event.*;  
 import java.awt.Graphics;  
 import java.awt.Color;  
 //<applet code=LineDraw.class width=400 height=300> </applet>  
 public class LineDraw extends Applet implements MouseMotionListener  
 {int x1,y1,x2,y2;  
  boolean flag=false;  
 public void init()  
 { x1=0; y1=0;  
  addMouseMotionListener(this);  
  addMouseListener(new MouseAdapter(){  
  public void mousePressed(MouseEvent ME)  
  { x1=ME.getX(); y1=ME.getY();}  
  }  
  );  
 }  
 public void mouseMoved(MouseEvent ME)  
 {showStatus(ME.getX()+","+ME.getY()); }  
 public void mouseDragged(MouseEvent ME)  
 {  
  Graphics g=this.getGraphics();  
  x2=ME.getX();  
  y2=ME.getY();  
  g.drawLine(x1,y1,x2,y2);  
  x1=x2; y1=y2;  
  }  
 }  

Sunday, May 27, 2012

.Net 4.5-The End of Microsoft .Net Framework Client Profile





Microsoft had introduced 2 Variants of the .net Frameworks till .Net Framework Version 4,the Complete Framework and the Client Profile which was only a subset of the the Complete Framework.

Why did Microsoft do it?

Since the Complete Framework had a large size Microsoft did not want the END user's to consider it annoying to download the complete framework to run applications developed in .Net.
Certain software's only used some parts of the framework.So client profile was created as a subset of the .Net Framework complete Edition.The client Profile did not support ASP.Net and the Advanced Web Programming.

Was Client Framework a Success?

The Straight forward answer is 'NO'.If you ask why just compare the size of the two packages.

 .NET Framework 4 32BIT + 64 bit Full  - 48.1 MB
 .NET Framework 4 Client Profile-   41.0 MB

Just a 7MB Difference.So this is where it failed,the users will find it comfortable to download the full framework as the sizes have a small difference.This also created confusion among common users regarding the different terms used.

But with the Release of the .NET Framework 4.5 Microsoft is putting an End to the Client Framework model.Microsoft has mentioned about this in their MSDN Article http://social.msdn.microsoft.com/search/en-us?query=compact+&x=0&y=0

Quoting from MSDN

Starting with the .NET Framework 4.5, the Client Profile has been discontinued and only the full redistributable package is available. Optimizations provided by the .NET Framework 4.5, such as smaller download size and faster deployment, have eliminated the need for a separate deployment package. The single redistributable streamlines the installation process and simplifies your app's deployment options.
 Thus us Developers and END Users will find it comfortable to download a single version rather than getting confused with all different versions around.




Saturday, May 26, 2012

The Best 4 Free IDEs for coding programs in C Language

C Language is the Base for all Softwares existing today,it is a powerful language for programming applications which require Low Level System Functions.The Object oriented successor of C is C++ which is considered much easier to program when compared to C because of its Object Oriented Nature.


It is Necessary for Every Programming Aspirant to learn C Language and C should be the primary language you learn because future languages apart from Functional Languages most Imperative Programming Languages use the structure similar to C.


There are Several Powerful and Completely free IDEs(Integrated Development Environments) Available for Developing C Programs which can be simultaneously used for other languages like C++.


Given Below is a List of the Best 4 Free IDEs for Developing Programs using the C Programming Language.


1)Eclipse-CDT(C/C++ Development Tooling):

Eclipse is Popular IDE for Developing Java Applications.It is mainly used for Developing Android Applications by Integrating the Android Plugin. Eclipse IDE has its C/C++ Counterpart called Eclipse CDT Which can be used to Develop both C and C++ Programs.The main feature of CDT is Code refactoring and Syntax Highlighting.



You can Download Eclipse CDT from http://www.eclipse.org/cdt/





2)Pelles C :

Pelles C is a good free Integrated development Environment for developing C programs.
It is available in both 32 and 64 bit versions with support for Windows 7 64 bit editions.It is a good alternative for the Old 16 Bit Borland Turbo C Compiler(TC).


Pelles C is a lightweight bundle of Integrated features.It can be used it to edit source files, icons, cursors, bitmaps, resource scripts
For More Information on Pelles C Please check out this post http://c-madeeasy.blogspot.in/2011/07/pelles-c-good-ide-supporting-windows-7.html




You can Download Pelles C from http://www.smorgasbordet.com/pellesc/





3)Dev-C++ IDE:


Dev-C++ is an Free IDE by BloodShed Software that can be used to Develop C and C++ Programs
Dev-C++ IDE Supports GCC Based Compilers has Profiling Feature.It is also a good IDE Targeted for C/C++ Development.Dev-C++ supports GCC Based Compilers ,has Code Completion Feature and has Inbuilt Profiling.


You can Download Dev-C++ IDE from http://www.bloodshed.net/devcpp.html

4)Code::Blocks:

Code::Blocks is a  free C/C++ IDE which is Open-source and Cross Platform.The main feature its ability to maintain the look and feel across different platforms.It also has Plugin Support to extend the usability.




You can Download Code Blocks IDE from http://www.codeblocks.org/

Tuesday, May 22, 2012

Program to Implement Selection Sort in Java+Explanation



Selection sort is said to be an efficient algorithm when considering small computations involving limited memory/resource but it is quite inefficient when compared to other techniques when huge computations are required.Selection sort is said to be efficient for small list of items because of its simplicity.

The following steps Explains the working of the Selection sort Algorithm


  1. Obtain the Item with the Minimal value from a List/Collection of items
  2. Swap the item with the Item in the first position of the Collection/List
  3. Repeat the Process for the rest of the Items in the Collection


The Following is the Complete Program Source Code in Java for Implementing Selection Sort Algorithm
 import java.io.*;
import java.lang.*;
class array
{
 DataInputStream get;
 int a[];
 int i,j,n;
 void getdata()
 {
 try
  {
   get=new DataInputStream(System.in);
   System.out.println("Enter the limit");
   n=Integer.parseInt(get.readLine());
   a=new int[n];
   System.out.println("Enter the elements in the array");
   for(i=0;ia[j])
   {
    temp=a[i];
    a[i]=a[j];
    a[j]=temp;
   }
  }
 }
 System.out.println("Elements in ascending order is:");
 for(i=0;i=0;i--)
 System.out.print(" "+a[i]);
 }
}
class selectionsort
{
 public static void main(String arg[])
 {
  array obj=new array();
  obj.getdata();
  obj.sorting();
 }
}

Wednesday, May 16, 2012

How to Recover Lost or Forgotten RAR(Winrar) Archive Passwords

RAR Files are common format for compression.It is likely that you forget a Encrypted RAR Password.
RAR Files are secured by strong encryption so it is not easy to recover lost RAR File Passwords.

This Tutorial will teach you how to recover lost RAR File Passwords using a technique called Brute-Force Attack.In this method random passwords of varying length are checked againt the Encrypted Winrar Archive untill the correct password is obtained.This is similar to a person checking possible password,.


Follow these Simple Steps to Recover your Lost RAR File Passwords


1.Download and Install RAR Password Recovery Software from this link  http://www.intelore.com/rar_password_recovery.php


2.Open the Encrypted Archive in RAR Password Recovery




3.Click on the Brute Force Tab and specify the settings,the default settings will check passwords ranging from 0-9 characters and a-z alphabets you can change this.

























4.Click on Start Button to start recovery.Once the password is found you will be shown a window with the password


   











For a Detailed View see the Video Tutorial Below or visit Youtube 
http://www.youtube.com/watch?v=hqNLKqEwUBE








Sunday, May 13, 2012

Quick Sort Program in Java -Explanation+Complete Source Code

Quick-sort is a sorting technique commonly called divide and conquer algorithm. Quick-sort first divides a large array of items into two smaller arrays : the low items and high items(ie:all elements in first array is less than all elements in second). 
Quick sort algorithm involves three steps
  1.  An n element, called a pivot is picked from the array.Pivot is commonly the middle element of the array
  2. Rearrange the array elements such that all elements less than the pivot come before the pivot and all elements greater than the pivot come after the pivot,this step is called array partitioning
  3. Then a recursive sorting of the partitioned arrays is done individually
Following is the complete source code for Quick-sort program in Java.

 import java.io.*;  
 import java.lang.*;  
 class array  
 {  
//c-madeeasy.blogspot.com
  DataInputStream get=new DataInputStream(System.in);  
  int a[];  
  int i,n,h,l;  
  void getdata(int n,int x,int y)  
  {  
  try  
  {  
   a=new int[n];  
   System.out.println("Enter the elements");  
   for(i=0;i<n;i++)  
   a[i]=Integer.parseInt(get.readLine());  
  }  
  catch(Exception e)  
  {  
   System.out.println(e.getMessage());  
  }  
  l=x;  
  h=y;  
  }  
  void sort(int l,int h)  
  {  
  int temp,key,low,high;  
  low=l;  
  high=h;  
  key=a[(low+high)/2];  
  while(low<=high)  
  {  
   while(key>a[low])  
   {  
   low++;  
   }  
   while(key<a[high])  
   {  
   high--;  
  }  
  if(low<=high)  
   {  
   temp=a[low];  
   a[low]=a[high];  
   a[high]=temp;  
   low++;  
   high--;  
   }  
   }  
   if(l<low-1)  
   {  
   sort(l,low-1);  
   }  
   if(low<h)  
   {  
   sort(low,h);  
   }  
  }  
  void display(int n)  
  {  
  System.out.println("Asending order is");  
  for(i=0;i<n;i++)  
  System.out.println(" "+a[i]);  
  }  
  }  
  class quicksort  
  {  
  public static void main(String arg[])  
  {  
   array obj=new array();  
   DataInputStream get=new DataInputStream(System.in);  
   int n,x,y;  
   n=0;  
  try  
   {  
   System.out.println("Enter the limit");  
   n=Integer.parseInt(get.readLine());  
   }  
  catch(Exception e)  
   {  
   System.out.println(e.getMessage());  
  }  
  x=0;  
  y=n-1;  
  obj.getdata(n,x,y);  
  obj.sort(x,y);  
  obj.display(n);  
  }  
  }  

Saturday, May 12, 2012

Program to create Parser for IF-ELSE Statement using Flex(Lex) and Bison(Yacc)


'IF -ELSE' Statement is commonly used in all programming languages to implement various logical operations.
The control flows by checking a specific condition-if('cond) then expression if the condition is not satisfied the control flows 
to the else statement else-expression.


Parsing if-else statement is done by definitions of a grammar which uses Regular expressions.Compiler construction tools Flex(Lex) and Bison(Yacc) in Linux(Ubuntu) are used to define the grammar and basic operations .On compilation a c program is generated which is actually the parser for 'IF-ELSE' statement.A parser generates a Parse tree for Intermediate code generation.


Following are complete source codes for Flex and Bison programs to create a Parser for 'IF-ELSE' Statement which accepts valid 'IF-ELSE' Statements
 /*PARSER FOR IF ELSE STATEMENT*/  
 //c-madeeasy.blogspot.com  
 /*YACC PROGRAM*/  
 %{  
 #include<stdio.h>  
 #include<stdlib.h>  
 %}  
 %token num alpha LT GT EQ LE GE NE AND OR INC DEC END  
 %left '+''-'  
 %left '*''/'  
 %right '^'  
 %right '='  
 %nonassoc UMINUS  
 %nonassoc IF  
 %nonassoc ELSE  
 %left GE NE LT GT LE EQ  
 %left AND OR  
 %%  
 S:ST END{printf("\n Accepted\n");exit(0);}  
 ST:IF'('F')''{'ST'}'%prec IF  
  |IF'('F')''{'ST'}'ELSE'{'ST'}'  
  |E';'  
  |E';'ST  
  F:C LO C  
  |C  
 LO:AND  
  |OR  
  C:E RELOP E  
  |E  
  E:alpha '='E  
  |E'+'E   
  |E'-'E   
  |E'*'E   
  |E'/'E  
  |E'^'E  
  |'('E')'   
  |'-'E %prec UMINUS  
  |alpha  
  |num  
  |alpha INC  
  |alpha DEC  
 RELOP:LT  
    |GT  
    |EQ  
    |LE  
    |GE  
    |NE  
   ;  
 %%  
 #include"lex.yy.c"  
 int main()  
 {   
 yyparse();  
 yylex();  
 return END;  
 }  
 yyerror(char *s)  
 {  
  printf("\nError");  
 }  
 /*LEX PROGRAM*/  
 %{  
 #include"pgm4.tab.h"  
 %}  
 %%  
 "if" {return IF;}  
 "else" {return ELSE;}  
 "&&" {return AND;}  
 "||" {return OR;}  
 "<=" {return LE;}  
 ">=" {return GE;}  
 ">" {return GT;}  
 "<" {return LT;}  
 "!=" {return NE;}  
 "++" {return INC;}  
 "--" {return DEC;}  
 "==" {return EQ;}  
 [0-9]+ {return num;}  
 [a-zA-Z]+ {return alpha;}  
 [\t];  
 [\n];   
 "$" {return END;}  
 .  {return yytext[0];}  
 %%  
 /*OUTPUT  
 if(i>0)  
 {  
 a=0;  
 c++;  
 }  
 else  
 {  
 h;  
 }  
 $  
 Accepted  
 if(a>l)   
 {  
 w;  
 }  
 $  
 Accepted*/  


Monday, May 7, 2012

Program to Construct Interpreter for Arthemetic Expression Evaluation using Bison and Flex


Arithmetic expressions are common in programming languages,this program is a sample implementation of an Interpreter to evaluate basic arithmetic expressions like a*b,a+b etc .This is accomplished by using compiler construction tools Flex(Lex) and Bison(Yacc) in Linux operating system environment.The following are complete source codes for two  Flex and Bison Programs to create an evaluator for Arithmetic Expressions

 /*YACC PROGRAM*/  
 %{  
 #include<stdio.h>  
 %}  
 %token num alpha END  
 %left '+''-'  
 %left '*''/'  
 %right '^'  
 %nonassoc UMINUS  
 %%  
 S:E END{printf("\n The given expression is valid\n");exit(0);}  
 E:E'+'E  
  |E'-'E  
  |E'*'E  
  |E'/'E  
  |'-'E %prec UMINUS  
  |'('E')'  
  |E'^'E  
  |num  
  |alpha  
  ;  
 %%  
 #include"lex.yy.c"  
 int main()  
 {  
  yyparse();  
  yylex();  
  return 0;  
 }  
  yyerror(char *s)  
  {  
  printf("\nerror\n");  
  }  
 /*LEX PROGRAM*/  
 %{  
 #include "pgm2.tab.h"  
 %}  
 %%  
 [0-9]+ {return num;}  
 [a-z]+ {return alpha;}  
 [ \t]  ;  
 [\n]  ;  
 "$"  {return END;}  
 .    {return yytext[0];}  
 %%  
 /*OUTPUT  
 r+x  
 $  
 The given expression is valid  
 d++c  
 $  
 error*/  

Tuesday, May 1, 2012

Program to create Lexical Analyser for C Programming Language using Lex/Flex

Flex/Lex is a compiler construction tool that can be used to design a compiler.In this example flex is used to create a sample lexical analyzer for c programming language,it can recognize the valid symbols in c programming language including valid programming constructs.
The following is a complete source code Flex/Lex program to implement a Lexical analyzer for C programming language
 letter [a-zA-Z]  
 digit[0-9]  
 %%  
 {digit}+("E"("+"|"-")?{digit}+)? printf("\n%s\tis real number",yytext);  
 {digit}+"."{digit}+("E"("+"|"-")?{digit}+)? printf("\n%s\t is floating pt no ",yytext);  
 "if"|"else"|"int"|"char"|"scanf"|"printf"|"switch"|"return"|"struct"|"do"|"while"|"void"|"for"|"float" printf("\n%s\t is keywords",yytext);  
 "\a"|"\\n"|"\\b"|"\t"|"\\t"|"\b"|"\\a" printf("\n%s\tis Escape sequences",yytext);  
 {letter}({letter}|{digit})* printf("\n%s\tis identifier",yytext);  
 "&&"|"<"|">"|"<="|">="|"="|"+"|"-"|"?"|"*"|"/"|"%"|"&"|"||" printf("\n%s\toperator ",yytext);  
 "{"|"}"|"["|"]"|"("|")"|"#"|"'"|"."|"\""|"\\"|";"|"," printf("\n%s\t is a special character",yytext);  
 "%d"|"%s"|"%c"|"%f"|"%e" printf("\n%s\tis a format specifier",yytext);  
 %%  
 int yywrap()  
 {  
 return 1;  
 }  
 int main(int argc,char *argv[])  
 {  
 yyin=fopen(argv[1],"r");  
 yylex();  
 fclose(yyin);  
 return 0;  
 }  
 /*INPUT PROGRAM  
 #include<stdio.h>  
 void main()  
 {  
  printf("\nhai\n");  
 }  
/*
OUTPUT

#  is a special character
include is identifier
< operator 
stdio is identifier
.  is a special character
h is identifier
> operator 

void  is keywords 
main is identifier
(  is a special character
)  is a special character

{  is a special character
 
printf  is keywords
(  is a special character
"  is a special character
\n is Escape sequences
hai is identifier
\n is Escape sequences
"  is a special character
)  is a special character
;  is a special character

}  is a special character
*/

How to Restart Windows Explorer after a Crash using Task Manager



Windows Explorer is exposed to frequent crashes and hangs. After explorer hangs you can use Task Manager to End the explorer process but the Start Menu will disappear.To restart explorer follow the simple steps listed below

  • Press Ctrl+Alt+Delete to start Task Manager
  • Click on File>New Process
 
  • Type in explorer and Click Ok
  • Explorer will restart and Start Menu will Reapper

Monday, April 30, 2012

Time Class Program in C++ using operator overloading to add two different Time values

The following program is an implementation of operator overloading in C++ to add two time values in the format HH:MM:SS to the resulting time along with rounding off when 24 hours is reached.
A Time class is created and Operator + is overloaded to add the two Time Class Objects.


The complete source code in C++ to Implement Time class is given below
 #include<iostream.h>  


 #include<conio.h>  
 class time  
 {  
 public:  
 time()  
 {  
 hr=0;  
 min=0;  
 sec=0;  
 }  
 int hr,min,sec;  
 void read()  
 {  
 cout<<"Hours=";  
 cin>>hr;  
 cout<<"\nMinutes=";  
 cin>>min;  
 cout<<"\nSeconds=";  
 cin>>sec;  
 }  
 time operator +(time t2)  
 {  
 time t3;  
 t3.sec=sec+t2.sec;  
 if(t3.sec>60)  
 {  
 t2.min+=1;  
 t3.sec-=60;  
 }  
 t3.min=min+t2.min;  
 if(t3.min>60)  
 {  
 t2.hr+=1;  
 t3.min-=60;  
 }  
 t3.hr=hr+t2.hr;  
 return t3;  
 }  
 void display()  
 {  
 if(hr>=24)  
 { hr=hr%24;  
 }  
 if(hr<10)  
 { cout<<"0"<<hr;  
 }  
 else  
      cout<<hr;  
 if(min<10)  
 { cout<<":0"<<min;  
 }  
 else  
      cout<<":"<<min;  
 if(sec<10)  
 { cout<<":0"<<sec;  
 }  
 else  
      cout<<":"<<sec;  
 }  
 };  
 void main()  
 {  
 clrscr();  
 time c1,c2,c3;  
 cout<<"\n\nEnter the First Time\n\n";  
 c1.read();  
 cout<<"\n\nEnter the Second Time\n\n";  
 c2.read();  
 c3=c1+c2;  
 cout<<"\n\nFirst Time  \t\t";  
 c1.display();  
 cout<<"\n\nSecond Time  \t\t";  
 c2.display();  
 cout<<"\n\nAfter addition,the time is ";  
 c3.display();  
 getch();  
 }  


Wednesday, March 14, 2012

Java Program -1 way Client-Server Communication using TCP/IP



In java Networking is done using Sockets and ServerSockets.To get a good idea of how sockets are used in java for creating a client server model see the article. http://c-madeeasy.blogspot.com/2012/03/concept-of-sockets-and-networking-in.html

TCP/IP(Transmission Control Protocol/Internet Protocol) :
Is connection based protocol that is widely used over the internet.It is commonly referred to as IP.The following program uses TCP/IP to communicate.


After reading the above article,see the code below.You can see how socket and server sockets are used to create a one way client server program.Here a client can communicate with the server only.Both are DOS/Terminal Java Programs.

Fist you start the server program followed by client program in two separate terminals.In the client terminal type anything,you can see that appearing in the server terminal window.

The complete Java Program source code to implement 1 way client and server model is provided below as two separate programs Client.java and Server.Java

 //Server Program  
 //c-madeeasy.blogspot.com www.codeuniverse.tk  
 import java.io.*;  
 import java.net.*;  
 class server{  
 public static void main(String []args)  
 {  
 String data;  
 ServerSocket ssock;  
 Socket clientsock=null;  
  DataInputStream is;  
 try{  
 ssock=new ServerSocket(2000);  
 System.out.print("Server Started");  
 clientsock=ssock.accept();  
 is=new DataInputStream(clientsock.getInputStream());  
 System.out.println("Connection Accepted");  
 while(true)  
 {  
 data=is.readLine();  
 System.out.println(data);  
 }  
 }  
 catch(Exception e)  
 {  
 System.out.println("ERROR");  
 }  
 }  
 }  
 ---------------------------------------------------------------  
 //Client Program  
 import java.io.*;  
 import java.net.*;  
 class client{  
 public static void main(String []args)  
 {  
 String text;  
 Socket sock=null;  
  DataOutputStream dout;  
  PrintStream sender;  
  DataInputStream keyboardreader;  
  System.out.println("Connecting to Server.....");  
  try{  
   sock=new Socket("localhost",2000);  
   }  
  catch(Exception e)  
  {  
  }  
  try{  
  System.out.println("Connected");  
  keyboardreader=new DataInputStream(System.in);  
  sender=new PrintStream(sock.getOutputStream());  
  do  
  {  
  text=keyboardreader.readLine();  
  sender.println(text);  
  }while(!text.equals("quit"));  

Friday, March 9, 2012

The Concept of Sockets and Networking in Java Simplified

Socket:
A socket is one end-point of a two-way communication link between two programs running on the network.java.net Package provides support for sockets. Socket classes can be used to implement the connection between a client program and a server program.

ServerSocket:
ServerSocket class is exclusive for the Server side implementation of the client-server model.


 Java programming with Socket class allows easy implementation of a client-server model for one way or two way communication. We can easily implement a simple one way client server model,2 way client server model,a broad cast server,a multicast server using Sockets and Server Sockets in Java. 

                                                                      courtesy:oracle

Client Side
 Basically a socket can used in a client to send message it involves creation of socket by using the code


Socket mysocket=new Socket(localhost,2000)


Here a socket is created in the local machine itself you can specify the
ip address of the server machine instead of localhost.

Server Side


In the Sever Side a ServerSocket is created.ServerSocket is a different
class rather than socket.It is meant for the server side only.
In the server side the following code is usually used


ServerSocket ssock=new ServerSocket(2000)


As you can see the same port number should be used in the client and server side.

Classes like PrintStream is used to send message from the client to the server.It is established easily like this

PrintStream ps=new PrintStream(mysocket.getOutputStream)
ps.println("my message");

This code in the client side sends message to the server.In the server 
side this message can be easily accepted and displayed using the 
following code

ServerSocket ssock=new ServerSocket(2000)
Socket mysocket=ssock.accept()
DataInputStream d=new DataInputStream(mysocket.getInputStream)
String msgfromserver=d.readLine() 
System.out.println(msgfromserver)


The method accept() is used to accept a connection from the client.Note that you need to surround the statements with a try-catch block to handle all the exceptions.
In this way you can send a message from the client to server.



Thursday, March 8, 2012

Hybrid Inheritance Example Program in C++ to Calculate the Marks and Percentage of a Student



Hybrid Inheritance is the combination of two or more inheritances : single, multiple,multilevel or hierarchical Inheritances. The following is a C++ Program to for Calculating the marks secured by a student.A Parent class with student identification is created and another class called marks is inherited from the main class.This class marks is further inherited by another class called sports and finally the sports class is inherited by the percentage class to calculated the percentage of marks.This is the best example for Hybrid Inheritance in c++The complete source code is provided Below 



 #include<iostream.h>  
 #include<conio.h>  
 #include<stdio.h>  
 #include<string.h>  
 class student_id  
 {  
 //c-madeeasy.blogspot.com  
 int rno;  
 char name[20];  
 public:  
 void read_id()  
 {  
 cout<<"\n\nEnter the Name of the Student : ";  
 gets(name);  
 cout<<"\n\nEnter the Roll No. : ";  
 cin>>rno;  
 }  
 void display_nr()  
 {  
 cout<<"\n\n\t\tSTUDENT REPORT\n\nNAME : ";  
 puts(name);  
 cout<<"\n\nROLL NO. : "<<rno;  
 }  
 };  
 class marks:public student_id  
 {  
 public:  
 int i,mark[3];  
 void read_m()  
 {  
 read_id();  
 for(i=0;i<3;i++)  
 {  
 cout<<"\n\nEnter the Marks Secured in SUBJECT "<<i+1<<" out of 100 : ";  
 cin>>mark[i];  
 }  
 }  
 void display_m()  
 {  
 display_nr();  
 cout<<"\n\n\tMarks Secured ";  
 for(i=0;i<3;i++)  
 cout<<"\n\nSUBJECT "<<i+1<<" : "<<mark[i];  
 }  
 };  
 class sports  
 {  
 public:  
 int sm;  
 void read_sportm()  
 {  
 cout<<"\n\nEnter the marks in SPORTS out of 10 : ";  
 cin>>sm;  
 }  
 };  
 class percentage:public marks,public sports  
 {  
 public:  
 float total,prcntge;  
 void calculate()  
 {  
 read_m();  
 read_sportm();  
 total=0;  
 for(i=0;i<3;i++)  
 {  
 total+=mark[i];  
 }  
 total+=sm;  
 prcntge=(total/310)*100;  
 }  
 void display_totp()  
 {  
 display_m();  
 cout<<"\n\nTOTAL = "<<total;  
 cout<<"\n\nPERCENTAGE = "<<prcntge;  
 }  
 };  
 void main()  
 {  
 int cont;  
 percentage pc;  
 clrscr();  
 do  
 {  
 pc.calculate();  
 clrscr();  
 pc.display_totp();  
 cout<<"\n\nDo You Want to Continue?(1-YES/0-NO)";  
 cin>>cont;  
 }while(cont==1);  
 getch();  
 }  

Which is the Best Photo Watermarking Software

Photo Theft is becoming more and more common in the web with the outburst of social websites like Facebook,Google Plus and Image sharing se...