Java programming from entry to entry

Source: Internet
Author: User
Tags object serialization

I. JDK (Java Development Kit)
JDK is the core of the entire Java, including the Java Runtime Environment (Java runtime envirnment), a bunch of Java tools and the Basic Java class library (RT. Jar ). No matter what Java application server is, a specific version of JDK is built in. Therefore, mastering JDK is the first step to learn java well. The most popular JDK is the JDK released by Sun. In addition to sun, many companies and organizations have developed their own JDK, such as JDK developed by IBM and jrocket of Bea, and JDK developed by GNU. Among them, the JVM (Java Virtual Machine) Running Efficiency of ibm jdk is much higher than that of Sun JDK. The jrocket running on the X86 platform is much more efficient on the server than Sun JDK. But no matter what we say, we still need to Master Sun JDK first.
1. Download and install JDK
JDK is also called j2se (Java2 SDK Standard Edition), can be downloaded from Sun's Java website, http://java.sun.com/j2se/downloads.html, JDK is currently the latest version of j2sdk1.4.2, it is recommended to download this version of JDK, download the page at http://java.sun.com/j2se/1.4.2/download.html.
The downloaded JDK is an executable installation program. After the installation is completed by default, a set of JRE (for use by browsers) will be installed in the C: Program filesjava directory. In C: install a JDK (including a JRE) under j2sdk1.4.2 ). Then we need to add the Java path C: j2sdk1.4.2bin at the beginning of the Environment Variable path. In this way, JDK is installed.
2. JDK command tools
JDK's most important command line tool:
Java: Start JVM to execute class
Javac: Java compiler
Jar: Java packaging Tool
Javadoc: Java document Builder
These command lines must be very familiar with each parameter. JDK documentation provides detailed documents on how to learn these commands.
Ii. JDK documentation
Documentation is also available on the JDK download page. We recommend that you download documentation at the same time. Documentation is the most important programming manual, covering the description of all aspects of Java. It can be said that the majority of the time spent learning Java programming is spent reading this documentation. I carry it with me. When I write Java code, I can check it at any time.

3. app Server)
APP Server is a platform for running Java Enterprise components and forms the main runtime environment of application software. Currently, the mainstream app server is BEA's WebLogic Server, IBM's WebSphere, and free JBoss. You can select one of them for learning. I personally recommend WebLogic, because of its clean architecture and convenient development and deployment, it is the preferred development platform for Java Enterprise software developers. The following describes several common app servers:
1. Tomcat
Tomcat is not a real app server in a strict sense. It is just a Web container that supports running Serlvet/JSP. However, Tomcat also extends some app server functions, such as JNDI, database Connection Pool, user transaction processing, and so on. Tomcat is widely used in small and medium-sized Java Web applications. Therefore, this article introduces how to download, install, and configure Tomcat:
Tomcat is a sub-project under the Jakarta project under the Apache organization, its main website is: http://jakarta.apache.org/tomcat/, Tomcat latest version is tomcat4.1.27, software download connection is: http://www.apache.org/dist/jakarta/tomcat-4/binaries.
To download tomcat, you can download both the zip package and the EXE installation package (I suggest you clean the ZIP file). In either case, after the download and installation are complete (you can decompress the ZIP file directly ). You need to set two environment variables:
Java_home = C: j2sdk1.4.2
Catalina_home = D: tomcat4 (your tomcat installation directory)
After installation, start Tomcat to run catalina_homebinstartup.bat and close tomcat to run the shutdown. Bat script. After Tomcat is started, port 8080 is used by default. Therefore, you can use a browser to access http: // localhost: 8080 to test whether Tomcat is started properly.
Tomcat provides two management tools on the web interface. The URLs are:
Http: // localhost: 8080/admin/index. jsp
Http: // localhost: 8080/manager/html
Before enabling these two management tools, you must manually configure the administrator user and password. Open the CATALINA_HOMEconftomcat-users.xml file with a text tool and add the following lines:

 

In this way, the user "Robbin" has the super administrator permission. After you restart tomcat, you can use the user to log on to the two management tools above and configure and manage Tomcat on the web.
2. BEA WebLogic
WebLogic can download the latest Weblogic8.1 Enterprise Edition After free registration on the BEA website. License can be used for free for one year. In fact, this is enough. WebLogic download link: http://performance.bea.com/index.jsp, weblogic's on-line document: http://edocs.bea.com /.
3. IBM webshpere
WebSphere can also download to the free trial version, to IBM's developerworks website can see the download of Websphere trial products and related WebSphere information, the link of the Chinese site of developerworks is: http://www-900.ibm.com/developerWorks/cn/wsdd, webSphere download connection: http://www7b.software.ibm.com/wsdd/downloads/WASsupport.html.
4. JBoss
JBoss is a free and open-source app server. It can be downloaded from the JBoss website for free: Ghost. There are several good JBoss configuration documents on jdon, can be used for reference: http://www.jdon.com/idea.html

