Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures

Home

Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips

Books

Submit News
Search the site here...
Search...
 
Search the JavaFAQ.nu
1000 Java Tips ebook

1000 Java Tips - Click here for the high resolution copy!1000 Java Tips - Click here for the high resolution copy!

Java Screensaver, take it here

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java programming articles and tips. Please take your copy here.

Take your copy of free "Java Technology Screensaver"!.

Java Newsletters Archive: 20

JavaFAQ Home » Java Newsletters Go to all tips in Java Newsletters


Bookmark and Share

***********************************************
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ *
* > The Java FAQ Daily Tips, weekly publication < *
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ *
* *
* Issue No: 20 17 January 2001 *
* http://www.javafaq.nu/java *
* *
* *
* Please recommend our FREE "100 Java Tips" book and us to your *
* friends and colleagues! *
* http://javafaq.nu/java/advert/our_book.shtml *
***********************************************

Table of Contents

1. Are there any tools out there that will convert a program
writen in C to JAVA?
2. Can we create DLLs in java??? if yes How???
3. Is there a way to know from class X which class called the
method foo()?
4. Can someone tell me the difference between the JRE that comes
with the J2SDK and the stand-alone JRE?
5. Why I see applet in applet viewer and do not in a browser?
6. Whenever I compile my servlets it always says "can't find
package javax.*" even though I downloaded the JSDK...
7. Why does this simple application never exit?
***********************************************

Hello dear friends!

***********************************************

Tip 1 Q: Are there any tools out there that will convert a program
writen in C to JAVA?

Answer: Yes.

C2J: http://www.novosoft-us.com/NS2B.nsf/w1/C2J 
C2J has successfully compiled itself as well as programs such as
PGP and YACC. Obviously YMMV.

Based on C2J is a C++ to Java tool:
http://sol.pace.edu/~tilevich/c2j.html

***********************************************

Tip 2 Answer: Unfortunately it is impossible. DLL stands for
Dynamic Linking Library and has definite structure inside. DLL is
a part of executable code and helps to make an application for
Windows to be more smaller. And more flexible. It is something
like classes but compiled (Java class files are byte codes and
JDK compiles them during the runtime...).
In Java it is not possible to make an executable code.
But with third party software Yes! 
See native compilers on our site. 
But I didn't hear about creating DLLs.

So my answer is: in Java it is not possible, but with third party
applications it is possible theoretically. Although I do not know
any compilers that produce DLLs
there is no limitations to do that....

John

***********************************************

Tip 3 Q: Is there a way to know from class X which class called the
method foo()?

Answer: If class A and class B are calling a method foo() on class X,
is there a way to know from class X which class called the method
foo() (they can be either A or B). I know that this can be done by
capturing the stack trace and examining it, but that solution looks
expensive as I have to create a new Throwable object every time and
capture stack trace (And I do this quite frequently).

Is there any other elegant solution to do this, any help and direction
is appreciated.

Answer: Pass a reference to the class to the foo() method.

foo(Object x){
System.out.println(x.getClass());
}

should do it.

***********************************************

Tip 4 Q: Can someone tell me the difference between the JRE that
comes with the J2SDK and the stand-alone JRE?
Can someone tell me the difference between the JRE that comes
with the J2SDK and the stand-alone JRE? When should I use which?
I read the sun's web page and they said the the JRE stand-alone
package is for shipping your application, it doesn't come with a
compiler nor debugger, but what does it really mean?

Answer: Exactly that. The Java 2 SDK (aka JDK) is the JRE plus
the compiler (javac) and debugger (jdb). The JRE is entirely
sufficient to run a Java application (with a couple exceptions
in situations where you call into the compiler or some such).
It's entirely redistributable with your Java application if
you've written an app in Java intended for an audience that
may not have the JRE installed.

***********************************************

Tip 5 Q:Why I see applet in applet viewer and do not in a browser?
When i try to view my applet on a web page i get the error

java.lang.NoSuchMethodError: java/lang/Double: method
parseDouble(Ljava/lang/String;)D not found

Which is weird as it compiles fine on Borland and with the JDK
using applet viewer
Anyone have any ideas what is going wrong?

Answer: The parseDouble method was only added to Java in JDK 1.2
Browsers typically only support Java 1.1 
If you have the JRE installed, you can run Java 1.2 applets. But
you must also change the HTML code that embeds the applet. Check
javasoft.com. I believe they have a program which will
automatically change the "APPLET" tag to "EMBED" and add whatever
else is needed. It's been a while since I've done applets but I
do remember running across a similar problem.

***********************************************

Tip 6 Q: Whenever I compile my servlets it always says "can't
find package javax.*" even though I downloaded the JSDK. Where
the JSDK files so it'll find that package?

Answer: There are no classes in the javax.* package. There are
classes in javax.servlet.* and javax.servlet.http.*, but neither
are really related to javax.* -- importing javax.* won't affect
them. You should import the packages that you really want to use!

***********************************************

Tip 7 Q: Why does this simple application never exit?

public class UIQuitTest {
public static void main (String[] args) {
java.awt.Frame f = new java.awt.Frame();
f.dispose();
f = null;
} // end of main ()
}

The application above never quits, is it a bug or a (mis)feature?
Win98, JRE 1.3.0

Answer: By creating an AWT object, you now have started the AWT
thread. In order to end the application now, you have to do
a System.exit(0) that will kill all non-daemon threads,
including the AWT thread.

The Java FAQ Daily Tips is a newsletter that is only sent to those
who have specifically subscribed to it.

Copyright (c) 2000 John Andersson


 Printer Friendly Page  Printer Friendly Page
 Send to a Friend  Send to a Friend

.. Bookmark and Share

Search here again if you need more info!
Custom Search



Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy