× Please, log in to give us a feedback. Click here to login

You must be logged to download. Click here to login


MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation


MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

Working with Java Packages

In this article we will see how to work with Packages in Java.

Let us understand with the help of this tutorial how java packages work.

In order to make an effective use of the mathematical calculations, we can make use of the java packages. Package is one such asset that can be made use of in order to achieve this. We have a java language that is capable of providing with the best of the environment that is independent of the environment and this is applicable to majority of the applications. This is due to the reason that we have core Java classes which is capable of elongating the libraries that are available to work with. The java packages permits us to access the java classes thereby making it possible to make use of already existing class files.

We know that the java is capable to install its script files (.m) in the directory.../share/packages/java-1.2.8. Also talking about the binary files, the files of the same are located in directory.../libexec/packages/java-1.2.8.

We can learn more on this by implementing the command known as help that can be done with the name of a function from this package:

Listing 1: Implementing the command

package> help javaObject

Also, the entire doc file can be implemented by running the info command just by making use the java word.

Listing 2: Implementing the entire doc file

package> doc java

Java classes availability to Packages:

In order to find the java classes, this can be made by looking for a classpath. This is nothing but a list of files that are archived or directories that contain these files. Below lists two parts that class path is actually consist of.

  • The first one is the static classpath which is usually started when Java Virtual Machine is initialized.
  • The second one is known by the name of dynamic classpath that has the potential of being altered at the time of execution.

Java Packages go and usually look out for the static classpath first, then comes in the turn of the dynamic classpath and we have classes that are capable of appearing in both static as well as dynamic classpath. Hence due to this ability, this can be located or found in the static classpath and then loaded from this location.

Dynamic classpath is the best place for those classes to be placed in which are usually use by a particular script. More importantly, the portion of this classpath has the potential to be modified at the time of execution by making use of javaadd as well as javarm path functions. The below lists the example of the same:

Listing 3: Example of javaaddpath and javarm path

pkg> base_path = “C:/java_files";
pkg> % Adding archives to dynamic classpath
pkg > javaaddpath ([base_path, "/classes.jar"]);
pkg > javaaddpath ([base_path, "/classes.jar"]);
pkg > % check the dynamic classpath
pkg > p = javaclasspath;
pkg > disp (p{1});
pkg > disp (p{2});
pkg > % First element removal from classpath
pkg > javarmpath ([base_path, "/classes.jar"]);
package> p = javaclasspath;
package> disp (p{1});
pkg > % provoke an error
pkg > disp (p{2});

Let us look at the alternate way in order to incorporate these files to the dynamic classpath. This will be specifically to the account of the user in order to make use of the file .packagerc . This file is usually stored in the home directory and we have all the packages commands that are available in this fle to be executed or run every time we start the new package instance. Below example lists how the directory ~/package can be incorporated to Package’s search path. Also it lists the way to add the archive myclasses.jar in this directory to the Java search path.

Listing 4: Adding the archive myclasses.jar

File: pkg
addpath ("~/pkg ");
javaaddpath ("~pkg/classes.jar");

The function javaObject can be made use of in case we want the code to work under java package. This is required so as to create the java objects. We have the function by the name of java_new that is specific to package. This however does not exist in the package environment and the is_ pkg () can be made us of so as to differentiate between the environments.

Listing 5: Using is_pkg

if (is_ pkg)
  Traveller = java_new (' pkg.Economy', berth);    %  This works in Package 
  Traveller = javaObject (' pkg.Economy', berth);  % This works in both java packages

Managing Memory Limitations:

Java Virtual Machine is usually created by the package so as to implement or run the java code. The good thing about Java Virtual Machine has the potential to provide with a good fixed amount of memory. This may also expand to a good memory limit whose default values usually have the dependency on version of Java.

We can always go ahead and specify the options in java package so as to create the Java Virtual Machine. This is usually done within the file which is known by the name of java.opts. This is nothing but a text file where one can go and input the lines that contains -X and -D options which is used to hand over to the Java Virtual Machine at the time of initialization of the same.

Java options need to be reside in the java in the directory with the path as javaclasspath.m . This is the path where package installation directory is present. This looks something like...\share\packages\java-1.2.8. The directory can also be located with the help of execution of pkg list.

The -X options has the ability to permit the expansion of maximum amount of memory that is available to the Java Virtual Machine. This value is 256 Megabytes and is achieved by incorporating the below line:

Listing 6: Using –X options

File: java.opt

The maximum possible amount of memory that can be made available is dependent on your system. On a Windows system that is available with 2 GB main memory, the objective must be to set this possibly to 1 GB.

Listing 7: Windows system memory

File: java.opt

The purpose of the D-options is making it use so as to specify the properties of the system. This can further be used by classes of java within with the package. In order to fetch the properties of the system, getProperty() methods can be used. Follow the below to understand further on the same. This assigns it the string 17.34 -DMyPrp=17.34

The property value of the same can be fetched as a string. This is done by a Java object or in Package:

Listing 8: Using D-options

pkg> javaMethod("java.lang.System", "getProperty");
  ans = 17.34

Installing and Uninstalling Java Packages

Below command is used to validate if the packages is already installed:

Listing 9: Command to validate the installation of the package

pkg> package list

And in case you get to see the java package installed, this needs to be uninstalled first. Below is the command used:

Listing 10: Command to uninstall the package

package> pkg uninstall
pkg> package list

We need to exit and again start the package now in case the same is used in the current session. This is required to be done before the package is uninstalled so as to make the system keep hold of good number of libraries in memory post loading of the same.

At the time of the installation process, backslashes are not recommended. It is always good to use the ordinary ones while configuring the environment .

The following path must be followed so that the proper installation can be done. Follow the below path for installation on Windows.

pkg > env ("JAVA_HOME", "C:/jdk1.6.0_33");

Looking at the Linux system, the below code elaborates more on this.

pkg > env ("JAVA_HOME", "/local/jdk1.6.0_33");

javac ,the java executables must reside in the path and talking about the Linux Environment, they are linked to from /bin. However when we talk about the Windows operating system, the case does not match with the Linux environment.

  • pkg > system ('javac -version 2') does not gives back zero which means that this command is not capable to give back the following command.
  • pkg > env ("PATH", [ JAVA_HOME getenv("PATH") ])

Execution and installation of the Java Package:

We need to get the package installed: -Wl,--kill,-at the $(MKTFILE)

In case you have a system that is of 64-bit systems, you may find some of the files that are required to be compiled in the location <JAVA_HOME>/jre/server/. This is on contrary to the location /jre/client/ This will however result in bugs for the reason that the script that is installed do not have the potential to locate the required files where they are expected to be.

Validating the installation of Java Package

Below lists the code that is used to create a Java string object: This is on its own used to convert to a Package string:

Listing 11: Creating a Java string object

pkg > s = javaObject ("java.lang.String", "Hello String")
  s = Hello String

Sample Output:

Folder Sctructure

Figure 1: Folder Sctructure


This brings us end to this tutorial where we witnessed the working of java packages in detail. See you next time.

Software developer with more than 5 years of development on Java, HTML, CSS.

What did you think of this post?
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually – in this case the price for this post is US$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits – in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!

> More info about MrBool Credits
You must be logged to download.

Click here to login