Java based usb application - java

I working on a Java based application which can be carried around by the user in a USB flash Drive. At the startup I want to check for existing JVMs on the machine the USB is plugged-in.
How can I achieve it ???

Investigate JSmooth -- http://jsmooth.sourceforge.net/ --
or Java Web Start in newest Java 6.
http://java.sun.com/j2se/1.5.0/docs/guide/javaws/developersguide/cdinstall.03.06.html

If you wrap the program in an .exe wrapper - as Launch4j - it can check for JVM installation,
before each execution.

Isn't this a chicken-and-egg situation?
Your Java program needs to be launched in a JVM before it can run its logic to look for JVMs. And at the point it can look, a JVM has already been found so I don't think you could do anything particularly useful with it. (Unless your "main" app is actually a tiny bootstrapper, which chooses the JVM it wants and uses Runtime.exec to launch the real application.)
In any case, I would suggest that it's not the responsibility of the application to choose which JVM it wants to run in; the user will set up his environment to run with the JVM he wants, and I'd consider it rude to ignore this and force your own choice on him (which is likely to be made with less knowledge about the relative merits of those JVMs).

Related

If it's "Write once run anywhere", why do so many Java programs tell me to pick the version for my OS?

I am fairly new to Java or programming in general. On my journeys through the internet to master this language I have come up the saying "write once run anywhere" multiple times.
But I have found many software that requires you to pick the right version for your OS. Sometimes there is only one version available.
Could you explain to me why that is so?
[expanded per the comments]
Java runs on a Virtual Machine, the JVM. In an ideal world this means that the Operating System is abstracted away behind this and you only have to make sure your code works with the JVM which will make it work with the underlying OS. This can already be undone by using the wrong path separators or line endings; it is not an absolute truth.
An application can use many Operating System-specific approaches/libraries/functions/etc that might make it not feasible to restrict yourself to one general codebase. Instead they might want to leverage some advantages provided by a platform and create a separate application with it.
The statement should probably be somewhere along the lines of "Write once in a general fashion, run anywhere" but that's not as snappy.
This statement is often linked to Java but there are also other languages that incorporate this: weblanguages like Javascript and HTML will run on any browser because the browser itself forms the abstraction between the language and the underlying OS.
Other languages don't have this (entirely?) since they work differently: C# will use the underlying .NET framework which as it is only exists for Windows. There exists a cross platform variant (Mono) but it would be an overstatement to consider C# truly cross platform.
The Java program or source code is compiled to generate "bytecodes" ( an intermediate binary format). Second, the bytecodes is executed by an interpreter which is part of the Java Virtual Machine (JVM).
"Write Once, Run Everywhere" refers to the fact that an application written is Java can be run on any hardware which has the Java Virtual Machine (JVM), and that the JVM is now licensed to hundreds of operating systems vendors systems including Microsoft for Windows.
Well, some stuff is really cross-platform (most of standard Java library), while some other stuff may need right version for the OS. Generally, this applies to software that uses dynamic libraries, that aren't written in Java. In this case, versions for different OSes are packed with libraries for this OS.
In case there's version only for one OS - it could be because required libraries don't exists for other OSes or developer didn't port it. There is still possibility that it's actually cross-platform, but developer tested it only under one OS.
Your question is more based on platform dependency/independency.
Java is a programming language which is platform independent which means the code which you write will produce the same output on all machines running Windows, Linus, Unix, etc... without any changes to the code. To run a Java program you need to have JVM (Java Virtual Machine) installed. Now what does JVM do.? Well, it translates your code into Machine code which the Operating System could understand. Therefore JVM is platform dependent since every OS has a different Machine code.
So, basically you write a Java Program only once and can be used/run everywhere.
you can write source code in one platform and run it any where.some times you can encounter problem if a new java version is available but still current version runs the code.

Bootable program

