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
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.
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});
C:/java_files/classes.jar
pkg > disp (p{2});
C:/java_files/classes.jar
pkg > % First element removal from classpath
pkg > javarmpath ([base_path, "/classes.jar"]);
package> p = javaclasspath;
package> disp (p{1});
C:/java_files/moreclasses.jar
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
else
Traveller = javaObject (' pkg.Economy', berth); % This works in both java packages
EndJava 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 -Xm256m
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 -Xm64m
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.34Below 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.
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.
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
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.







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