Tuesday, November 4, 2008 | | 0 comments

J2ME- implementing DiscoveryListener

DiscoveryListener interface should be implemented for any bluetooth program written in Java.

Following are the methods that should be overridden while implementing the DiscoveryListener.

  1. public void deviceDiscovered(RemoteDevice remoteDevice, DeviceClass deviceClass)  -  A device is discovered
  2. public void inquiryCompleted(int param) - Inquiry for bluetooth enabled and discoverable is completed
  3. public void serviceSearchCompleted(int transID, int respCode)  -  search for services of a discovered device completed
  4. public void servicesDiscovered(int transID,ServiceRecord[] serviceRecord) -  a service is discovered for the device

Wednesday, September 10, 2008 | | 0 comments

Bluetooth in J2ME

Bluetooth is a very short range radio technology allowing the communication between devices which are in close physical proximity. When bluetooth is used to form a small network between bluetooth enabled systems, it is called a PAN or Personal Area Network.
  •  A Bluetooth network can have one master device and upto 7  slave devices. Such a personal area network is called piconet.
  • The term Device refers to a discoverable entity in the piconet.
  • The process of discovering devices is called Inquiry.
  • Each device in a network is assigned a UUID -  Universally Unique IDentifier. A unque randomly generated number of 128 bits identfying the device.
  • SADP - Service Application Device Profile enables the applications that runs on bluetooth devices to discover services on the device.
  • JSR 82 is the bluetooth JSR
  • javax.bluetooth is the package for bluetooth in JAVA.

| | 0 comments

J2ME Display

  • The devices display is seen as an instance of Display class in MIDP or CLDC profile.
  •  The bit depth should be atlaest one. A bit depth of one can have 2 colors.Black and white. A bit  depth of 2 can have four and so on...So an n bit display willl allow 2^N colors.
  • javax.microedition.lcdui and javax.microedition.lcdui.game packages manage the display.
  • Contents of display are changed by passing Displayable() instances to setCurrent() method of Display.
  • public void startApp() {
    Display d = Display.getDisplay(this);
    // ...
    } // this is a typical program to start Display in the startApp() method.

| | 0 comments

J2ME Jargon

J2ME we know is the mobile version of JAVA. A long list of terms is associated to J2ME which a J2SE programmer is not likely to be aware of... Here is a list which of course, needs addition:

  1. J2ME - Java 2 micoedition, the version of JAVA designed specifically for micro devices like PDA,Cellphones,Set top boxes etc. 
  2. Configuration and profiles : Check this post about configurations and profiles
  3. CDC - Common device configuration - a set of rules defining a set of devices to be used under this scheme.
  4. CLDC - Common Limited Device Configuration - a more limited CDC - specifically for PDAs and phones
  5. MIDP - Mobile Information Device profile - A more specific CLDC which narrows down the devices under CLDC to a limited set of mobile phones and PDAs by limiting memory, screen size etc.
  6. JCP- Java Community Process - a community to standardize the usage of JAVA.
  7. JSR - Java Specification Requests - A list and specifications of configurations and profiles in J2ME. Visit www.jcp.org
  8. KVM - a small Virtual Machine of JAVA used in CLDC implementations. K stands for data transferred in Kilo Bytes.
  9. Foundation Profile - A specification for devices which support a networked J2ME enviornment. It does not support user interface. User interfaces and other support is built on top of this profile.
  10. PDAP -  A PDA profile
  11. JTWI - Java Technology for Wireless Industry. A technology which attempts to standadise the J2ME technology.
  12. WORA - (Write Once Read Anywhere) The Java mantra which extends even to J2ME speaking of the platform independence.
  13. Platform fragmentation - A problem associated with J2ME applications which can not be completely solved. WORA is not fully satisfied in J2ME since differenet devices use different device specific APIs. So different versions of same program need to be specified for different platforms.
  14. J2MEWTK - Java 2 Micro Edition Wireless ToolKit
  15. Preverify - An entirely new step in the process of building J2ME applications. Bytecode verification is divided into two, one being that of preverification, so that only a lightweight second verification is requireed before loading classes actually.
  16. Manifest file - A file inside Java Archive which describes the content of that archive. In J2ME additional manifest information is added to manifest file describing MIDP runtime enviornment.
  17. Obfuscator-  A tool for minimizing the size of JAR file.
  18. Proguard- An obfuscator.
  19. Ant - A powerfull build scripting tool. Can be sued for automating the build process of MIDlet suits. Opensource, similar to 'make' and a part of Apache project.

Tuesday, September 9, 2008 | | 0 comments

J2ME - Configurations and Profiles

In general, the whole J2ME can be divided into two. Configurations and Profiles.

Configurations are the a set of specifications defined for a kind of device whose constrains are memory and processing capability. CDC(Connected Device Configuration) and CLDC(Connected Limited Device Configuration). Usually a minimum and maximum amount of memory elements like ROM or RAM is specified as configuration.

The term Profile is more specific. A family of devices which come under a particular category in a "Device" is called a profile. It is build on top of a configuration. It specifies a set of APIs for the application development of that family. MIDP or Mobile Information Device Profile is the example. MIDP comes under CLDC. It specifies additional memory constrains, screen size, network connection and input mode which are not specified by CLDC.

| | 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.

| | 3 comments

Into GUI Java Network Chat

Finally I managed to make a simple GUI Java Network Chat Work.

  • It is two way. I meant client-server. Earlier I did a client to server messaging application.
  • Connection is given inside the code itself. Its temporarily given as localhost. You can make it work in any LAN by substituting it with clients IP address.
  • You will find many errors with this. Yet this will atleast teach you how not to programin JAVA. ;)