Iv. Java application Runtime Environment
Java applications can be divided into the following aspects:
1. Java Desktop applications
Desktop applications generally require only JRE support.
2. Java Web Applications
Java Web applications must install JDK, a Web Container (such as Tomcat), and a multi-user database. Web applications must be divided into at least three layers:
Browser layer: displays the user page in the browser.
Web layer: Run Servlet/jsp
DB layer: backend database that provides data access services to Java programs
3. Java Enterprise Applications
Enterprise applications are complex and can be extended to layer n. The simplest case is divided into four layers:
Browser layer: displays the user page in the browser.
Client layer: Java client graphics programs (or embedded device programs) directly interact with the web layer or EJB Layer
Web layer: Run Servlet/jsp
EJB layer: runs EJB to complete business logic operations
DB layer: backend database that provides data access services to Java programs
4. Java embedded applications
Java embedded applications are an emerging field. They are engaged in Embedded Development and need to download the j2's development kit from sun. j2's includes the dedicated virtual machine KVM for embedded devices, which is different from the JVM contained in the general JDK. You also need to download the simulator from a specific embedded vendor.

Java learning path (2), books
It is impossible to read only one or two books to learn a new knowledge. A step-by-step reading process is required. I recommend the Java series books published by oreilly.
Here I just want to add one point. Many people start with thinking in Java, but I think this book is not suitable for beginners. I think the correct way to use this book should be as an auxiliary reader. Thinking in Java is not a complete introduction to the entire java system, but a leaping writing method, it is a method similar to tips to deeply analyze and explain many Java knowledge points.
For beginners, it is best to find a book on getting started with Java, but it introduces Java syntax, object-oriented features, core class libraries, and so on in sequence. while reading this book, let's take a look at thinking in Java to deepen our understanding of Java and how it works. At the same time, we can fully understand the entire Java System.
For getting started books on Java, Cai xuexiao recommends oreilly's cutting ing Java, 2nd edition, or Java in a nutshell, 2nd edition (for C ++ background). I have not read these two books. In fact, I think the Electronic Industry Press's "Java 2 programming details" or "Java 2 from entry to mastery" is very good.
Among all the Java books, the most useful is not o'reilly's Java serials. The most useful is JDK documentation! Almost all the knowledge you want to obtain is available in documentation. The most important part is the API documentation of the Java basic class library, which is organized by package, each class has a detailed explanation, its inheritance relationship, whether an interface is implemented, and where can all its public attributes and methods be found, the interpretation and meaning of each attribute, the purpose of each method, the called parameter, the meaning of the parameter, the type of the returned value, and the exceptions that the method may throw. In this way, all the books on Java programming are actually just in a relatively easy-to-understand language, and a good way to introduce the usage of some classes in a package in documentation. As a result, if you have enough ability to directly learn Java class libraries through documentation, you do not need to read other books. In addition, documentation is also a required manual for programming. There are three documentation shortcuts on my desktop: documentation of j2sdk1.4.1, documentation of servlet2.3, and documentation of j2sdkee1.3.1. With these three documentations, no other books are needed.
For Java Web programming, the core thing is to be familiar with and master the HTTP protocol, which has nothing to do with Java. After being familiar with the HTTP protocol, you need to be familiar with Java class libraries for implementing HTTP protocol, that is, Servlet APIs. The most important thing is servlet APIs. Of course, it is very difficult for beginners to learn web programming directly through servlet APIs. I recommend o'reilly's Java Server Pages book to learn web programming.
Among the EJB books, Enterprise JavaBeans, 2nd edition is a very good book. The learning threshold for EJB is relatively high and it is difficult to get started, however, this book completely reduces the difficulty of learning. It is particularly important that the learning of EJB should be combined with the specific implementation of an app server. Therefore, while learning EJB, you must learn an app server synchronously. This book has three related books: weblogic6.1, websphere4.0, and jboss3.0. There are both theories and practices. While learning EJB, you can view and do it while learning it, and learning EJB will become very easy.
However, this book also has a problem, that is, the old version mainly focuses on the ejb1.1 specification and some ejb2.0 specifications. The mastering EJB 2.0 book written by Ed Roman is completely written in accordance with ejb2.0 specifications. It covers all aspects of EJB programming and has a lot of programming experience tips, it is also one of the most recommended books for learning EJB.
If you use WebLogic to learn J2EE, the J2EE application and BEA WebLogic Server is definitely the first choice. Although it is about weblogic6.0, it is worth buying, this book is officially recommended by BEA, and the author is also an engineer of Bea. Now the Chinese version is everywhere. This book introduces the development and deployment of various J2EE technologies on the Weblogic Platform in combination with WebLogic, which has great practical guidance significance.
After having mastered the basic knowledge of the Java platform and the knowledge of J2EE, we should learn how to use the OO method to design the software, so we must learn the "Design Pattern ". Sun has published a J2EE Core Model, which is an essential book for architects who develop Java Enterprise platform software. This book comprehensively introduces various design modes of the J2EE architecture and is a must-read book for designers.

