• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

bluetooth connection

 
saad sal
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok here is the problem. I have this Bluelet gallery (.java) files that contain all the bluetooth connection related code. Plus I have made a GUI class for the mobile device.

Coming from a C++ background i dont know HOW to include the Bluelet code gallery into my GUI class ( similar to an #include statement in C++.)..... Would package solve the problem.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your "include" is really the import statement.

Your Bluelet java files should be in a jar file, and you include the jar file in you classpath, then you just import the classes you need to use with the import statement. Just like in J2SE.

Mark
 
saad sal
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well i have both the ".java files" and the "jar file" for the service discovery and stuff. Should i only add the jar file to the class path.


Another question i have is that when i use
"import javax.microedition.io.*;"
Is this like using #include<iostream.h> in C++ OR do i have to add some sort of java header files at javax.microedition.io classpath ?
[ January 27, 2006: Message edited by: saad sal ]
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Java has no include statements and no such concept.

Think of it as an easier way of communicating with other classes. Java's Virtual machine does all the hard work for you, and goes out and looks for the classes when you try to use them.
There is no need to include those classes in your files since the VM will find automatically those classes for you (if they reside in it's CLASS PATH or current running directory).

However, some sort of namespace scheme is required to avoid clashes (for example, both of us can try and name our classes Hello).
So Java has packages which you can use to "put" your classes in (same as the namespace concept in c++ or c#).
So if you have a class called HttpConnection inside the package javax.microedition.io then in order to call it from your code you need to use its full name like this:

javax.microedition.io.HttpConnection

To simplify things, you can use the import statement which all it does is allow you to ommit that full name! so if you write this:

import javax.microedition.io.HttpConnection;

then you can use HttpConnection directly without the full name.

You can also import all of the classes in the package like this:

import javax.microedition.io.*;

So you see, it is not really an include since java finds the classes automatically. It is just a way to reference all the different classes/packages in your code.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also import all of the classes in the package like this:

import javax.microedition.io.*;


But I highly recommend using the "*" approach and name each individual class that you are going to import.

Also to note, the jar file would go into the classpath, whereas the .java file needs to be in the package directory for compiling and runnign to work. What his mean is that if your root directory is c:\myApp\src and the import is com.javaranch.MyClass;

then the MyClass.java file needs to be in the c:\myApp\src\com\javaranch directory.

Mark
 
saad sal
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thankyou both. That cleared out my problem
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic