Tuesday, September 12, 2017

Book - Core Java for Impatiens - Chapter 2 - Object Oriented Programming

* It is a good idea to run javac with the -d option. Then the class files are generated in a separate directory, without cluttering up the source tree, and they have the correct subdirectory structure

*By default, JAR files use the ZIP format. There is also an option for another compression scheme, called “pack200,” that is designed to compress class files more efficiently

*You can use JAR files to package a program, not just a library. Generate
the JAR file with jar cvfe program.jar com.mycompany.MainClass com/mycompany/*.class
Then run the program as  java -jar program.jar

*The javac and java programs have an option -classpath, which you can abbreviate
to -cp. For example,
java -classpath .:../libs/lib1.jar:../libs/lib2.jar com.mycompany.MainClass
This class path has three elements: the current directory (.), and two JAR files in
the directory ../libs.

*In Windows, use semicolons instead of colons to separate the path elements:
java -classpath .;..\libs\lib1.jar;..\libs\lib2.jar com.mycompany.MainClass

*If you have many JAR files, put them all in a directory and use a wildcard to
include them all:
java -classpath .:../libs/\* com.mycompany.MainClass

*Since the warningString variable is not private, the methods of all classes in the java.awt package can access it. Actually, no method other than those of the Window class itself does that, so it seems likely that the programmer simply forgot the private modifier.
This can be a security issue because packages are open ended. Any class can add itself to a package by providing the appropriate package statement.
The Java implementors protect themselves from such an attack by rigging the ClassLoader class so it will not load any class whose fully qualified name starts with java.
If you want to have a similar protection for your own packages, you need place them into a sealed JAR file. Provide a manifest, a plain text file containing entries
Name: com/mycompany/util/
Sealed: true
Name: com/mycompany/misc/
Sealed: true
Then run the jar command like this:
jar cvfm library.jar manifest.txt com/mycompany/*/*.class

* Static Import : A form of the import statement permits the importing of static methods and
variables. For example, if you add the directive
import static java.lang.Math.*;

*You cannot import static methods or fields from a class in the default package.

In order to buy book : Core Java for Impatiens



No comments:

Post a Comment

Thank you for your comment!