Java learning path (3) Process
Each person's learning method is different. One person's learning method is not necessarily suitable for another person. I can only talk about my learning method. Because I learned Java completely by myself, I have never been able to make it happen? Playing tricks ?? Turns? Tomb? Why? Old Yin Qi? Have an appointment? Why is Yi qixun copying n Yihui? What kind of chilies do I have to worry about? Waste? Why can't I use anti-inflammatory drugs? BR> the first step to learning Java is to install JDK and write a hello World ,? In fact, the learning of JDK is not that simple. There are two problems with JDK that are easily plagued by Java programmers: one is the classpath problem. In principle, it is necessary to understand how the JRE classloader loads the class, the package and import problems, and how to find the class path. By clarifying these two problems, we have removed the biggest obstacle to learning Java and using JDK. We recommend that you take a look at Wang Sen's "Java deep Adventure" and discuss these two issues in depth.

The second step is to learn the Java syntax. Java syntax is similar to C ++. Basically, the mainstream programming languages are not class C, but class C ++. There is nothing new, so the syntax is learned, about half a day is enough. The only thing to note is that there are several keywords that are not easy to understand: public, protected, Private, static, when to use, why to use, how to use, it may take a long time for someone to give me some advice. But later I saw thinking in Java, which mentioned these concepts.
The third step is to learn the features of Java's object-oriented programming language. For example, inheritance, constructor, abstract class, interface, method polymorphism, overload, overwrite, and Java exception handling mechanism. For a person without an object-oriented language background, I think this process takes a long time, because I have no C ++ experience before learning Java and only C experience, it took me about a month to fully understand these concepts. I tried to repeat, modify, and try the examples in the book and read them over and over again, after reading the past, I had to read it five times before I fully realized it. However, I think if I have C ++ experience, it may take a day or two. In this process, you can take a look at thinking in Java, which provides a very thorough explanation of object-oriented. Unfortunately, I didn't see this book when I was studying it, so I spent a lot of time learning it through my own attempts and guesses.

Step 4: Get familiar with Java class libraries. The Java base library is the jrelibrt. jar package under the JDK installation directory. Learning the basic library is to learn Rt. jar. There are many classes in the basic class library. It is said that there are more than 3000, and I have not made any statistics. But for us, there are only four at the core:
Java. Lang .*;
Java. Io .*;
Java. util .*;
Java. SQL .*;
The four packages of learning, each of which can be written as a thick teaching material, and o'reilly does. I think it is impossible to study by reading four books if the time is too short. I think the better way to learn is as follows:
First, read the entire package framework and understand the composition of the class, interface, and exception of the entire package. It is best to find an article about the entire package framework. The first few chapters of these books that specifically introduce the package should be the introduction of these general frameworks.