Code given here:
client.java

import java.net.*;
import javax.swing.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;

class client extends JFrame implements ActionListener
{

Socket soc=null;
PrintWriter pr=null;
DataInputStream din =null;

JPanel panel1=new JPanel();
JButton button1=new JButton("Send");
JTextArea text1=new JTextArea(20,30);
JTextArea text2=new JTextArea(5,30);


class msgs implements Runnable
{
Thread t=null;
msgs()
{
t=new Thread(this);
t.start();
}
public void run()
{
while(true){
try{

text1.setText(text1.getText()+din.readLine());
}catch(Exception ae){}
}
}
}



client()
{
try{
soc=new Socket("localhost",2008);
din= new DataInputStream(soc.getInputStream());
pr=new PrintWriter(soc.getOutputStream(),true);

panel1.setLayout(null);
setLayout(new BorderLayout());
text1.setBounds(5,5,200,200);
text2.setBounds(5,210,200,50);
button1.setBounds(5,290,200,50);
panel1.add(text1);
panel1.add(text2);
panel1.add(button1);
getContentPane().add(panel1);
button1.addActionListener(this);

msgs m = new msgs();
}catch(Exception e){}


}

public void actionPerformed(ActionEvent ae)
{
if(ae.getActionCommand().equals("Send"))
{

pr.println("Client: "+text2.getText());
text1.setText(text1.getText()+ "\nClient: "+text2.getText());
}
}
public static void main(String args[])
{
client client1=new client();
client1.setSize(250,400);
client1.setVisible(true);
}
}



server.java:

import java.net.*;
import javax.swing.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;

class server extends JFrame implements ActionListener
{

ServerSocket servSoc = null;
Socket soc=null;
DataInputStream din=null;
PrintWriter pr = null;

JPanel panel1=new JPanel();
JButton button1=new JButton("Send");
JTextArea text1=new JTextArea(20,30);
JTextArea text2=new JTextArea(5,30);

class readMsg implements Runnable
{
Thread t=null;

readMsg()
{
t=new Thread(this);
t.start();
}
public void run()
{
while(true){
try{
text1.setText(text1.getText()+din.readLine());
}catch(Exception e){}
}
}
}

server()
{
super("Server");
try{


servSoc=new ServerSocket(2008);


panel1.setLayout(null);
setLayout(new BorderLayout());
text1.setBounds(5,5,200,200);
text2.setBounds(5,210,200,50);
button1.setBounds(5,290,200,50);
panel1.add(text1);
panel1.add(text2);
panel1.add(button1);
getContentPane().add(panel1);

setSize(250,400);
setVisible(true);

button1.addActionListener(this);

soc=servSoc.accept();
din= new DataInputStream(soc.getInputStream());
pr=new PrintWriter(soc.getOutputStream(),true);

readMsg r=new readMsg();


}catch(Exception e){}
}

public void actionPerformed(ActionEvent ae)
{
System.out.println("Aaaaa");
if(ae.getActionCommand().equals("Send"))
{

pr.println("Server: "+text2.getText());
text1.setText(text1.getText()+ "\nServer: "+text2.getText());
}
}
public static void main(String args[]) throws Exception
{
server server1=new server();

}
}

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();
}
}


Sunday, August 31, 2008 | | 0 comments

List of student projects in Java

I wasted the entire night. Did not do anything worth. Anyway browsed Internet and found some good Java resources.

One of them is here for you : A nice list of student projects in Java

And many people say eclipse is better than netbeans. Is it? Anyway I'm gonna stick to netbeans.

| | 0 comments

A CLI Java Network Application

Finally, I did make a simple Command Line Java network application to work. In fact, I just copied it from this "Creating simple Chat client" available at Internet. But I learned each and every line of code in it, the only thing I wanted.

Now I'm going to make it work in a GUI. As per now, I have succeeded partially. On way I learned theory of Sockets classes in Java which implements(not in the Java sense) it.

I will post my updates after completing it. Oh, almost forgot....I will be doing this project as a network application.

Saturday, August 30, 2008 | | 0 comments

NetBeans IDE for Java

I began to use Netbeans IDE for programming in Java. Even though I can not grasp it fully in the first look, I believe I can do better with it.
For those who do not know what Netbeans is:

Netbeans is a Integrated development environment from SUN microsystems. Even though it is specifically designed for java programming, support for other languages can also be added by installing extra plugins. Just got to netbeans.org and download the latest version.

| | 0 comments

Packages in Java

A package is a collection of classes. There are inbuilt packages and you can also build package of your own. In fact, whatever program you build belong to a package(It was a new information for me). If you do not manually specify a package name, it belong to a nameless package. It is recommended only for small test programs sor simple applications. All major works should use a package. We will do too!!!

You can learn more about packages here
Sun tutorial on Java PAckages

| | 0 comments

Set Path for Java in Windows Vista

Now, I wanted to set path for Java in Windows Vista to make it run at command prompt. I re-learned it from Sun Java site

Goto System->Advanced->Environment variables ->

Under system variables, modify the path option. Put a semi column (;) and add the path to your Java's bin directory (mine was C:\Program Files\Java\jdk1.6.0_03\bin) to it.

You are done.

| | 0 comments

Mini project in Java

Hi, I'm Vishnu Prathish from College of Engineering Trivandrum. We have to submit a mini project for our 5th semester for evaluation. We mean to do it in Java though I'm not well versed with it. So I started this blog to keep track the course in which I'm learning Java and eventually we develop our project.

I begin here....