Java update for applications

The Ultimate Guide to Java Update Check

In this quick tutorial, we’ll take a close look at how to check for Java updates.

We’ll get started with some insight into how to check the Java version. Then, we’ll explain in detail how to perform a Java update check. Lastly, we’ll shed light on how to disable Java automatic updates.

Java Update on Windows 10

In general, when we install Java on Windows 10, another small program that checks and tracks Java updates get installed too.

As a matter of fact, there are many simple methods that we can use to check whether there is a new Java update.

However, before checking for Java updates, we may need to know which version is installed on our machine. So, let’s see together how to do that!

How to check Java version

The most simple way to check the current installed Java version is to use the command prompt.

First, we need to open the command prompt. To do that, we need to type cmd in the search bar:

check java version

Then, we have to type: java -version in the command prompt:

 Microsoft Windows [Version 10.0.19041.572] (c) 2020 Microsoft Corporation. All rights reserved. C:\Users\Asus>java -version java version "1.8.0_261" Java(TM) SE Runtime Environment (build 1.8.0_261-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.261-b12, mixed mode) C:\Users\Asus> 

As we can see, the command line java -version displays the current Java version that is installed on our computers.

Now, let’s dig deeper to see how to perform a Java update check.

How Do I Check for a Java Update?

The process of checking Java update on windows 10 is pretty simple. All we need to do is follow the following steps:

First, we need to click on Show hidden icons — a special icon that we can find in the bottom right corner of the window.

java update check step 1

Then, we need to click on Java Update Available – This will open the following window:

check Java update step 2

Furthermore, as shown above, the windows will tell us everything we need to know. We can click on the update button to continue and get more information about the available Java update.

Now, let’s see how we can use another method to accomplish the same thing.

Firstly, we can type Check For Updates on the search bar. Then a new window named Java Control Panel will open for us.

another way to check java update

Then, we can go to the update tab to check if there is a new Java update. Easy, peasy right?

We can click on the update button if we want to start the process of updating Java. Once done, our Java will be upgraded to a new version.

Next, we’re going to explain a third method that we can use to check Java updates.

First thing we need to do is open the https://www.java.com/en/ URL in our favorite browser.

Then, we click on the big Java Download button. This will redirect us to a new page where we can find all the information about the last Java version and its release date.

We can also visit the following URL: https://www.java.com/en/download/uninstalltool.jsp to check for Java versions and updates on our computer.

Why is it Important to Check Java Updates?

In general, software updates are important because they provide fixes and improvements, and even patches to security vulnerabilities.

Since Java can be a critical component for many applications that we may install on our computers, then we need to make sure to update it continuously.

Fortunately to us, Java Update is a handy feature that tracks new Java releases. It periodically checks for new versions to keep your Windows computer up-to-date.

Bear in mind that we need to update Java to the newer version to prevent unwanted security issues and enhance performance.

You can refer to this URL https://java.com/en/download/help/java_update.html to explore more about how Java auto-update works.

How to Turn off Java Automatic Update?

Sometimes we may need to disable Java updates — I know what you’re going to say: WHY? This can generate security issues 🙂 — Yes and you’re right!

Keep in mind that it’s highly recommended that you do not turn off automatic updates. However, if you want that do it at your own risk.

Java provides a convenient and simple way to disable automatic periodic Java update checks.

First, we need to open the Java Control Panel window, then navigate to the Update tab, and make sure that Automatically check for updates checkbox is unchecked:

turn off java automatic update

Next, we navigate to the Advanced tab and search for the Application Installation. We need to make sure that the Never install value is selected.

never install java automatic update

Conclusion

To sum it up, we have explained how to perform a Java update check step by step. Along the way, we have showcased how to check the Java version on Windows 10.

We hope you enjoyed reading this article and learned something new from it.

Liked the Article? Share it on Social media!

Источник

Updating Java ME Applications

Updating a Java Platform, Micro Edition (Java ME) application involves updating static data, such as text and images, as well as updating code components of the application. In this article, I develop a sample application that illustrates how to update an application.

The article starts with the basics—updating simple text strings—and then moves to updating images. Finally, the article shows the easiest way to update the core application files, which Java ME makes quite easy. However, this ease can come at a price in terms of extra network traffic.

Note: The complete source code for the application described in this article can be downloaded here.

The Application Flow

Figure 1 shows an example application in action.

Figure 1. Example Application

The application has two elements: a basic text string and an image. Selecting Menu shows the three actions that can be performed, as shown in Figure 2.

Figure 2. Possible Actions

The Update Text menu item will check with a background server to see whether an update is available for the text portion of the application. Update Image will check to see whether the image needs to be updated. Finally, Update Code will update the whole application—the text, the image, and the underlying code.

Coding the Layout

The application is a simple MIDlet that has three basic commands and two visual components. We set up the basic display elements and hook up the commands in the constructor, as shown in Listing 1.

 public MyGreatApp() < // set up the basic MIDlet with the display and the elements display = Display.getDisplay(this); form = new Form("My App"); // we start with a blue square and a simple string of text text = new StringItem("", "My starting text"); try < image = new ImageItem( "", Image.createImage("/blue_square.jpg"), Item.LAYOUT_CENTER, ""); >catch (IOException ex) < handleError(ex); >exitCommand = new Command("Exit", Command.EXIT, 2); updateTextCommand = new Command("Update Text", Command.ITEM, 1); updateImageCommand = new Command("Update Image", Command.ITEM, 1); updateCodeCommand = new Command("Update Code", Command.ITEM, 1); // add the commands etc form.append(text); form.append(image); form.addCommand(exitCommand); form.addCommand(updateTextCommand); form.addCommand(updateImageCommand); form.addCommand(updateCodeCommand); form.setCommandListener(this); > 

