Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Tuesday, September 9, 2008 | | 0 comments

J2ME - A quick introduction

J2ME or Java 2 micro edition (Also known as Java 2 Mobile Edition) is the version of Java for micro devices. The term micro devices include Mobiles, Handhelds, Palm PCs, embedded systems or even smart cards. So Java is like this J2SE - J2EE - J2ME each with its own specific uses.

J2ME combines a less resourceful JVM and a small set of JAVA apis oriented and designed specifically to develop mobile application for mobile devices. J2ME applications are also called MIDlets, like applets in J2SE and servelets in J2EE (similarity is mostly in name only).


Sunday, September 7, 2008 | | 0 comments

Why implementing runnable is better than extending thread?

We all know that there is two ways to implement threading in Java. And everyone say that implementing runnable is better than extending thread. Why is it so? Simple answer...A Java class can extend only one class( Hybrid or Hierarchical inheritance is not supported) but it can implement any number of interfaces. Thus if we extend Thread in a class which require to be an applet or form, it is not possible.
So always implement runnable.

Friday, September 5, 2008 | | 0 comments

Simplest network Program in Java

Before going to a GUI network program, I decided to write a simple network program in Java. Wrote it and code is given below. A network program in Java can not be simpler than this. basically this program has two files.
  • s.java
  • c.java
s and c stands for server and client respectively. client sends a piece of text "This is the simplest text" to server. Server displays it. Thats all. Simple Huh!

s.java:


import java.net.*;
import java.io.*;

class s
{
ServerSocket servSoc=null;
DataInputStream din = null;
String s;
Socket soc;

s()
{
try{
servSoc=new ServerSocket(2008);
soc=servSoc.accept();
din=new DataInputStream(soc.getInputStream());

while(true)
{
s=din.readLine();
System.out.println(s);

}
}
catch(Exception e){}
}
public static void main(String ars[])
{
s s1=new s();

}
}



c.java:


import java.net.*;
import java.io.*;

class c
{
Socket soc = null;
PrintWriter pr=null;

c()
{
try{
soc=new Socket("localhost",2008);
pr=new PrintWriter(soc.getOutputStream(),true);
pr.println("This is the simplest text");
}
catch(Exception e)
{}

}
public static void main(String args[])
{
c c1=new c();
}
}