Wednesday, September 19, 2007

LG VX8300 and car kit

Just want to mention this cell phone tip. My cell phone is an LG VX8300. A few days ago the words car kit appeared on the display and I was unable to hear any sounds my phone made. The same thing happened a few weeks ago, but after several days my phone went back to normal. Well, it had been a couple of days & still nothing, so I did some research on the internet. I googled "lg vx8300" + "car kit" + remove and came across this site. I did the tip which involves clearing errors. Nothing, so I tried plugging in the charger and jiggling it around. Nothing. I don't have a car charger, so I tried plugging the phone into the data cable I use to upload photos to my computer. I jiggled the cable around & car kit briefly disappeared and then reappeared. I jiggled the cable some more & car kit disappeared again. It's been 6 hours and so far so good. Apparently the words car kit appear when the phone has been exposed to water. Have absolutely no idea how my phone may have gotten wet. Oh well. I'm just glad it's working again.



Cell phones

Friday, August 17, 2007

How to return multiple parameter values in Java

Here's a java tip I discovered.
Java doesn't allow functions to return multiple parameters. You can't pass by reference like in C/C++.
Say you have this function in C or C++:

int get(int a, int* b, int* c)
{
*b = 2 * a;
*c = 3 * a;

return 4 * a;
}

Now you want to write that function in Java. One option is to create an object which stores 3 integer values and return that.
An option involving less work, is the following:
Java lets you pass in an object, to which you can modify the content of the object, so:
First create a java class which stores an integer:

public class _Integer
{
public int _integer;

public _Integer
{
}
}


Now pass this object to your java function whenever you need to return more than one value:

int a = 1;
_Integer bInteger = new _Integer();
_Integer cInteger = new _Integer();

int d = get(a, bInteger, cInteger);


int get(int a, _Integer b, _Integer c)
{
b._integer = 2 * a;
c._integer = 3 * a;

return 4 * a;
}

If you need to pass doubles, create a _Double class, etc.

I thought that was a pretty cool workaround I came up with and just wanted to share.:)


More Java Info

Friday, August 10, 2007

How to get user defined environment variable in Java

I'm porting a C++ library over to Java 1.4.2 and I need to get the setting for a user defined environment variable. There used to be a very easy way, but it turns out some brilliant people decided to deprecate - get rid of - System.getenv for java 1.4. There must have been complaints because for Java 1.5 System.getenv is undeprecated. Unfortunately, I can't guarantee the users of my java software will be using java 1.5. Fortunately, there are people much smarter than I. I did some searching and found a website with some code which determines what system you are on and then calls the corresponding function to get all environment variables. You can then make a call to get the value of the environment variable you need. Here's the link to the site and the code itself:

import java.io.*;
import java.util.*;

public class ReadEnv {
public static Properties getEnvVars() throws Throwable {
Process p = null;
Properties envVars = new Properties();
Runtime r = Runtime.getRuntime();
String OS = System.getProperty("os.name").toLowerCase();
// System.out.println(OS);
if (OS.indexOf("windows 9") > -1) {
p = r.exec( "command.com /c set" );
}
else if ( (OS.indexOf("nt") > -1)
|| (OS.indexOf("windows 2000") > -1 )
|| (OS.indexOf("windows xp") > -1) ) {
// thanks to JuanFran for the xp fix!
p = r.exec( "cmd.exe /c set" );
}
else {
// our last hope, we assume Unix (thanks to H. Ware for the fix)
p = r.exec( "env" );
}
BufferedReader br = new BufferedReader
( new InputStreamReader( p.getInputStream() ) );
String line;
while( (line = br.readLine()) != null ) {
int idx = line.indexOf( '=' );
String key = line.substring( 0, idx );
String value = line.substring( idx+1 );
envVars.setProperty( key, value );
// System.out.println( key + " = " + value );
}
return envVars;
}

public static void main(String args[]) {
try {
Properties p = ReadEnv.getEnvVars();
System.out.println("the current value of TEMP is : " +
p.getProperty("TEMP"));
}
catch (Throwable e) {
e.printStackTrace();
}
}
}



Java Resources

Thursday, August 9, 2007

Copper.net

I think I've mentioned before that all I can get in my area for an internet connection is dial up. Really sucks, but maybe someday there will be a faster option. Anyways, I've been using NetZero's 3g high speed for the past 2 years without much of a problem. Lately though, the high speed part has been very flaky. It keeps disconnecting and speeds have been slow. The other day I got fed up and came across a couple of different providers with good reviews. One is Toast.net. I haven't tried it yet though. The one I'm trying now is Copper.net High Speed. They have a really good deal going on right now, which is why I tried it first. It's $1 for 3 months, after which you can cancel if not satisfied. So far it's not bad. Netzero would always take a long time to load certain sites, such as blogs, including this one. Copper.net doesn't seem to have that problem. My blog actually loads pretty quick. The only drawback so far is Copper.net's high speed also seems to have a problem staying connected initially. Once it gets going though it is fine. So far connection speeds seem a bit faster than Netzero.
Regular price for the high speed version is $14.95 per month. Without high speed, it's $9.95 per month. The customer service number is also free. Unlike Netzero, which charges $2 per minute. Most numbers are V.92. You get a free 25mb email address. There seem to be a lot of access numbers, although just 2 for my area, but it's rural. Copper.net connects faster than Netzero, since it uses the built in dial-up networking in Windows. Netzero has it's own java application, which is much slower. Copper.net also lets you stay connected for a maximum of 4 hours, whereas Netzero disconnects you after 3 hours. If you're looking for a new dial up isp or a backup internet connection, you might want to check out Copper.net.
BTW, Copper.net's high speed is also compatible with the wiflyer.

Thursday, July 5, 2007

InstallAnywhere Now

I've been tasked with looking into an installer, which is supposedly free, called InstallAnywhere. Well, apparently it's not free. The free version is only a 21 day trial. However, tucked away on the zerog.com site is a free version called InstallAnywhere Now. The Windows version is 40mb, so I haven't downloaded or tried it yet, but will post when I do. There are also Mac, AIX, Solaris, Linux and Hp versions available.



In need of a new cell phone? Check out this site for some of the newest phones on the market.

Have you ever tasted a good cup of gourmet coffee? Chances are you haven't!

Thursday, June 28, 2007

WiFlyer

I haven't mentioned the WiFlyer in a while, but I'm still amazed by it. It is so cool. I live in a rural area where the only internet connection I can get is dial up. I'm really glad I discovered the WiFlyer though. It is a small device which plugs into an electrical outlet and phone jack and turns a dial up connection into a wireless dial up connection. I finally bought myself a laptop, so now I can move all over the house and still be able to surf the web using a dial up connection. No more extra long phone wire and no more confinement to one spot. Very sweet. There is also a new version of the WiFlyer out. It has a few more features and has a longer range.
If interested, check it out here. There is also a promotional code to use on check out. For a standard WiFlyer enter: friendw and for a WiFlyer+v enter: friendv. If you're stuck with dial up, the WiFlyer is definitely worth checking out. BTW, it is also compatible with a broadband connection if you ever switch over. The WiFlyer is also ideal for those who travel frequently as it is very compact and some hotels only offer a dial up connection. It is very easy to setup and very easy to use. I am still amazed every time I use it.
Oh, and the WiFlyer works just fine with Windows Vista.



Help Them Surf The Web Faster? Make Money Along! Its Too Easy, Try It Now!

Thursday, June 21, 2007

UnsatisfiedLinkErrors with a jar file, JNI and C++

I've been busy porting legacy C code to C++. Yeah, real fun. I also have a java gui which calls the C code using the Java Native Interface (JNI). This layer also had to be updated in order to use the C++ code. Everything worked great on windows. I then had to make sure everything built and ran correctly on linux and solaris. I am just not a linux or solaris person. Never have been, never will be. However, I did discover something useful.
I built my jar file and shared objects relatively easily. Next I tried running the jar file. The jar file linked to my shared object ok, but it couldn't find the function being called. I kept getting an UnsatisfiedLinkError. I guessed the reason was due to C++ name mangling.
Javah is used to create the jni header files. When the header files are created, javah automatically adds:

#ifdef __cplusplus
extern "C" {
#endif

to prevent C++ from mangling function names. I believe the command I used to look at the function names in the shared object was nm. Weird thing is, the names kind of looked mangled. I did some research on the internet, but found nothing useful. Everything worked fine on Windows, the header files use #ifdef cplusplus to prevent name mangling, so how could the function names be mangled? I don't know. I was desperate, so took the #ifdef cplusplus and put it in the C++ source file too. Right at the top, after the includes and before the first function. I ended the #ifdef cplusplus at the very end of the file. I recompiled and tried running the jar file again. What do you know? No more UnsatisfiedLinkErrors. The jar file found the functions in the shared object just fine. Thank goodness.





Help Them Surf The Web Faster? Make Money Along! Its Too Easy, Try It Now!