Updating JRE on Mac OSX

For those who desired to updating Java plugin (the runtime environment) to their Mac OS, here's a short how-to's guide. Java on OSX is available only from Apple it self by self-patch-package & not provided by Sun like others supported OS.

First, make sure that your OSX is virgin from JRE. Check it out from your favorite browser (Safari or Firefox) by loading an applet sample page (eg: from this link). If your browser displaying an unsupported plugin just like picture below, then it's the sign that your OSX still not Java ready yet.



If you guess that it may resolve from auto-search plugin window (for example from Firefox browser), then certainly that Firefox couldn't find it best suitable.



If you guess that it may resolve from Sun website, then you may find an answer that the JRE's only available from Software Update feature.



If you guess that Software Update feature will find you this lost JRE, then you probably find nothing up there.

So, where the hell is this JRE package? In a middle of annoyed situation, a knowledge base website from Apple has an important update information regarding to this case (http://support.apple.com/kb/DL848).



Finally, the patch package has founded. Download it & make an install like usual package. Note that you need to close your active browser before running the patch!



After the installation completed, try to open browser & execute your applet sample.



Like image above, so the case is closed now :)

Labels: , ,

  Post a Comment

Make DHTML more Dynamic with Java Applet

In a rarely cases, DHTML is not enough only with the use of Javascript. Some specific purpose in a web page just couldn't be supplied with it. Basically, Javascript has several limitations, especially in a page that need to retrieve information related to local machine resources.

Let say - for example - how to list printer names (on web based application) that installed locally in local machine? Without ActiveX object available in Windows & Internet Explorer browser, there is no option to gain with it. So, what's so special with "Dynamic" terms in DHTML if it stuck with specific OS's or browser? Please pay attention, Java Applet is the only key for the answer (multi-platform, multi-OS & multi-browser - theoretically :).

Well, I'm not a Java expert that order you to moved to become a Java programmer since my self is not included to the statement. Anyway - on this chance - I just tried to tells that "there's many ways to Rome", there's lots of things we can do to make our web page function properly accepted, but there's only a way to list printer name installed in local machine. Just spread up your creativity, make a R&D & your done! This article dedicated to peoples who follows Method 8 Framework & founder of jZebra (Hi, Tres. Looks like I need to modified the source :).

Before it started, imagine first: "I'm a new to Java programming, how can I make an applet?" and "Okay, I made it, so how can I embedded it to the page?" or "How can Java Applet communication with Javascript?"

As sequentially within the story, I'll share the answer. First of it, provide Netbeans & JDK installation file & configure it on your machine. Then, create an Applet project from Netbeans. On the example, I named both the project, class & java code with printName.

package printname;
import javax.print.PrintService;
import java.awt.print.PrinterJob;
import java.applet.Applet;
public class printName extends Applet {

public static void main(String[] args) {
String printerName;
printerName = menuList();
// just make a call to print out its value
System.out.println(printerName);
}

public static String menuList() {
// Lookup for the available print services.
PrintService[] printServices = PrinterJob.lookupPrintServices();

// Iterates the print services to a variable
String printerName = "";
for (PrintService printService : printServices) {
String name = printService.getName();
printerName = printerName + "#" + name;
}
return printerName;
}
}


Save & run above compiled code, you'll see that the applet will return a line of string of local printer name which separated with "#" character. Build & clean the code to make the JAR file.

Now, copy/upload the JAR file to the same folder where the HTML laid. Return to HTML editor & create a param tag to embed the JAR file. Also, create a dropdown select since we're gonna list that printer name from the applet to that object.

<html>
...
<script language="JavaScript">
function addOption(selectbox,text,value) {
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}

function removeAllOptions(selectbox) {
var i;
for(i=selectbox.options.length-1;i>=0;i--) {
selectbox.remove(i);
}
}

function fPrintName() {
var afPrintName = document.printName.menuList();
removeAllOptions(document.fInput.printerName);
addOption(document.fInput.printerName,'-- Pilih Printer --','');
if (afPrintName.length!=0) {
var namaPrinter = afPrintName.split('#');
n = namaPrinter.length;
for (var i=1; i<n; i++) {
addOption(document.fInput.printerName,namaPrinter[i],namaPrinter[i]);
}
}
}
</script>
<body onload="fPrintName();">
<applet name="printName" code="printname.printName.class" archive="printName.jar" width="1" height="1"></applet>
<form name="fInput">
<select name="printerName"></select>
</form></body>
...
</html>


Done, upload to the web server directory. Now, check your current printer from the control panel. There's 2 printers listed on my system.



Open your browser & locate to the html page. For the first usage, a standard permission window may appear since it need to confirm the security in the client side.




Finally, here come the result. The printer name now listed to the page.



CONCLUSION
The use of Java Applet on this case helping user to choose a selected printer name they want to print out with. It's useful to combine with jZebra since it only works with printer name that specified before. The Javascript core function located on fPrintName(). This function (first line -- document.printName.menuList()) purposed to communicate with the applet embedded in param tag, also to parse the string value returned from the applet. With 4kb of JAR executable size, this is so light-weight applet.

Labels: , , , ,

  Post a Comment

Testing Java on Mac OSX86

One interesting thing I found after installing Mac (Intel) OSX86 was the availability of complete Java development package. The built-in Java resource has become an added value so that you don’t have to worry anymore to seek & find the Java package natively for your Mac.



I tried to create a simple java source from text editor & would like to see the compile process & runtime result. The source below normally will displayed a “Hello Java…” string:

class hello {
public static void main(String[] args) {
System.out.println(“Hello Java”); } }



I then switch to terminal & make it compiled with javac compiler command:

:~/javac hello.java

Let the compiled source run & see the result below:



It works fine. The apple system has proven that it also stands for Java development based application instead of others OS. A great work from Mac OS team developers.

Labels: ,

  Post a Comment