Understanding the overall framework of the package is not to be familiar with the usage of each class. Remember what attributes and methods it has. I cannot remember it. Instead, you need to know what types of packages are composed of. What are the purposes of these classes and what functions are implemented by the core classes. During training, I usually talk about a package in a class, so it is impossible to describe the usage of each class in detail. However, I have repeatedly stressed that, what I want to tell you about these packages is not to tell you how class methods are called, nor to remind you of class method calls, but to understand, java provides us with classes, where each class is used. When I encounter a problem, I know which class or which combination of classes can solve my problem, that 'all !, When writing a program, you only need to know which class to use to complete your work. When coding, the specific method call is to write code while querying documentation. Everything is in documentation. You do not need to remember it, in fact, you cannot remember nearly 3000 method calls for more than 0.1 million classes. Therefore, it is extremely important to grasp the overall framework of each package.
Step 5: Through the above study, if the learning is solid, it will lay the foundation for Java, the rest of the work is to clear some useful classes except the above four packages in documentation. I believe that the progress has reached this step, and Java's self-learning capability has been developed. Now we can directly learn documentation. In addition to Gui programming, other useful packages in JDK are:
Java. Text .*;
Java.net .*;
Javax. Naming .*;
There are actually few classes in these packages, so it does not take a lot of time.
Step 6: Java Web programming. The core of WEB programming is HTTP. HTTP has nothing to do with Java. If you are not familiar with HTTP, you can also learn Servlet/jsp programming well, however, it cannot reach the level of perfection. Therefore, learning the HTTP protocol is essential. If I am familiar with the HTTP protocol and have a good foundation for Java programming, it would be easy to learn Servlet/JSP. It took me less than a week to learn Servlet/JSP, then we started to use JSP for the project.
In Servlet/jsp learning, the beginning is still servlet documentation. The most common classes of servlet APIs are very few, so it takes a little time to master them. Read all these classes and write several more examples. The essence of Servlet/jsp programming is to call these classes repeatedly to communicate with the Web server and Brower over HTTP. In addition, for JSP, you also need to be familiar with several common JSP tags. If the specific writing method cannot be remembered, you can temporarily check the tags.
In addition, the focus of Java Web programming learning should be on the Design Pattern of Web applications. How to analyze the business logic and make rational design, in accordance with the requirements of the MVC design pattern, use Servlet and JSP to complete different logic layers, Master how to control the process and share data between Servlet and JSP, and how to configure and deploy Web applications.
Step 7: J2EE Programming
If the above learning process is relatively smooth, the difficulty increases sharply. Because the above knowledge only involves one aspect, and core J2EE specifications such as EJB, JMS, and JTA are often the result of the comprehensive application of several Java technologies, therefore, it is difficult to master.
First, you must learn the JNDI. The JNDI is the method used by the app server to locate server resources (EJB components, datasouce, JMS). If you are not familiar with JNDI, EJB, JMS is almost impossible to learn. JNDI is actually the javax. Naming. * package, which is easy to use. The difficulty lies in the configuration of server resource files. For the server resource file configuration, you need to look at the specific documentation specifications, such as web. xml writing, ejb-jar.xml writing and so on. You need to be familiar with each different app server and its own service resource configuration files.
Then we can learn about JTA, mainly to understand the JTA's method of controlling transactions and how to use JTA. Here is a simple example. We know that transaction control (Conn. setautocommit (false ),...., conn. commit () is used as an atomic operation, but if my business needs to use operations on two different databases as an atomic operation, can you do it? At this time, only JTA can be used. Assume that the operation first inserts a record into database A and then deletes another record in database B. We cannot control the entire operation as an atomic operation by writing code on our own. If JTA is used, the app server controls it.
Before learning EJB, you need to learn Object serialization and RMI. Rmi is the foundation of EJB. Next, we will learn about JMS and EJB. For EJB, the most important thing is to understand how EJB calls remote objects through RMI, and under what circumstances EJB should be used.
After learning about EJB and JMS, you may realize that you need to learn more about the two fields: UML and design pattern. Java Enterprise software design attaches great importance to Framework Design. A good software framework is a necessary condition for successful software development. At this time, we should begin to focus on the learning of the design mode and framework, and master the EJB Design Mode and the core mode of J2EE through learning and practical programming experience.
In the J2EE specification, there are many enterprise technologies in addition to EJB, JMS, JTA, Servlet/JSP, and JDBC, which are not described here.
There is also a new field of Web Services. Web Services does not have any new things. It is like a kind of adhesive. It can unify different services and provide a unified call interface. for users, I only need to obtain the WSDL (service description) provided by the service provider. I have no idea whether the service provided by the server provider is an EJB component or. NET Component, what is the CORBA component, or other implementation, I do not need to know. The greatest part of web services lies in the sharing of Internet services by means of unified service provision and calling. It is a very exciting technical field. Web Services does not seem to have any good books yet, but it can be learned by querying information on the Internet.

So I don't think it is really a special routine. The destroy routine you write is the best example. If you are not at ease with the code you write, I strongly recommend that you check the Java source code of the JDK base class library. There will be a src.zip under the JDK installation directory, and you can see the entire JDK base class library, that is, Rt. jar Java source code, you can refer to how sun writes a Java program, what the specifications look like. When I am learning Java class libraries, when I do not understand them clearly or want to understand the operation details more clearly, usually open the source code of the corresponding class. by looking at the source code, all problems will be swept away.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.