But really, oh:
Download J2SE 6.0
Posted by daniel on November 16, 2004 at 7:57 AM | Comments (0)
No, really, we mean it.
The brand new java.net "Mustang" Snapshot Releases are perfect for you. These snapshots give developers access to the latest features and fixes made to the J2SE 6.0 release. Whether you choose to download the binaries or the source code, be aware that these early releases are only lightly tested before being made available so if you are risk averse or inexperienced, these snapshot releases should be avoided. If you live for adventure, join us on the cutting edge.
The Mustang snapshot news leads off today's Weblogs. Mark Rheinhold explains that this is Another experiment in openness. Building on the success of releasing the Tiger Snapshots, they will be releasing Mustang starting with build twelve. In addition, "For the first time ever we ' re shipping source bundles for a J2SE release while it's under active development (gulp). This should make it easier for interested developers to contribute to the release as it evolves. "The hope is that soon there will be" a streamlined process for patch submission so that you can send code directly to real live JDK engineers rather than paste it into a bug report, cross your fingers, and hope for the best. a streamlined process for patch submission so that you can send code directly to real live JDK engineers rather than paste it into a bug report, cross your fingers, and hope for the best. "
This is a big deal. I'm sure you can say "but why didn't you …" or "it's not …" but, in my opinion, this is a huge step. Mark also asks for you to submit ideas on how the process can be improved. Finally, anticipating some obvious feedback, Mark notes that "The source bundles are covered by the Java Research License. The JRL is, to my non-lawyerly brain, a big improvement over the old SCSL license - for one thing, I can understand it! The JRL also gives developers and researchers more flexibility than SCSL did, though it's still not an actual open source license in OSI terms (sorry). "
Jdk, j2ee, j2se, j2me distinction between the concept of
JDK is Java development toolkit, the Java equivalent is the function is compiled, running java procedure kits.
J2EE is the Java 2 enterprise edition is a Java Enterprise Edition for enterprise-level applications development
J2SE is the Java 2 standard edition is the standard version of Java, the standard for application development
J2ME is the Java 2 Micro Edition is the Java Micro Edition, used in the development of mobile phone
J2EE, J2SE, J2ME java is different to the use of the different services, that is, providing different types of libraries.
Enterprise network applications J2EE (Java 2 Enterprise Edition), in view of the ordinary PC applications J2SE (Java 2 Standard Edition) and
For embedded equipment and consumer electrical appliances J2ME (Java 2 Micro Edition) version 3 for beginners are from the start of J2SE.
2. J2ee and j2se distinction:
J2ee in j2se added on the basis of a series of enterprise-level application programming interface. J2ee contains a lot of technology! Of which you are familiar with the jsp,
Servlet, jdbc, jme 13 in the technology!
J2ee is mainly used for B / S applications! That is a browser-based and server!
J2se I feel only needs a sufficient containers, j2ee components can be distributed at the same time support the existence of a number of containers
1, J2EE in the end?
J2EE, the sun is a standard proposed by the company, to meet this standard products called the "realization" of the sun in which you download the j2ee development kits out of a
Such "realization" and jboss, weblogic, websphere j2ee standards are a "realization." As jboss, weblogic,
Websphere itself with j2ee the api, we can not use the sun to achieve j2ee.
2, j2ee sdk the distinction between fact and j2sdkee you can j2ee sdk and j2sdkee as it is one thing, the official name for j2ee sdk. But if you carefully analyzed, can also use the following
Law to understand: j2eesdk is jdk, this is the development ejg must be installed, j2sdkee is j2ee development environment, this is to install, in fact, if
Jboss you installed, it would not install j2sdkee all, as long as one of the documents entitled j2ee can reproduce the past, that is to say
Is jdk must be installed, and j2sdkee do not need to see what you do with the vessel.
3, contained a j2ee sdk also equipped j2se sdk?
In the sun J2ee1.4 the website, there are two download package:
J2ee1.4 sdk is a complete package (all in one), including j2ee server, j2se, sample, api doc; j2ee seems to contain almost by j2se
Have things. J2ee, I do have a jdk, and the following lib j2se below lib as big (the same version), but not as big jre because j2ee than
J2se many more, such as java.servlet .*, such as java.servlet.http .*.
J2ee is to allow you to develop j2ee specification things. If it is used for web servers, with j2ee also, as long as you installed a jre (even
J2se do not have installed), plus a servlet engines (such as tomcat) would suffice.
Below this view, at a glance:
J2se == == jdk bin + + include demo jre + + + src.rar lib / / SUN official jdk1.4.2
J2ee …. == jdk + / / jdk here and the above documents not only jre as big, why have already said.
Another is a separate j2ee server, the need to be installed before installation j2se sdk.
No matter which, after the completion of the installation, should establish java_home, j2ee_home, classpath environment variables, j2ee server can be running again.
In order to facilitate the development, the Sun Java divided into J2SE (Java 2 Standard Edition), J2EE (Java 2 Enterprise Edition), J2ME (Java 2 Micro Edition) and Java Card platform four. J2SE Java technology is the basis of all, regardless of what developers to develop Java applications platform, we must first learn J2SE. J2EE technology focused on enterprise server-side applications. J2ME mainly for embedded systems, including mobile phone, PDA, etc.. For the development of mobile applications, Sun also offers free J2ME Wireless Toolkit. Java Card technology can be used to develop smart card IC implantation in the application.
Above four platform software development kit (Software Development Kit, SDK) is free and can be downloaded from Sun's Web site. Of course, it would be used only SDK no attention, we need to develop tools to improve development efficiency. This tool is called Integrated Development Environment (Integrated Development Environment, IDE). Previously, Borland JBuilder and IBM Eclipse IDE two of the most favored Java programmers, and Sun's own IDE is unknown. After 2004, Sun placed its own IDE to an important position, and make efforts to promote NetBeans and Java Studio development. The former is written entirely in Java open-source tools, and the latter is the same weight as official development tools. Sun's development tools is root seedlings are red, Java programmers can finally bathed Sun (sunny) weather!
Java J2SE and cafes mainly dealing with, of course, will not skip J2ME and J2EE knowledge, it is worth looking forward to!
Notes (Annotations) in J2SE 5.0, it seems to me is the more significant new features. EJB 3.0 specification future will be full use of this feature to simplify Session Bean and Message-Driven Bean and EntityBean the definition and implementation.
Java is more or less the subject of the Notes. NET impact. This is not to say that Java did not comment, such as JavaDoc the previous mark, especially @ deprecated are notes, but this time the update will be pushed to the Java Notes unprecedented in the history of a high degree. Notes through, we can achieve the original function of the relative complexity of the senior.
Let us look at a practical example:
* Created on 2004-12-28
Import java.lang.annotation .*;
* @ Author Sean
(Public class MyAnnotations
@ MyAnnotationForMethods (
Index = 1,
Info = "This is a method to test MyAnnotation.",
Developer = "Somebody else"
Public void testMethod1 () (
/ / …
@ MySingleElementAnnotation ( "For instruction purpose only.")
@ MyAnnotationForMethods (
Index = 2,
Info = "This method is to show multiple annotations."
Public void testMethod2 () (
/ / …
@ Target (ElementType.METHOD)
@ Interface MyAnnotationForMethods (
Int index ();
String info ();
String developer () default "Sean GAO";
@ Interface MyEmptyAnnotation (
@ Interface MySingleElementAnnotation (
String value ();
In this example, I have defined three Notes: first MyAnnotationForMethods includes three members, namely index, info and developer, the developer a default value of "Sean GAO," in front of the @ Target (ElementType.METHOD) is Note that the comments shows that the method can only be used Notes second MyEmptyAnnotation is an empty Notes can be used as a marker, such as an earlier Serializable interface; MySingleElementAnnotation includes a third member of value, this is mandatory When there is only one element, we must use the name value, it can be the type of value, String, Class, enum, or the data types of one yuan array.
Notes interface similar to the definition, but they are used in the interface are significant differences. Specific reference I use the example cited above. Notes can be superimposed.
In practical application, is now more mature framework for some tests, as I said in a separate article in the translation prepared by the original author Cedric Beust TestNG. In the beginning of this article, I mentioned that in the future there will be EJB 3.0 specification in a considerable number of comments on the application, let us preview to the future with stateless session bean-like notes to the definition:
@ Stateless public class BookShelfManagerBean (
Public void addBook (Book aBook) (
/ / Business logic goes here …
Public Collection getAllBooks () (
/ / Business logic goes here …
/ / …
That's it. We do not even have to write any interface and deployment descriptors, how nice.
Notes relating to a more detailed explanation, refer here.
Nearly three years ago the design of one of the most significant updates to the Java platform in its history was planned. So what has happened in those three years? J2SE 1.5 ( "Tiger") has been developed through the Java Community Process (JCP) , and in addition to the 18 experts on the J2SE 1.5 JSR (JSR 176) there are an additional 15 component JSRs (see Table 1), each with their own domain experts. In addition to Java luminaries such as James Gosling and Graham Hamilton, over 160 Java experts worldwide have contributed to its design. The common goal was to make Java the best developer platform available, and I trust you will agree that we have listened very carefully to what the Java community wanted. Let's take a look at the information you need to get up to speed with J2SE 1.5, including code examples that you can run with the beta release that is available currently.
Although there are over 100 major features, the release is focused along certain key themes, namely, quality, ease of development, monitoring and manageability, performance and scalability, and desktop client. There are a few features that didn't fit neatly into the themes, and we'll look at those later.
Note that even if you do not change a single line of your existing application there are many features in J2SE 1.5 that you can take advantage of by just migrating to the new release. Be sure to try out the new beta, run your existing code, and then try some of the great new language features.
Language Changes and More
Perhaps the most talked about features in this release are the new Java language changes. Some of these changes have been covered in detail in several recent Java Pro articles. However, the ease of development theme covers much more than the Java language updates. There are other changes to make it easier for developer tools to work with the Java platform and also a whole new locking and threading framework.
The javac compiler uses the 1.5 language features by default. To use any of the examples you see here with the beta 1 release, you will need to add the option-source 1.5 when using the javac compiler:
Javac-source 1.5 Hello.java
The primary ease of development changes and the respective JSR in which they were developed are shown in Table 2. Arguably, the most significant language change delivered with J2SE 1.5 is the introduction of Generic types. Generic types provide the ability for API designers to create common code that can be used with any Java reference type and yet can be checked for type safety at compile time. The Collections API is a good example of an API that can benefit from Generic types and has already been updated in the 1.5 release. In addition , any APIs that call the Collection API inside the core platform have also been retrofitted with a Generic signature, along with the Class API. To see Generics types in action, consider this ArrayList example that uses the 1.4.2 release:
ArrayList list = new ArrayList (); list.add (0, "User1"); String firstuser = (String) list.get (0);
The last statement casts the object returned from the ArrayList to a String. This cast is required because the Collections API stores the ArrayList elements as Java objects. However, if somewhere in our application we also made a call to list.add (0, new StringBuffer ()), the compiler will accept this type as it is a valid Java object. Only when the program is run, the error is detected. The call to return the first element would retrieve a StringBuffer object instead, and this mis-mismatch would generate a ClassCastException at runtime. The same example with the generified Collections library is written:
ArrayList <String> list = new ArrayList <String> (); list.add (0, "User1"); String firstuser = list.get (0);
To use an API that has been generified requires supplying the type using the <> notation to both sides of the declaration as shown for ArrayList and then removing any casts. If we now try to compile the same example and supply the faulty code, list. add (0, new StringBuffer ()) the javac compiler will now generate an error.
Unlike C + + templates, the javac compiler only needs to create one generic class to represent any type used; C + + on the other hand creates one file per type used. It does this by removing the type information when storing the new generic class, called type erasure . This feature provides compatibility with previous APIs. However, the downside is that mixing and matching nongeneric and generic code has to be done very carefully; otherwise, the nongeneric mode is used. To generify your own APIs, check the Generics tutorial or look through the Collections API source (see Resources).
Convert Primitive Types
The Java language contains a small number of types like int and float that are not objects. One of the primary reasons these primitive types exist is for improved performance. However, when using an object-centric API like the Collections API, the onus is on the developer to convert the primitive type to an object and then convert it back again.
Autoboxing - With the new autoboxing feature the javac compiler generates the extra code necessary to convert from the primitive type, and with auto-unboxing converts the object back into its primitive type. This example shows an Integer object being stored using the generic Collections API, first with the 1.4.2 libraries:
Vector v = new Vector (); v.add (new Integer (7)); int first = ((Integer) v.get (0)). IntValue ();
And then with the 1.5 release:
Vector <Integer> v = new Vector <Integer> (); v.add (7); = int first v.get (0);
Enhanced for loop - The enhanced for loop feature reduces the extra coding required when stepping through a Collection. Stepping through a Collection often requires the use of an Iterator. The 1.4.2 version again is first, and it should look very familiar to Collection API users:
Vector v = new Vector (); for (Iterator i = v.iterator (); i.hasNext ()) (Integer value = (Integer) i.next (); System.out.println ( "value =" + value);)
The enhanced for loop uses the: character to identify that this is a special for statement. The element is retrieved from the Collection without us needing to declare an Iterator, as the javac compiler does the work behind the scenes. The same example using J2SE 1.5 and with Generic types is:
Vector <Integer> v = new Vector <Integer> (); for (Integer value: v) (System.out.println ( "value =" + value);)
Enumerated types - The enum keyword uses a special class to represent enumerated types. The new enumerated type is type safe, which means values outside that set are rejected at compile time. This example creates a type called Medal that only accepts values of Gold, Silver , and Bronze. It would reject a Medal of value 4, something that is difficult to prevent when using static final constants:
(Public enum Medal Gold, Silver, Bronze Medal winner); switch (winner) (case Gold: System.out.println ( "play anthem");)
Static import - The static import feature enables you to refer to static constants from a class or interface without needing to inherit from it. Instead of BorderLayout.CENTER, each time we add a component you can simply refer to CENTER:
Import static java.awt.BorderLayout .*; getContentPane (). Add (new JPanel (), CENTER);
There is another smaller ease of development change in this release as you no longer need to repeatedly call getContentPane () with Swing components. That line can be written simply as:
Add (new JPanel (), CENTER);
Metadata - The metadata feature in J2SE 1.5 provides the ability to associate additional data alongside Java packages, classes, interfaces, methods, and fields. The javac compiler or other tools can read this additional data, or annotations, and depending on configuration can also be stored in the class file and discovered at runtime using the Java reflection API.
It is anticipated that Metadata will be used to reduce the amount of repetitive or boilerplate coding, and also provide assistance in using deployment descriptors. For most developers the exposure to Metadata will only be through predefined Metadata tags; development and deployment tools will do the processing .
APT, the annotation processing tool available in beta 2 provides a framework for identification and processing of metadata tags. The code example in Listing 1 creates a Metadata annotation to store release information that is then simply displayed at runtime.
Now let's look at an example of the type of code generation that could be achieved using metadata processing tools. The interface source in this JAX-RPC server could be generated automatically by a metadata processing tool that has a rule for the tag @ remote without metadata :
Public interface HelloIF extends Remote (public String sayHello (String s) throws RemoteException;) public class HelloImpl implements HelloIF (public String sayHello (String s) (return "Hello" + s;))
Or reduced code with metadata:
Public class HelloImpl @ (public remote String sayHello (String s) (return "Hello" + s;))
When porting legacy code to the Java platform, one of the more laborious changes is to convert printf style output to the println concatenation style of output. Developers now have the option of using printf-type functionality to generate formatted output. When porting code, the C-style format strings should work the same with the printf formatter; however, even though using the \ n character is supported on Unix platforms for true cross-platform newline support, the% n character should be used:
System.out.printf ( "User-8s score%% n% d", "duke", 10);
The scanner API provides basic input functionality. To read simple input from standard input or any other stream requires calling a next () method from the Scanner API. The action for next () is to block if no data is available. There are also some complex pattern matching algorithms:
Scanner s = Scanner.create (System.in); int i = sc.nextInt (); / / Read an / / (String s1 = integertry s.next (Pattern.compile ( "[Yy ]")); / / only match Y or y) catch (InputMismatchException e) (System.out.println ( "Expected Y or y");) s.close ();
Varargs allows multiple arguments to be passed as parameters to methods. … It requires the simple notation and internally is used to implement the flexible number of arguments required for printf:
Void argtest (String … vargs) (for (int i = 0; i <vargs.length; i + +) (System.out.println (vargs [i]);)) argtest ( "arg1", "arg2") ;
The concurrency utility library is based on a popular package from Doug Lea that has been standardized in JSR 166. It provides many useful APIs and tools for writing safer multithreaded code. The APIs include a thread executor task that can be used for managing threads, as well as a range of locks, like the Semaphore; timers; and other synchronization primitives. The JSR also delivers a nanosecond timer, java.lang.System.nanoTime (), for platforms that support that granularity.
A simple example is the atomic lock, which guarantees that when retrieving a value and setting it - sometimes called test and set-the value does not change in the meantime. This example uses the new AtomicInteger class that protects the balance value when updating it:
AtomicInteger balance = new AtomicInteger (10); System.out.println (balance.getAndAdd (10));
At Your Request
One of the most requested features I hear from the Java community is to improve startup time. Along with the streamlined class loading and reducing startup bottlenecks, this release also introduces class-data sharing in the Hotspot Java Virtual Machine (JVM). This technology shares read-only class data between multiple running JVMs, which not only can reduce the memory footprint of multiple JVMs but also improves startup time as core JVM classes are prepacked.
Performance ergonomics are a new feature in J2SE 1.5, which means that if you have been using specialized JVM run-time options in previous releases it may be worth re-validating your application performance with no or minimal options.
Another popular feature request for J2SE 1.5 is to improve the monitoring and manageability of the JVM, and in particular, the ability to detect low-memory conditions. Internal data from the JVM, like thread information and memory, is available for publication through the JMX API (JSR 003) interface. The published data is also available through the JMX remote interface (JSR 160) and can be monitored using the SNMP protocol. Not only can you view this information, but the framework provides a way to also manage or set values-for example, changing the logging level dynamically. Probably the most useful property to monitor is the low-memory threshold. The threshold can be customized for each JVM, and an SNMP trap or JMX notification can be sent when the threshold is exceeded, allowing an administrator to bring more machines online to share the load.
To enable a JVM to be monitored using the standard SNMP ports in the beta 2 release, modify the management.properties file, or supply these options at runtime:
Java-Dcom.sun.management.snmp. Acl = false-Dcom.sun.management. Snmp.port = 161-Dcom.sun. Management.snmp.trap = 162-Dcom. Sun.management.snmp.acl = false — jar Java2Demo.jar
You can enable the JMX MBeanServer in a similar manner:
Java-Dcom.sun.management. Jmxremote.authenticate = alse-Dcom. Sun.management.jmxremote.port = 5001-Dcom.sun.management. Jmxremote.ssl = false-jar Java2Demo.jar
Most of the native monitoring functionality has been implemented using jvmti. This API has been specified through JSR 163, enables improved performance analysis, and will replace jvmpi. The API also provides the ability to use bytecode instrumentation to enable tools to add additional profiling only where it is needed, including at runtime. Although it is possible to write your own jvmti server, the main benefit will be enhanced developer tools.
Generating a stack trace from an embedded JVM or from a JVM that doesn't have a console has never been easy. You can now call Thread.getAllStackTraces () to generate a list of all stack frames from within your application. Alternatively, you can request a stack trace of the current thread and parse each element in sequence:
StackTraceElement e  = Thread.currentThread (). GetStackTrace (); for (int i = 0; i <e.length; i + +) (System.out.println (e [i]);)
In the rare case that the JVM aborts you can configure it to call your own error handler program:
- XX: OnError = "command" optional% p used as process id-XX: OnError = "pmap% p"-XX: OnError = "% p gdb"
In addition, by using the JDI serviceability bridge you can even attach a java debugger tool, such as jdb, to a core file or hung JVM process. To connect to a core file on Linux and debug Java methods, use:
Jdb-server-connect sun.jvm.hotspot.jdi. SACoreAttachingConnector: javaExecutable = / usr/java/j2sdk1.5.0/bin/java
Look and Feel
The Java Desktop client is one of the key themes of the release and has been the subject of many improvements in this release. I mentioned improved startup time and memory footprint earlier. Desktop developers also asked for updates to the cross-platform Look and Feel, and the release includes the fresh new Ocean Look and Feel (see Figure 1) and further improvements in the native GTK skinnable Look and Feel and Windows XP Look and Feel.
If you have the latest OpenGL drivers, you can now use native hardware acceleration for any Swing application by using this run-time property:
Java-Dsun.java2d.opengl = true-jar Java2D.jar
The Linux release now uses a new windowing toolkit based on X11 instead of motif. This toolkit is faster and also provides better drag and drop and clipboard interoperability. To enable this toolkit on Solaris, set the toolkit system property:
Java-Dawt.toolkit = sun.awt.X11.XToolkit-jar Notepad.jar
J2SE 1.5 provides the foundation XML support to J2EE and also the Java Web Services Developer Pack. JAXP 1.3 (JSR 206) introduces XML 1.1 along with SAX 2.0.2, XLST and DOM Level3. In addition to tracking the latest W3C specifications these updates bring faster XML processing.
Unicode 4.0 support includes 32-bit surrogate character support. Surrogate characters are encoded as a special pair of UTF16 values to generate a different character, or codepoint. A surrogate pair is a combination of a high UTF16 value and a following low UTF16 value.
The approach taken by the Unicode organization to support these additional characters lends itself to a similar approach taken by the Supplementary Character API (JSR 204). As the Java char is also 16 bits, the core APIs have been updated to handle two chars together. In a few cases an additional method that takes an int type has been added for methods that only took a char as an argument. However, for most users the change will be transparent.
JSR 200 introduces a JAR file compression technology that can be used to dramatically shrink JAR files for network transmission. This compression and inflation can be achieved programmatically by using the javax.pack.Pack200 class. In addition, for simple downloads, you can use the stand-alone tools pack200 and unpack200. The pack200 command creates a compressed JAR file called charsets.pack.gz from charsets.jar. As part of the compression process the JAR file is deconstructed and reassembled; for this reason signed JARs should be initially prepared - with the repack option. In this example, the charset.jar file is repackaged and gzip compressed into the file charsets.pack.gz:
Pack200-v charsets.pack.gz charsets.jar
To unpack the transferred charsets.pack.gz back into the charsets.jar file, use the unpack200 command with the arguments in the same order:
Unpack200 charsets.pack.gz charsets.jar
In this case the original JAR file, which is available in the JRE, is originally 8.61 MB, and using a normal compression tool would reduce the size to 419 MB. With the new pack tool this size can be further reduced by default to 1.69 MB , which is 80 percent smaller than the original size.
Finally, JDBC rowsets were originally introduced in J2SE 1.4, and J2SE 1.5 introduces a disconnected CachedRowSet and WebRowSet implementations. The CachedRowSet contains an in-memory collection of rows retrieved from the database. The connection to the database is managed by the RowSet API and simply needs information about the datasource or database connection details. The rowset can then be updated without tying up database connection resources, and then it can be resynced at a later time. The WebRowSet is an extension to the CachedRowSet that can also import and export an XML representation of the database rowSet (see Listing 2).
We've only covered some of the larger features in the J2SE 1.5 beta release here. There are over 100 features, but there are many smaller updates and bug fixes. Try the beta release with your own applications, and see the improvements firsthand.
Read. NET may be based on the packing friends and uncrating is no stranger to the concept. First, we must be clear that, in Java, there are two different data types: value types and reference types. Value types of data not object, the result of memory and resources are relatively small, but not as an object called its toString (), hashCode (), getClass (), equals (), etc., should not be added directly to the pool; quoted data is a type of a target, taking up memory and more resources, but provides a wealth of access methods, at the same time as the real object, can be directly Add pool.
The so-called packing is to type with their relative values should be used types of packages, so that they can have the characteristics of objects, such as we can into the int type Integer type of packaging object, or to Double-double packaging, and so on.
The so-called entitlements, is packed with the opposite direction, Integer and Double application of this type of object to simplify the value types of data.
Published in J2SE 5.0, we can only deal with the manual packing and uncrating, and now, the compiler can automatically help us to complete the necessary steps. I offer the following code two versions of the crating and uncrating, and the use of a version of the manual, put another version of these obvious to the compiler code to accomplish:
Public static void manualBoxingUnboxing (int i) (
ArrayList <Integer> aList = new ArrayList <Integer> ();
AList.add (0, new Integer (i));
Int a = aList.get (0). IntValue ();
System.out.println ( "The value of i is the" + a);
Public static void autoBoxingUnboxing (int i) (
ArrayList <Integer> aList = new ArrayList <Integer> ();
AList.add (0, i);
Int a = aList.get (0);
System.out.println ( "The value of i is the" + a);
See it in J2SE 5.0, we no longer need to be explicit to a value of the types of data into corresponding object to it as an object to other methods, there is no manual that will be representative of a numerical target uncrating value for the corresponding data types. Of course, there are a number of issues that must be done: the type and value of type used in the occupation of resources, there is still a clear distinction in the use of this convenient at the same time, do not forget the simple nature of their differences.
J2SE 5.0 of the automatic packing and uncrating detail, refer here.
J2SE 5.0 introduced here in three of the more important characteristics: enumerated types, annotation types, Norm.
J2SE 5.0 (Tiger) is the release of the Java language history of the development of an important milestone in the Java programming is so far achieved by the greatest progress.
J2SE 5.0 offers many exciting features. These features include Fan-(generics) support enumerated types (enumeration) support, metadata (metadata) support, automatic uncrating (unboxing) / packing (autoboxing ), the number of variable parameters (varargs), static import (static imports), and a new thread architecture (Thread framework).
1. Enumerated types
J2SE 5.0 and JDK before there are two basic ways to define new types: Classes and Interface. For most object-oriented programming,
These two methods may seem sufficient, but in some exceptional circumstances, these methods is not suitable, for example, we would like to define a type of Priority, it can only access
By the High, Medium, Low three values. Any other value is illegal. J2SE before JDK 5.0 is of this type can be constructed, but a lot of work needs to be done,
May bring such as unsafe (type security issues??), And other potential problems, and J2SE 5.0 enumerated types (Enum) can avoid these problems.
(Public enum Priority High, Medium, Low);
It includes a enum keyword, a new enumerated types, as well as the names of Priority Priority for the definition of a group of values.
2. Type Notes
J2SE 5.0 offers many new features. One of the very important characteristics, is the metadata (Metadata) support. In J2SE5.0, such metadata called
Note (Annotation). Through the use of notes, developers can not change the original logic of the situation, embedded in the source file some additional information. Code Analysis
Tools, development tools and deployment tools through which additional information can be verified or deployment. For example, for instance, you want the parameters of a method or return
Value not empty, although we can be described in the Java doc, but express the same meaning that there are many, such as "The return value should not be
Null "or" null is not allowed here. "It is very difficult under these testing tools to analyze language programmers expect a prerequisite (Pre-condition) and the bailiffs
Conditions after the (Post-condition). And the use of Notes (Annotation), this problem can be easy to solve.
J2SE5.0 support the user's own definition of the Notes. Notes definition is very simple, Notes @ Interface is the keyword to the statement. For example, the following is one of the most simple injection
Public @ interface TODO ()
Note the use of markers
@ SingleValueAnnotation ( "some value")
@ MultipleValueAnnotation (
Key1 = value1,
Key2 = value2,
Key3 = value3,
In the proceedings can not only use their own definition of the Notes may also be used in the built-in Notes J2SE5.0 type. J2SE 5.0 in the pre-defined three types Remarks:
Override: java.lang.Override said that the current method of rewriting the category of a father, if the father of the corresponding method does not exist, there will be compiled wrong
Deprecated: java.lang.Deprecated that does not encourage the use of the current method or variable domain.
SuppressWarnings: java.lang.SuppressWarnings closed compiler warning, so that the 1.5 compiler before the code, not a large number to do
Alarm unrelated to the heart.
It is worth noting that J2SE5.0 also offers four types of Notes for the Notes. Have the following four:
1. Target: These are used to specify the Notes (Annotation) is the definition of what type. For example, this type of method may only be defined. Than
If override, which can not be modified to override @ class or field.
2.Retention: Retention of the strategy can choose from the following three:
RetentionPolicy.SOURCE: compile after class file will be removed from the Notes (Annotation).
Retention.CLASS: Note (Annotation) remain in the class file, but does not deal with VM.
RetentionPolicy.RUNTIME,: Note (Annotation) remain in the class file, VM will be dealt with.
Please note that if you want to find in the running of these notes were used in what must be the definition of the Notes, RetentionPolicy.RUNTIME choice,
Otherwise, even if you use Notes-like variables or modified, in the run-time can do receive this information.
3.Documented: This Note (Annotation) will be part of public API.
4.Inherited: Suppose Note (Annotation) definition of the use of the Inherited, and if this Note (Annotation) modification of a class,
A kind of sub-category has been the Notes (Annotation) modified.
Summary of the so-called meta-data, which is information on the information. Generally speaking, the code analysis tools, testing tools or deployment tools will be used to produce metadata configuration information as well as
Configuration information generated by control logic. These tools usually use the reflective properties of Java, remodeling metadata information, and such information to explain.
New technologies will continue to change the procedures for the design and development of the design concept. So Note (Annotation) bring to us? Only in the code analysis, or
Is the framework of development and testing and deployment framework will use the time? In our application of the full use of meta-data, the software can improve the quality and maintainability.
3. Fan -
J2SE 5.0 is the most significant change is the addition of one of the generic types of support. J2SE 1.4, as well as in the previous version, Java is not the type of security procedures. Cases
For example, Collection framework defined in the List, Map of containers such as Object types are elements that contain elements of this type is Object object. Use of this
A list of ways to achieve, can be used to operate integer, real, string or any object type. Such as
List stringList = new ArrayList ();
StringList.add ( "abcde");
String str = (String) stringList.get (0);
This method need to use a list of mandatory conversion (also known as the show modeling), it is not type safe. Above this kind of code, although the variable name
StringList for, but we can still object to an integer add to the queue, for example,
StringList.add (new Integer (5));
In such circumstances, access to the list of characters from the object, the mandatory conversion will lead to abnormal operation.
Fan-type security into Java is an important step for the use of norm-types can be constructed security code.
Refers to the so-called Fan-type parameter (parameterized types). Java is a type of strong language, J2SE 1.4, as well as in the previous version, we have a definition
A Java class, or interface methods, must designate the type of a variable. Sound in the Fan-type, or function interface, the definition of the variables do not specify a certain time variables
Specific types, but instead of using a type parameter. In the use of this class, interface, or method, the parameters of this type from a specific type of substitute.
The following examples on how to create one of the most simple types Fan
Public class GenSample <T> ()
Behind with a class name <T> that this is the norm types, which are a type parameter T (type parameter), in the use of the Fan-time, type parameter can be replaced
For any type of categories, but it is not the original type (primitive type), for example, int, double.
Below through a list of examples to specify if the sound Fan-type parameters and the type of usage.
(Public class GenList <T>
Private T  elements;
Private int size = 0;
Private int length = 0;
Public GenList (int size) (
Elements = (T ) new Object [size];
This.size = size;
Public T get (int i) (
If (i <length) (
Return elements [i];
Public void add (T e) (
If (length <size - 1)
Elements [length + +] = e;
In the list of examples, the type parameter T is used to that list the types of elements, that is, this list is the element of the T type.
In the use of this list, this type parameters T will be replaced by the specific type.
Note that when the type parameter T is not specific category, it is not using the new operator to create T targets, such as the new T (), or new T .
In J2SE 5.0, not only can be FAN-type sound, the sound Fan can also interface, Interface-Harmony sound Fan Fan-type syntax similar to the interface is also said life behind
Add <T>, for example,
(Public interface GenInterface <T>
Void func (T t);
Fan-type sound in time, but the use of many types of parameters. Various types of parameters with a comma separated, for example,
Public class GenMap <T, V> ()
Fan-J2SE 5.0 is to provide a robust set of features, the use of norm-can create type-safe, reusable code, although the Fan-also Java and C + + can not be the norm-par, but with the Java language ability Evolution, Fan type in the Java language will play a greater role.
Using Java 2 Standard Edition (J2SE) 1.4 programming for Internet security
Part I: server-side
Qusay H. Mahmoud of
November 2002 madman translation Border Town
Any computer networks or the Internet to transmit information can be intercepted, many of whom are some of the more sensitive content, such as credit card numbers or other personal data. In order to better the business environment in the use of Internet and e-commerce, application software must use encryption, authentication and security of the communication protocol to protect the user's data security. Safety hypertext transfer protocol (secure Hypertext Transfer Protocol, HTTPS) is built on Secure Sockets Layer (Secure Sockets Layer, SSL), the HTTP, it has been successfully applied to e-commerce.
Java Secure Sockets expansion (Java Secure Socket Extension, JSSE) to enable Internet communications security to become a reality. It is 100% Pure Java Implementation of SSL framework. This package let Java developers to develop secure network application based on TCP / IP applications Ho agreements, such as HTTP, FTP, Telnet, or NTTP, in the client and server-side security established between the data channel.
JSSE has been integrated into the Java 2 SDK Standard Edition 1.4 (J2SE 1.4), and this is really a good news. This means that if you install the J2SE 1.4, do not need to download the other packages, you can create SSL-based Internet application procedure. A total of this series of two articles, it is one on the market for the future development of the Interent safety manual. This article is mainly for the server-side, and under the stress of a client. SSL overview article from the beginning, and then tell you how to proceed with the following:
- JSSE use of the API
- In your C / S applications in combination with JSSE
- The development of a simple HTTP server
- Let HTTP server will be able to handle HTTPS request
- Included in the J2SE used in the keytool generate their own certificates
- Development, deployment and operation of a secure HTTP server
Netscape SSL protocol is developed in the 1994's to allow server (such as the typical browser), and HTTP server can connect to the communications security. It encryption, authentication source, such as support for data integrity, in order to protect the public in an unsafe network exchange data. SSL have these versions: SSL 2.0 are potential safety problems, now has several on No; SSL 3.0 applications are more widely; Finally, the SSL 3.0 from improved transport layer encryption (Transport Layer Security, TLS) has become Internet standards and used in almost all new software.
In the data transmission, data encryption technology will be adopted into the content seems senseless not to protect the illegal use of the data. The procedure is: data at one end (client or server) is encrypted, transmission, then decrypted at the other end.
Source certification is to verify the identity of the sender of data approach. Browser or other client first attempt and a Web server on the security of communication links, the server will be information to a trust emerged in the form of certificates.
Certificate from the certification body the authority (CA) - the trusted authority to issue and verify. A certificate description of a person's public key. A signature of the document will be made following assurances: I certify that the documents belong to the public key documents in the name of the entity. Signature (authoritative certification organization). At present renowned authority certification body has Verisign, such as Entrust and Thawte. Attention is using SSL / TLS X.509 certificate is a certificate.
Data integrity is to ensure that data in the process of transmission has not been changed.
SSL and TCP / IP protocol level
SSL is truly Secure Sockets Layer. Its connection movements and similar TCP connections, so you can imagine SSL connection is the safety of TCP connection, because the agreement hierarchical graph of the location of SSL is on the TCP in the application layer, as shown in Figure 1. Takes note of this very important point. However, SSL does not support TCP certain characteristics, such as the frequency of the data.
Figure 1: SSL, and TCP / IP protocol level
Can exchange encryption technology
SSL is one of the characteristics of e-commerce services to provide the exchange of encryption algorithm to provide technical standards and certification methods. SSL's developers recognize that not everyone will use the same client software, which not all clients will be included in any detail encryption algorithms. The server is the same. At the ends of the connecting client and server in the initial "handshake" when the need for an exchange of encryption and decryption algorithms (password). If they do not have enough common algorithm, the connection attempt will fail.
When the attention of SSL allows the client and server end mutual authentication, the practice is typical only in the server-side SSL layer verification. Client is often at the application level, transmission channel via SSL to protect the password for authentication. This model commonly used in the banking, stock trading and other security network applications.
SSL completely "handshake" agreement as shown in Figure 2. It features in the SSL "handshake" in the process of information exchange sequence.
Figure 2: SSL "handshake" agreement
The meaning of these messages are as follows:
- ClientHello: Send information to the server client, information, such as the SSL protocol versions, speaking group ID and password information, such as encryption algorithm and to be able to support the size of the keys.
- ServerHello: choosing the best group server password and send this information to the client. Password includes client and server support.
- Certificate: its public key server will contain a certificate sent to the client. This information is optional, and request certification on the server when it will be needed. In other words, the certificate for the server to the client to confirm the identity.
- Certificate Request: This news just in the server requests client authentication sent its own time. Most e-commerce applications on its own does not require a client.
- Server Key Exchange: if the certificate contains a public key server insufficient for key exchange, it sent the information.
- ServerHelloDone: This informed client, the server has completed the exchange of the initialization process.
- Certificate: only if the client requests the server to verify their own when sent.
- Client Key Exchage: client and server have a key share. If you use Rivest-Shamir-Adelman (RSA) encryption algorithm, the client will use the public key server encryption key will be sent to the server after. Servers use their own private key or key to decrypt the information be shared keys. Now, the client and server have a shared security key distribution.
- Certificate Verify: if the server requests verify client, the news server to allow completion of the verification process.
- Change Cipher Spec: Client server requests the use of encryption mode.
- Finished: Client server told it is ready for a secure communications.
- Change Cipher Spec: client server requests the use of encryption mode.
- Finished: client server told it is ready for a secure communications. This is the SSL "handshake" the outcome of the signs.
- Encrypted Data: client and server can now be developed in a safe communications channel for the exchange of information encryption.
Java Secure Sockets expansion (JSSE) provide a framework and a 100% Pure Java Implementation of SSL and TLS protocol. It provides data encryption, server authentication, and complete information optional client authentication mechanisms. JSSE is outside the food will be complex, the fundamental abstraction of the encryption algorithm, and thus reduce the risk of being sensitive to the safety or the risk of sexual assault. In addition, since it will be a seamless integration of SSL in the application of course, the security application development becomes very simple. JSSE framework can support many different security communication protocols, such as SSL 2.0 and 3.0 and TLS 1.0, but only realized J2SE v1.4.1 SSL 3.0 and TLS 1.0.
JSSE API provides a scalable network socket type, credit and key management, as well as to simplify the creation and design of the socket socket factory framework, this expansion of java. Security and java. Net two packets. These categories are included in java x.net and java x.net.ssl package.
SSLSocket and SSLServerSocket
Java x.net.ssl.SSLSocket is java. Net.Socket subclass, and he supports all standard Socket method, and some of Secure Sockets new approach. Classes and SSLSocket java x.net.ssl.SSLServerSocket similar category, it is used to create the server INTERLINKED son, and SSLSocket not.
Create a SSLSocket example of how two ways:
- SSLSocketFactory examples of the implementation of createSocket used method to create.
- Through the SSLServerSocket accept obtained.
SSLSocketFactory and SSLServerSocketFactory
Java x.net.ssl.SSLSocketFactory category is used to create the Secure Socket object factory. This is the java x.net.ssl.SSLServerSocketFactory factory, but it is used to create secure server socket.
Can be obtained through the following methods SSLSocketFactory examples:
- Executive SSLSocketFactory.getDefault obtained a default factory.
- Through specific configuration of constructing a new factory.
Pay attention to the default factory configured to allow only server authentication.
So that the existing Client / Server applications become safety
In the existing C / S applications integrated SSL security to enable them become relatively simple, use a few lines on JSSE code can be done. In order to become server security, the following examples show Canada and the content must be:
Import java. Io .*; import java x.net.ssl .*; public class Server (int port = portNumber; SSLServerSocket server; try SSLServerSocketFactory factory = ((SSLServerSocketFactory) SSLServerSocketFactory.getDefault (); server = (SSLServerSocket) factory. createServerSocket (portNumber); SSLSocket client = (SSLSocket) server.accept () / / Create input and output streams as usual / / send secure messages to client through the / / output stream / / receive secure messages from client through / / the input stream) catch (Exception e) ())
In order to become client security, the following examples show Canada and the content must be:
Import java. Io .*; import java x.net.ssl .*; public class Client (… try (SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault (); server = (SSLServerSocket) factory.createServerSocket (portNumber); SSLSocket client = (SSLSOcket) factory.createSocket (serverHost, port); / / Create input and output streams as usual / / send secure messages to server through the / / output stream receive secure / / messages from server through the input stream) catch (Exception e) ())
J2SE v1.4.1 and a JSSE providers, together SunJSSE release. SunJSSE installed and pre-registered Java encryption system. Please SunJSSE as a realization of the names to consider, it provides SSL v3.0 and the realization of TLS v1.0, also provided ordinary SSL and TLS password Group. If you want to find your realization (here SunJSSE) supported by the group password list can call the getSupportedCipherSuites SSLSocket methods. However, not all of these groups are available password. In order to find out who is available, call getEnabledCipherSuites methods. List setEnabledCipherSuites this method can be used to change.
A complete example
I found that the use of JSSE develop the most complex issues related to management of system settings, as well as certificates and keys. In this example, I demonstrated how to develop, deploy, and run a complete support GET request methods of HTTP server applications.
Hypertext Transfer Protocol (Hypertext Transfer Protocol, HTTP) is a "request - in response to the" Application Protocol. The agreement to support a fixed set of methods such as GET, POST, PUT, DELETE, etc.. GET method in general use request to the server resources. There are two GET request examples:
GET / HTTP/1.0 <empty-line>
GET / names.html HTTP/1.0 <empty-line>
Unsafe HTTP server
In order to develop an HTTP server, you must first carry out is how to understand the HTTP protocol work. This is a server only supports a simple GET request methods server. Code Example 1 is the realization of this example. This is a multi-threaded the HTTP server, ProcessConnection category for the implementation of different threads in the new request. When the server receives a request from the browser, it Analysis of this request and to identify necessary documents. If the requested documents available on the server, then the requested documents will be sent to the server shipDocument methods. If the requested documents did not open, then sent to the server is the wrong news.
Code Example 1: HttpServer. Java
Import java. Io .*; import java. Net .*; import java. Util.StringTokenizer; / ** * This class implements a multithreaded simple HTTP * server that supports the GET request method. * It listens on port 44, waits client requests, and serves documents * * / public class HttpServer (/ / The port number which the server / / will be listening on public static final int HTTP_PORT = 8080; public ServerSocket getServer () throws Exception (return new ServerSocket (HTTP_PORT); ) / / multi-threading - create a new connection / / for each request public void run () (ServerSocket listen; try (= getServer listen (); while (true) (listen.accept Socket client = (); ProcessConnection cc = new ProcessConnection (client);)) catch (Exception e) (System.out.println ( "Exception:" + e.getMessage ());)) / / main program public static void main (String argv ) throws Exception (HttpServer httpserver = new HttpServer (); httpserver.run ();)) (class ProcessConnection extends Thread Socket client; BufferedReader is; DataOutputStream os; public ProcessConnection (Socket s) (/ / constructor client = s; is try (= new BufferedReader (new InputStreamReader (client.getInputStream ())); os = new DataOutputStream (client.getOutputStream ());) catch (IOException e) (System.out.println ( "Exception:" + e.getMessage ()) this.start (); / / Thread starts here … this start () will call run ()) public void run () (try (/ / get a request and parse it. is.readLine String request = ( ); System.out.println ( "Request:" + request); StringTokenizer st = new StringTokenizer (request); if ((st.countTokens ()> = 2) & & st.nextToken (). equals ( "GET") ) (if ((st.nextToken request = ()). startsWith ("/")) request.substring request = (1); if (request.equals ( "")) request request + = "index.html"; File f = new File (request); shipDocument (os, f);) else (os.writeBytes ( "400 Bad Request");) client.close ();) catch (Exception e) (System.out.println ( "Exception:" + e.getMessage ());)) / ** * Read the requested file and ships it * to the browser if found * / public static void shipDocument (DataOutputStream out, File f) throws Exception (try ( DataInputStream in = new DataInputStream (new FileInputStream (f)); int len = (int) f.length (); byte  = new byte buf [len]; in.readFully (buf); in.close (); out . writeBytes ( "HTTP/1.0 200 OK \ r \ n"); out.writeBytes ( "Content-Length:" + f.length () + "\ r \ n"); out.writeBytes ( "Content-Type: text / html \ r \ n \ r \ n "); out.write (buf); out.flush ();) catch (Exception e) (out.writeBytes (" <html> <head> <title> error < / title> </ head> <body> \ r \ n \ r \ n "); out.writeBytes (" HTTP/1.0 400 "+ e.getMessage () +" \ r \ n "); out.writeBytes ( "Content-Type: text / html \ r \ n \ r \ n"); out.writeBytes ( "</ body> </ html>"); out.flush ();) finally (out.close (); )))
Experiment to HttpServer categories:
- HttpServer code will be stored in documents HttpServer. Java, and choose a directory to store it there.
- Use java c compiler HttpServer. Java
- Establish some HTML file as an example, there must be a "index.html", as it is in this case the default HTML document.
- Operation HttpServer. Use 8080 servers running ports.
- Open the Web browser, and a request: http://localhost:8080 or http://127.0.0.1:8080/index.html.
Note: You can think of HttpServer may receive some malicious URL? For example, or http://serverDomainName:8080//somefile.txt such as http://serverDomainName:8080/../../etc/passwd. As an exercise, modify HttpServer URL so that it does not allow such visits. Note: Write your own or use java SecurityManager. Lang.SecurityManager. Main ways you can add to the first sentence System.setSecurityManager (new Java.lang.SecurityManager) to install the security manager. Try!
Expansion HttpServer enable them to deal with https: / / URL
Now, I have to revise HttpServer categories, it becomes safe. I hope that the HTTP server can handle https: / / URL request. I mentioned earlier on, JSSE allows you to easily integrate the SSL to applications.
The creation of a server certificate
As I mentioned earlier, the use of SSL certificates for verification. The need to use SSL to guarantee the safety of communications client and server, we must create certificates. JSSE use and the use of certificates issued by the J2SE Java keytool together to create. With the following command to the HTTP server to create a RSA certificate.
Prompt> keytool-genkey-keystore serverkeys-keyalg rsa-alias qusay
This command will create a qusay alias used by the certificate, and kept in a serverkeys named in the document. Generate the time, this tool will prompt us some information, such as the information below, and increases the content of my writing.
Enter keystore password: hellothereWhat hellothereWhat is your first and last name? [Unknown]: ultra.domain.comWhat comWhat is the name of your organizational unit? [Unknown]: Training and ConsultingWhat ConsultingWhat is the name of your organization? [Unknown]: java courses.comWhat comWhat is the name of your City or Locality? [Unknown]: TorontoWhat TorontoWhat is the name of your State or Province? [Unknown]: OntarioWhat OntarioWhat is the two-letter country code for this unit? [Unknown]: CAIs CAIs CN = ultra, OU = Training and Consulting, O = java courses.com, L = Toronto, Ontario ST = C = CA correct? [no]: yesEnter yesEnter key password for
(RETURN if same as keystore password): hiagain
As you can see, keytool tips for keystore enter a password, it is because for server can visit keystore it must know the password. The tool also requires a password to enter alias. If you prefer, these password information can be designated by the keytool from the command line, use the parameters - storepass and - keypass on up. I use the attention to the "ultra.domain.com" as a name, the name of the machine is for my imaginary name. You should enter the server host name or IP address.
Keytool you are running in order when it may take a few seconds to generate the time your password, the specific speed depends on the speed of your machine.
Since I created a certificate for the server can now be modified to make them safe HttpServer. If you check HttpServer category, you will notice getServer method to return a server INTERLINKED son. In other words, the only way it necessary to amend the getServer return to a secure server socket on it. 2 in the code examples in Canada and is part of the changes made. Please note, I will be replaced by a 443-port, which is https default port number. Another point is worth noting: 0-1023, between the ports are preserved. If you run in different ports HttpsServer, should be URL: https: / / localhost: portnumber. But if you run in the 443 HttpsServer port, should be URL: https: / / localhost.
Sample code 2: HttpsServer. Java
Import java. Io .*; import java. Net .*; import java x.net .*; import java x.net.ssl .*; import java. Security .*; import java. Util.StringTokenizer; / ** * This class implements a multithreaded simple HTTPS * server that supports the GET request method. * It listens on port 44, waits client requests and serves documents * * / public class HttpsServer (String keystore = "serverkeys" char keystorepass  = " hellothere. "toCharArray (); char keypassword  =" hiagain. "toCharArray (); / / The port number which the server will be listening on public static final int HTTPS_PORT = 443; public ServerSocket getServer () throws Exception (KeyStore ks = KeyStore.getInstance ( "JKS"); ks.load (new FileInputStream (keystore), keystorepass); KeyManagerFactory kmf = KeyManagerFactory.getInstance ( "SunX509"); kmf.init (ks, keypassword); SSLContext sslcontext = SSLContext.getInstance ( "SSLv3"); sslcontext.init (kmf.getKeyManagers (), null, null); ServerSocketFactory ssf = sslcontext.getServerSocketFactory (); SSLServerSocket serversocket = (SSLServerSocket) ssf.createServerSocket (HTTPS_PORT); return serversocket;) / / multi - threading - create a new connection / / for each request public void run () (ServerSocket listen; try (= getServer listen (); while (true) (listen.accept Socket client = (); new ProcessConnection ProcessConnection cc = ( client);)) catch (Exception e) (System.out.println ( "Exception:" + e.getMessage ());)) / / main program public static void main (String argv ) throws Exception (HttpsServer https = new HttpsServer (); https.run ();))
String keystore = "serverkeys";
Char keystorepass  = "hellothere." ToCharArray ();
Char keypassword  = "hiagain." ToCharArray ();
Keystore designated name, password and key password. Write code directly in the text of passwords is a bad idea, but we can run servers in the command line when the designated password.
GetServer methods, and other JSSE code:
- It visited serverkeys keystore, JSK is Java KeyStore (a keytool from the keystore).
- KeyManagerFactory used to create X.509 keystore key management.
- SSLContext is to achieve JSSE environment. It can be used to create the ServerSocketFactory create SSLServerSocket. While we use SSL 3.0 designated, but often return to the realization of support other versions of the agreement, such as TLS 1.0. Old browser more often use SSL 3.0.
Attention to the default under the client does not need the test. If you want to request the server to verify the client, the use of:
HttpsServer now used to be a category of:
- ProcessConnection HttpsServer and will be two categories (The code) stored in document HttpsServer. In java.
- Let HttpsServer. Java and keytool serverkyes documents created in the same directory.
- HttpsServer use java c compiler.
- HttpsServer operation. By default it should be used under 443 port, but if you can not use it at this port, please choose another, more than 1024 ports.
- Open a Web browser and enter the request: https: / / localhost or https: / / 127.0.0.1. This is false translation server using 443 port situation. If this is not the ports, then use: use: https: / / localhost: port
In your browser, type https: / / URL of the time, you will get a pop-up security warnings, as did Figure 3. This is because their own HTTP server certificate is generated. In other words, it created by unknown CA, in your browser preservation CA did not find the CA. One option allows you to display the certificate (check it is not the correct certificates, as well as who is signed), and install the certificate, the certificate or refused to accept the certificate.
Figure 3: from unknown server certificate issued by CA
Note: in the private system of internal generated your own certificate is a very good idea. But in the public system, preferably from the renowned CA obtain the certificate, in order to avoid the browser security warnings.
If you accept the certificate, you can see the security after linking pages. After the visit with a Web site when the browser will no longer be the pop-up security warnings. Attention to the many Web sites use HTTPS, which is to have a certificate from an unknown or the CA. For example, https: / / www.jam.ca. If you do not visit this page, you will see Figure 3 the same as a safety warning.
Note: You receive a certificate, it is only effective for the current session, that is to say, if you completely withdraw browser, it has failure. Netscape and Microsoft Internet Explorer (MSIE) allows you to have permanent assurance certificates. In MSIE in practice is: Select shown in Figure 3, "View Certificate" and the newly opened window, select "Install Certificate."
The article talked about the JSSE SSL and describes the framework and its realization. The examples given in the text that can be integrated into the SSL your C / S applications is a very easy matter. The paper gives an example of security HTTP server, you can use it to experiment. The paper also introduced JSSE API and can occur HTTPS request Web browser.
[Original] J2SE beginners study notes what is a JAVA? (Easily reproduced - just please indicate the source)
I began to write something original, suitable for beginners and vegetables rookie, Titans and Daxia doors do not have to read, but if I have any say in the wrong place, or please exhibitions! J2SE beginners notebook is the latest I like to have some of a series, is just beginning to face contact with friends JAVA language, I have to obtain JAVA software engineer, recently participated in preparations for the SCJP SUN examination, writing that their own learning experience, and to share !
No experience, we lack a lot of criticism about:)
JAVA2 LWL (J2SE5.0 amended version) Author: Mr. Zhu Zhongjie Press strong industrial machinery to you recommend this book! Very good! Mr. Zhu Zhongjie Java is a very well-known expert
J2SE beginners study notes what a JAVA?
A history of Java
I learn a lot of friends to start a JAVA asked me most about is the problem, a simple, JAVA is an object-oriented programming language, as for what is object-oriented, after the article, will you, but if you is a C + + or C # programmers, I believe that has been very clearly the object-oriented concept, in December 1990, includes Sun's JAVA by James Gosling, the father of several technical staff set up called "Green Team" Group responsible for the development of a distributed system architecture, is the face of major consumer electronics products operating platform, when the group launched a similar function on the market today PDA products named Star7 Figure:
At that time, in the preparation of Star7, the language is the predecessor of Oak JAVA (Oak), but registered trademarks in Oak found another company is registered, so what name should we be? Engineers changed a cup of coffee while discussing, watching the hands of coffee, suddenly everyone's inspiration came, so the name Java was born.
JAVA is a start but not good accepted by the market, when the SUN about the abolition of this panel, the world's first global information network browser
Mosaic was born, and its high-performance Java has been widely used in the global information network platform for the preparation of interactive procedures (Applet), Java started to embark on the stage of history, May 23, 1995 - the birthday of Java, JDK (Java Development Kits) 1.0a2 officially released
The Java framework
1.Java own syntax:
Java language syntax generally consistent with the C language, and to improve a number of shortcomings, Java remove the C language in the guidelines, pre-processor, not the first document, in relation to other c + +, Java does not support the concept of multiple inheritance, Java has been added to garbage collection mechanism, exception handling, basically produced by the process itself and system security considerations.
2.Java execution environment:
"One preparation, running everywhere" is the slogan of Java's most charming, was having such characteristics, in addition to Sun's own Java platform provides the execution environment, the other manufacturers also invested a considerable amount of experience in the implementation of Java development environment.
And the general language have been compiled to machine language for the implementation of different Java to be compiled as a neutral bytecode (byte code), then loaded into a JAVA virtual machine (JVM) in the implementation of the hardware, which is cross-platform JAVA reasons, JVM there are now multiple platforms version.
JAVA implementation of the environment as a whole is called JRE, which contains the JVM and available to the browser using the Java Plug-in.
Note: You can run JAVA JRE construed as a virtual PC - Java Pc
Interpretation of the term:
What is the API?
API Application Programming Interface that is a group of other programmers write procedures, as long as you use according to his rules, you can use the procedures
Java 1.2 version officially changed its name to JAVA2
JDK corresponding to J2SDK
Debugger for the preparation of the implementation of the basic platform tool kit
J2SE - java development package, the latest version is 6.0 Beta, but our example is the JDK_1.4_02 do anything to fulfill your platform is also inseparable from the development of J2SE, which includes the Java program from the basic class library , there are some tools and compiler support procedures
Sun is also available for the development of enterprise-class J2EE, J2ME-oriented embedded development, not here to discuss additional support packages:
JAVA3D, not to in-depth discussions
Summary: the advantages of java
1. Time to prepare, run everywhere
5 Network Applications
6. Garbage collection mechanism and exception handling these advantages now that we should not be, and in the subsequent articles, through examples, we would like to deepen the impression immediately feel JAVA?
This site is the two will go
Sun technology communities China
Notes on first reading finished, we do not know that to understand Mody, I began studying JAVA is the mentality wrote this article, and I hope and the vast majority of beginners exchange JAVA, Java experts also hope that with the experts to criticize correction, help raise younger brother!
My E-mail: email@example.com
J2SE 1.4.2 enhancements and changes
J2SE 1.4.2beta latest version of this paper to introduce this version of the main new features with the new changes.
Client HotSpot compiler, mainly in the speed and footprint on the compiler improvements.
Server HotSpot compiler, in the IA32 platform fooled processor and operating system support, the use of SSE and SSE2 instructions.
Constant divisibility faster computing.
2nd faster floating-point computing power division.
NullPointerException faster processing.
Http and https against the NTLM authentication is now supported on the Windows platform.
HTTP redirect support to the relative URL, and in 1.4.2 before, we call redirect the URL is an absolute must URL address.
New I / O (NIO)
Channel original category (SocketChannel, ServerSocketChannel, etc.) finalize method is removed.
I / O
In Windows2000/XP, the locale of the Windows default encoding no corresponding ANSI code page conversion from utf-16le to utf-8. In this version provided by the existing ASCII text encoding, as well as compatibility with the locale processing output systems.
Changed the Windows platform installation procedures, mainly in the locale on the support of the change. There is now a single installation procedure, if only supports Windows operating system in Europe languages will be installed by default under the support of the European languages. If Windows system to support at least one non-European languages will be installed on all languages support. Users can customize the installation to install another language.
Many new certificates and encryption algorithm was added to this version, such as the CA certificate, AES (Advanced Encryption Standard), SHA-256, SHA-384 and SHA-512 hash algorithm.
Repair some bug.
JNDI / LDAP services are now provided on request access to LDAP server using SSL connection support.
Users do not have LDAP URL can be specified in the port. For non-SSL connection port, the default is 389, and SSL connection port, the default is 636. In version 1.4.2 before all connections are the default port number 389..
Java sound technology
Windows and Solaris, now supports Port.
Now supports ALSA (Advanced Linux Sound Architecture).
At the same time, in the Lunux capture / playback and has now become possible.
Java 2D technology
1.4.2 has been amended many of the bug. Much of the work done to strengthen Window mainly in full-screen support. If there are amendments to the font handling, and in Linux on the 24-bit pixel support, as well as IDE locked the bug, among others.
1.4.2 now bundled with the Thai input method, but is in default under closed. To enable it, will be located in the JRE lib / im thaiim.jar moved to the directory lib / ext directory.
In Windows XP, you may experience this problem: for example, can not change the input method or tool of the input method can not be displayed. If you encounter such a problem, please use the latest Windows XP service pack.
Amended Windows2000 and XP, set up in a TextArea SCROLLBARS_BOTH only display a vertical of the bug.
Amended in 1.3.1 and 1.4 running from a modal window Runnable Deadlock problem.
Amended in the absence of ANSI code page when Windows input method can not enter text of the bug.
Introducing two new Look & Feel: Windows XP L & F and GTK + L & F.
Improved start-up time
Best of the core library to improve startup time. For a small command-line applications, startup time increased 30 percent for a small-scale Swing applications, improved 14% to 20% of the start-up time.
In 1.4.1, from the stop Applet () or destroy () method call in a pop-up window mode Fang could lead to some problems, such as NullPointerException, or do not show this dialog box, even when Applet were destroyed after the dialog box exists, the situation is the worst Browser die. These problems have been repaired in 1.4.2.
In 1.4.1, java.applet.getDocumentBase () returns a Applet this document contains a list of URL. 1.4.2 In return for the amendments in this document their own URL. Similarly, java.applet.getCodeBase () returns the URL Applet, in 1.4.2 now amended to return to the directory containing this Applet URL.
In 1.4.2, when through the Java Plug-in the deployment of an applet (in the cache turned on circumstances), if the applet in a number of class JAR files in the document, and if they have a category called the javax.crypto . Cipher.getInstance () method, then access to the same JAR file the request and threw out the operation will fail, "java.lang.IllegalStateException: Zip file closed," but now this bug has been amended.
Java Plug-in technology
Java Plug-in now supports Mozilla version 1.1 and beyond.
In this version of the ActiveX Bridge technology has been re-realized. It allows JavaBean like ActiveX controls as shown in ActiveX container. Different from before is that developers want to use ActiveX Bridge must re-package their bean.
JSObject now can return to the correct DOM element types.
Java Web Start 1.4.2
JAWS achieved when each operation, the computer automatically detects all registered JRE.
JNLP URL is not even. Html and. Jnlp file can now be directly in the application management for JAWS in the open and marked as bookmarks.
JPDA (Java Platform Debugger Architecture)
New interface capabilities to JVMDI, allowing multi-threaded implementation of the suspend and resume. This function also increased in JVMPI. They are:
JvmdiError SuspendThreadList (jint reqCount, jthread * reqList, jvmdiError * results)
JvmdiError ResumeThreadList (jint reqCount, jthread * reqList, jvmdiError * results)
In addition, now also achieved in the previous JVMDI did not realize the interface functions:
JvmdiError GetOwnedMonitorInfo (jthread thread, infoPtr JVMDI_owned_monitor_info *)
JvmdiError GetCurrentContendedMonitor (jthread thread, jobject monitorPtr *)
Java compiler (javac)
Increased - classpath order options synonymous order - cp.
Increased - Xmaxerrors and - Xmaxwarns command option to restrict the largest printing in the Java console a few errors and warnings.
Javac Health also to repair some of the Bug. Such as not to repeat the mistakes of the local category, such as a declaration.
Added several new command option.
At the time waiting for watching Xianlaimoshi suddenly thought of J2SE doubt on the point. Run Java programs, the machines must have JRE. Now do a hypothetical, if we use J2SE development of a common procedure, and then to start the promotion, it is not a requirement on a user's machine must have the JRE, if a computer user is blind, I do not know what is JRE (which is very possible things , is also very common), even if such a statement in the document JRE needs of ordinary users, is still a difficulty. Of course, the paper can also be bundled with the installation of JRE installed, so that the user is not a violation? But what they do not have a user, he will install the JRE strange feeling, then your product doubt. Therefore, the use of J2SE to prepare procedures do exist in this issue.
Of course, J2EE, this issue could be satisfactorily resolved, because users focused, easier to control. J2ME is, can be controlled through the terminal. From that point on, we can see the importance of controlling platform, it is assumed SUN like Microsoft, windows, then this problem can easily solve Rafah, not MS SUN Unfortunately, it will not develop MS Java such as the inter - platform language.
France lost last night, Zidane was determined to never master the art. . . . . . .« go back — keep looking »