I'm a front end developer that's looking to get into some other languages such as Java or C++. I have an idea for a program and was just looking for an answer to something. What I would like to do is build a program and boot directly to that program. For example I have an old computer and I wipe the hard drive clean. So they is nothing currently on it. Not even an OS. I want to build a program that I can install to the hard drive that will boot straight into the program once started. Would this be considered an OS?
No you don't. Unless you want to spend many years, writing drivers for your graphics card, harddisk controller, usb controller, dma controller and all the other hardware your computer have.
What you want is a minimal operation system, which include just the kernel, and a runtime library and which start your program and nothing else on startup. A minimal Linux such as linux from scratch or bsd would be a good starting point.
First of all you need to decide your your program needs what. I mean should operate in Protected mode or the routine you have is tiny, so it is enough to run before entering protected mode (i.e. in real mode).
Here you can do three things
Modify bootloader to jump the execution to your code . Then Your code can resume normal os initialization.
Modify your os kernel early initialization code So that it executes your code before entering protected mode
I think your code will not be harmed if a bit of os portion is running. So you can write your routine before full kernel initialization.
Now note that for the later two point you need to modify your kernel, which is not easy (not even always possible)
Now the problem in first approach: Nothing will be ready for you, not even a regular c library or divice drivers , so you have to write every raw bit of code by hand which is crude.
This is off course not possible in java. Because the jvm will not be ready for you.
Now practically: there are lot of tiny os available, use one of them and modify as per your need. use this link to get a complete list of what is available for you.
First, Java is right out. You cannot possibly do this in Java without enormous amounts of tool-building. Java is not suited for this task at all.
You can do it in C++ or C. The search terms you are looking for is operating system development. This would probably not technically be considered developing an Operating System since it wouldn't run other programs, but the information about how to get through the boot-up procedure and establish a minimal environment are going to be most easily found in the category of operating system development. Some reasonable starting resources for that can be found at the OS Dev Wiki.
Alternately, you could take an existing small open-source OS and modify what it does after the boot-up sequence completes. If your program is intending to do anything more than just use the keyboard and the screen in text mode, there need to be device drivers. Thus, depending on the project, changing an existing OS may be the easiest route because you won't need to write your own device drivers for any devices you want to use.
Java can't run without Environment. If you want to run you program on you machine without OS, Java is a wrong choice.
C++ program can run without OS, but it's difficult to write a bootable program in C++.
If you want to write your own bootable program, you should use assembly for boot and load function, with some knowledge to use hardware in low level.
You have to have an operating system, so your program would be the operating system (or you would have to use another one and write it for that). It's certainly possible in C++, but it's not really possible to write an operating system in java.
Unless you want write something in (for example) Open Firmware and Forth or say a ROM BASIC. You'll probably qualify as a boot loader. Your application may qualify as an operating system. In my opinion, and a modern context, it entirely depends on how much functionality it provides to hosted applications. I'm not sure that something like FreeDOS would be considered an operating system (no pre-emptive task scheduling or GUI for example) given modern computers (I don't care to argue the point either way).

Would Java Virtual Machine run on WinRT?

It seems to be a simple question, but I wasn't able to find a meaningful answer, only a lot of speculations.
Also, if an answer is yes, which JVM would it be, Oracle's or again something patched by Microsoft?
Specifically: I have a Java desktop application, running on JRE 7, would it run on WinRT?
I mean, can I install JRE 7 on WinRT? Would it run without problems?
Yes and no.
It would certainly be possible to implement a Java Virtual Machine, or at least a substantial portion of one, using the Windows Runtime APIs and the portions of the Windows API that are usable from a Windows Store app. However, such a JVM would need to be an interpreting JVM, not a JIT compiling JVM. JIT compilation requires the ability to change memory protection (to allow execution of generated code), but the APIs to change memory protection (VirtualProtect and friends) are not callable from user code in a Windows Store app.
So, could you implement an interpreting JVM usable in a Windows Store app? Probably. Whether or not it would be possible to implement a JVM that performs well enough to be usable is another matter altogether, though.

Writing a basic java shell or GUI on a kernel

As a hobby I have been writing a shell in java. It's very basic, it include the creation, deletion, reading of files through a command line or through a desktop-like environment if a plugin is installed (which I also wrote).
Now my question is a very complicated one, but I hope someone can point me to the right direction.
Is there a layer or an operating system out there that has java
support, so I can run my java application on top of it, to serve as a
shell? Something minimal?
I don't fully understand the library inheritance in java to its full extent yet, and I'm not sure if AWT and swing applications are something that is built for the major OSs out there.
Can someone point me in the right direction? I just want to learn here, and I don't fully understand the full details of the layers underneath my java program.
There are (at least) 2 examples where Java is supported at the operating system level
Sun had a bare-metal operating system called JavaOS which is no longer available. I don't recall the exact details but I think that the target architecture was some kind of embedded processor.
There is an open source bare-metal Java operating system called JNode that runs on x86. It already has a command shell (the "bjorne" shell) and a primitive GUI.
The bad news with JNode is that it doesn't have a working "isolates" implementation, so it is impossible to stop a buggy applications from bringing the operating system to its knees. This has become a roadblock to progress ... especially since a viable isolates implementation probably would require a redesign of the system architecture to support a separate address space for each isolate.
Java doesn't interact directly with the OS, instead it uses the Java VM that serves as a mediator between the Java app and the hosting OS. Having this VM allows Java apps to be portable since it abstracts away the OS specifics. Java VM implementations differ for different OSs but that's probably not something you should be worrying about; the VM is available and distributed for most major OSs, just download and install the one for yours from http://www.java.com. After that you're free to go with your app.

Difference between 'java' and 'libjvm.so' (Linux) or 'jvm.dll' (Windows)?

What are the differences in starting an application through the plain java command, against directly invoking the JVM through libjvm.so in Linux or jvm.dll in Windows ?
Recently I saw on a forum that starting eclipse using the dll or .so file will give better performance. I would like to get to know how this happens.
Thanks.
Typically folks build against jvm.dll if they want to wrap their own functionality around a Java core, where sometimes it's hard to do things that look "native" from Java. A good example is indeed Eclipse, where they want to pop up a splash screen and do some other actions before starting up. For other products, it's that Java is only a small part of their workload (eg: large C++ app that needs to bridge into Java at some point).
From a performance perspective, it's irrelevant. It's all about how you want the "fit and finish" for things like Eclipse.
The link discusses Eclipse start-up; it is likely that this is faster because, by using the -vm argument to specify the JRE, the Eclipse executable doesn't have to search the system for an appropriate JRE to launch (which would incur disk I/O and possibly involve detecting the version of the JRE). You aren't speeding up Java, you're speeding up the native launcher.

Categories

Resources