Listing 1. Setting Up the Display Elements

There is nothing remarkable about this code. It creates a Form and then adds the two visual elements, a StringItem and an ImageItem, to the Form. These are the elements that we are going to upgrade.

Then various commands are added: Exit and three update commands (UpdateText, UpdateImage, and UpdateCode). Notice that the Exit command is set at a separate level from the update commands, so the update commands are grouped together when you select Menu.

Finally, the current MIDlet is set as the command listener for all the commands so it can handle the callbacks. Let’s look at what we need to do to update the text, the image, and the code.

Coding the Command Handlers

The most important point to remember while coding the command handlers for this MIDlet is that all command handling should be done in a separate thread so it doesn’t block the main thread of operation while doing potentially expensive network calls.

Listing 2 shows the code for handling the UpdateText command:

 if(c == updateTextCommand) < new Thread() < public void run() < ContentConnection cc = null; DataInputStream dis = null; try < cc = (ContentConnection)Connector.open( "http://localhost:8080/updatedText.txt"); int size = (int)cc.getLength(); dis = cc.openDataInputStream(); byte[] data = new byte[size]; dis.read(data); String newText = new String(data); // found some text, and it is updated - so update the screen if(newText != null && !newText.equals(text)) < text.setText(newText); >> catch(IOException ioex) < handleError(ioex); >> >.start(); >

Listing 2. Code for Handling the UpdateText Command

When the command handler for this code starts, it creates a new thread and contacts the server (the server holds the text, image, and code files).

At this point, we are interested only in checking for text-based updates, so we use the ContentConnection class (instead of the usual HttpConnection class). With the help of this class, we check for the presence of an updatedText.txt file on the server. If such a file is found, we read it, using a DataInputStream, into a byte array and convert it into a string. At any stage, if an error occurs, the error handler takes over.

If the file is found, its contents are read, and the contents are not the same as the existing text, we modify the text in StringItem. Voila! We have updated our text! Figure 3 shows the MIDlet after we have run the UpdateText command.

Figure 3. MIDlet After Running the UpdateText Command

The next step is to see how we can update the image. Updating the image is not very different from updating the text. Listing 3 shows how it is done.

 if(c == updateImageCommand) < new Thread() < public void run() < HttpConnection cc = null; DataInputStream dis = null; try < cc = (HttpConnection)Connector.open( "http://localhost:8080/red_square.jpg"); int size = (int)cc.getLength(); dis = cc.openDataInputStream(); byte[] data = new byte[size]; dis.read(data); // found an image - update it if(size >0) image.setImage(Image.createImage(data, 0, data.length)); > catch(IOException ioex) < handleError(ioex); >> >.start(); > 

Listing 3. Code for Updating the Image

As you can see, instead of using the ContentConnection, we use the HttpConnection class to update the image. If we find an image and its size is greater than 0, we download it into a byte buffer using a DataInputStream instance. Using the Image.createImage() method, we create this image in memory and then update the ImageItem to use this new image.

It is expected that an update process on the server would keep the text file or the image file only if updates were available. This would be an offline process and part of the update routines. We could modify our code to notify the user that there are no updates available, instead of letting the error handler handle it.

Finally, we come to one of the easiest parts of the update process. Updating the core code itself (or rather, updating the whole MIDlet and its associated files). Why is this the easiest part? Because by using an in-built function, we can request that the MIDlet update itself. This is useful when you have made several modifications to the code and associated logic and, therefore, non-static data needs to be updated. The downside is that the update process can be network-expensive.

To update the code, use the following code snippet:

 if(c == updateCodeCommand) < try < this.platformRequest("http://localhost:8080/UpdateArticle.jad"); >catch (ConnectionNotFoundException ex) < handleError(ex); >>

We use the method platformRequest(String) to update the code itself. This method is provided by the MIDlet class, and it is used to request that the device on which it is running handle the provided URL. Note that this is not strictly for updating the application/MIDlet itself, but for the generic transfer of handling the URL by the associated device. For example, if this method is called with the URL of an image, the handling device would need to call up an image viewer to view the image provided by the URL.

By providing a URL that ends in .jad (in our case, http://localhost:8080/UpdateArticle.jad) and has the same file name as the currently installed application, the device understands that a request is being made to update the application itself. If the .jad file (and the associated .jar file) is found, and it is determined to be valid, the device will start the download/install/update cycle automatically, without any further intervention from the code itself, as shown in Figure 4.

Figure 4. Updating the Application

Of course, user intervention is required to acknowledge the update process and to answer any pre-update questions, as shown in Figure 5.

Figure 5. The User Must Authorize the Update

Once the user authorizes the update, the device downloads and updates the code. This process happens without any more intervention from the user or the original MIDlet. Once the update has finished, the old MIDlet is removed from the device and the new one is installed. After the install, the device will confirm whether the user wants to start the new MIDlet.

All in all, the platformRequest(String) method of the MIDlet class makes it easy for the application developer to provide an in-built update mechanism for applications.

Conclusion

If you don’t need to update the entire source code for your application, use the connection classes provided within the javax.io package, such as ContentConnection and HttpConnection, to update static data, such as text and images.

On the other hand, if you need to provide a mechanism for updating the entire source code, make sure you follow a valid update process on the server, and use platformRequest(String) with a URL that ends in jad to provide the updates. The device’s interface will then make sure the updates are applied by removing the old MIDlet and installing the new updated version.

See Also

About the Author

Vikram Goyal is the author of Pro Java ME MMAPI: Mobile Media API for Java Micro Edition, published by Apress. This book explains how to add multimedia capabilities to Java technology-enabled phones. Vikram is also the author of the Jakarta Commons Online Bookshelf, and he helps manage a free craft projects Web site.

Источник

Читайте также:  Python generator object to list
Оцените статью