Getting started with Java

Source: Internet
Author: User
Tags object serialization jboss ibm developerworks
Tools
JDK (Java Development Kit)

JDK is the core of Java, including Java runtime envirnment.
And Java-based class libraries (RT. Jar ). No matter what Java application server is actually built into a certain version of JDK.
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, jrocket developed by BEA, and
JDK developed by GNU. Among them, the JVM (Java Virtual Machine) Running Efficiency of ibm jdk is required.
It is much higher than the JVM contained in Sun JDK. The jrocket running on the X86 platform is more efficient than the jrocket running on the server.
Sun JDK is much better. However, we still need to Master Sun JDK first.

1. Download and install JDK
JDK, also known as j2se (Java2 SDK Standard Edition), can be downloaded from Sun's Java website, HTTP
: // Java.sun.com/j2se/downloads.html. The latest JDK version is j2sdk1.4.2. We recommend that you download this
The download page for JDK is http://java.sun.com/j2se/1.4.2/download.html.

The downloaded JDK is an executable installation.ProgramBy default, after the installation is completed, it will be in the c: \ Program Files \ Java \ directory
Install a set of JRE (for use by browsers) and a set of JDK (including a set of JRE) under c: \ j2sdk1.4.2 ).
Then we need to add the Java path c: \ j2sdk1.4.2 \ bin at the beginning of the Environment Variable path. In this way, JDK is installed
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. To learn these commands,
JDK documentation provides detailed documentation.

Ii. JDK documentation

Documentation is also available on the JDK download page. We recommend that you download documentation at the same time. Documenta
Tion is the most important programming book, covering the description of all aspects of Java. It can be said that learning
Java programming, most of the time is spent reading this documentation. I carry it with me, write Java
CodeCan be viewed 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. Current mainstream AP
P server is BEA's WebLogic Server, IBM's WebSphere, and free JBoss.
I recommend WebLogic because the architecture is more dry and the development and deployment are more efficient.
Convenience 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
Web containers, but Tomcat also extends some app server functions, such as JNDI, database connection pool, and user transactions.
Processing. Tomcat is widely used in small and medium-sized Java Web applications.
Install and configure Tomcat:

Tomcat is a subproject under the Jakarta project under the Apache organization, its main website is: http://jakarta.ap

Ache.org/tomcat/, the latest tomcat version is tomcat4.1.27, and the 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 which case, after the download and installation are completed (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_home \ bin \ Startup. bat, and disable tomcat to run Shu.
Tdown. Bat script. After Tomcat is started, port 8080 is used by default. Therefore, you can access http: // Lo in a browser.

Calhost: 8080 to test whether Tomcat is started normally.

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. Use a text Tool
Open the catalina_home \ conf \ tomcat-users.xml file, add the following lines:



In this way, the user "Robbin" has the super administrator permission. After restarting tomcat, you can use
Users can log on to the two management tools above and configure and manage Tomcat through web.

2. BEA WebLogic
WebLogic can download the latest Weblogic8.1 Enterprise Edition After free registration on the BEA website. License can
It is enough to use it for free for one year. WebLogic download connection: http://commerce.bea

. Com/index. jsp,.../edocs.bea.com /.

3. IBM webshpere
WebSphere can also be downloaded to a free trial version, and you can see the webfe-test on the IBM developerworks website.
Download the ere trial product and related WebSphere documents. The link to the developerworks Chinese website is: HTTP
: // Www-900.ibm.com/javasworks/cn/wsdd/, WebSphere download connection: http: // www7b

.Software.ibm.com/wsdd/..wassupport.html.

4. JBoss
JBoss is a free open source app server, can be free download from the JBoss Website: http://www.jboss.org/I

Ndex.html, then ...n.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 are 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 Application is an emerging field. For Embedded Development, You need to download
2me includes the dedicated virtual machine KVM for embedded devices, which is different from the JVM contained in General JDK. You also need
Download simulators from specific embedded vendors.

Books
It is impossible to read only one or two books to learn a new knowledge. A sequence is required.
A progressive reading process. 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, each attribute's interpretation, meaning, usage of each method, and calls of books involved in 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 table: 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, for beginners, learning web programming directly through servlet APIs
I recommend o'reilly's Java Server Pages 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 books recommended to learn about EJB. For Learning J2EE with WebLogic, the J2EE application and BEA WebLogic Server are definitely the first choice.
Although it is about weblogic6.0, it is still worth buying. This book is officially recommended by Bea.
Bea engineers. Now the Chinese version is everywhere. This book introduces various J2EE
It is of great practical significance to develop and deploy the above technologies on the Weblogic Platform.

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.

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 and never asked anyone, the learning process was basically entirely self-developed. I don't know whether this method is a good one. I can only provide you with some reference.
.
The first step to learning Java is to install JDK and write a hello world. In fact, JDK is not so learning.
Simple: there are two problems with JDK that are easily plagued by Java programmers: classpath. 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 mainstreamProgramming LanguageIt is similar to C ++ and there is no new things. Therefore, it takes about half a day to learn the syntax. 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, and 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 I only have to figure out and modify it, I tried to read those chapters over and over again. I had to read them five times before I fully understood them. However, I think if C ++ has been verified, it should be enough time in a day or two. In this process, you can take a look at thinking in Java, which provides a thorough explanation of object-oriented. Unfortunately, when I was studying,
I didn't see this book, 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 JRE \ Lib \ RT. 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 million
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 a better learning method 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 the framework that introduces the entire package.Article. 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 which classes are included in the package, what are the purposes of these classes, and the core classes respectively.
What functions are completed. I usually give a package for a class during training, so it is impossible to introduce it in detail.
I have repeatedly stressed the usage of each class, but I will not tell you how to call these classes.
You do not need to remember the class method call, but want to know which classes Java provides for us
Where is a class used? When I encounter a problem, I know which class or which combination of classes can solve it.
My problem, that's all !, When writing a program, as long as you know which class to use to complete your
Work is enough. When coding, the specific method call is to write code while querying documentation. All
Everything is in documentation. You do not need to remember it. Actually, you cannot remember the total number of more than 3000 classes.
There are nearly 0.1 million method calls. 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 of its 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 the GUI programming, other useful packages in JDK are as follows:
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 the HTTP protocol, which has nothing to do with Java. If you are not familiar with the HTTP protocol, you can also learn Servlet/jsp programming well, but you cannot do anything about it, the realm of yitongbaotong. Therefore, learning the HTTP protocol is essential. If you are familiar with the HTTP protocol and have a good foundation for Java programming, learning Servlet/JSP is easy.

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 where 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 I want to perform operations on two different databases as an atomic operation, can you do it? Only
JTA. 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 ejbs. The most important thing for ejbs is to understand how ejbs call remote objects through RMI, and under what circumstances to use ejbs.

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 at all. It is like a binder. Different services can be unified to 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. I don't need to know about the net component, what is the CORBA component, or other implementations. 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 you can learn it by checking information on the Internet.

Method
Java as a programming language, the best way to learn is to write code. After learning a class, you can write a simple example program to run it to see what the result is, and then call several more class methods to see the running result, in this way, the class is learned intuitively and the memory is very deep. The code should not be called. You should think about it. If I don't write it like this, try again. I remember which expert said that learning programming is a process of destruction. After running the examples in the book and learning the examples compiled by documentation, he constantly tries to use different methods for implementation, constantly try to break the code structure and see what results it will have.
In this way, you will have a thorough understanding of Java.
For example, we have compiled Hello world.

Public class helloworld {
Public static void main (string [] ARGs ){
System. Out. println ("Hello World ");
}
}

Many beginners do not quite understand why the main method must be defined as public static void main (string [] ARGs) in this way. Can it be written like this? This includes questions when I first learned Java. Do you want to know the answer? It is very simple. You should change the main name to run it to see what errors are reported, and then analyze the root data error information. Remove the public of main and try again to see what errors are reported; static removal can still be run; do not know if the main method must pass a string [] array, change string [] to int [], or try it out; if you do not know whether to write the ARGs parameter name, you can also change the ARGs to another name to see how the running result works.

This is what I did when I first studied java. I modified the hello World Program seven or eight times and kept running and analyzed the running results, finally, I fully understand why the main method is defined in this way.
In addition, for Staic, public, private, exception, try {} catch {} finally {}, etc.
I didn't understand it very well at the beginning. I started to run the examples in the reference books successfully, and then I began to destroy it.
Rewrite the program to see if it can run, what it looks like, and whether it can run.
Expected results are displayed. This is time-consuming, but an example program is destroyed several times in this way. I just
I have thoroughly learned the relevant knowledge. Sometimes you may even intentionally write some wrong code to run it and see if it can be obtained.
Expected running error. In this way, we have a profound understanding of programming.
Among them, it is particularly worth mentioning that JDK has a very good debugging function,-verbose
Java-verbose
This option is available for javac-verbose and many other JDK tools.
-Verbose can display the classes loaded by the JVM in sequence during command execution.
Information to help us analyze what the JVM has done during execution.

In addition, many of the destructive routines you write during the learning process should be consciously stored in different categories, and the typical routines accumulated in your work should also be sorted regularly, you have a code library. Encounter
Similar problems: Copy & paste, search & replace in the code library.
Sending speed. The ideal situation is to abstract some common routines to form a common class library and encapsulate
Okay. The reusability is enhanced.
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 JavaSource code. In the JDK installation directory, there will be a src.zip file. You can see the entire JDK base class library, that is, the Rt. Jar Java
Source code. You can refer to how sun writes Java programs and what the specifications look like. When I am learning Java class libraries, I want to understand the details of operations more clearly when I do not understand them clearly.
When reading the source code of the corresponding class, all the problems will be cleared.

Resource

1. http://java.sun.com/
(English)
Sun's Java website should be visited frequently. Needless to say.

2. http://www-900.ibm.com/developerWorks/cn/

For the IBM developerworks website, go to the English site. This is not only an excellent target
Image analysis and design websites are also excellent websites for Web Services, Java, and Linux. It is strongly recommended !!!

3. http://www.javaworld.com/
(English)
Discussions and news about many new Java technologies. I 'd like to know more about all aspects of Java, which is better here.

4. http://dev2dev.bea.com.cn/index.jsp

Bea's developer field. As the most important app server vendor, BEA has many unique technologies on weblogic.
Developers are not to be missed.

5. http://www.huihoo.com/

The gray fox power website, a professional middleware website, is not a professional Java website, but is applicable to J2EE enterprises.
Profound technical accomplishments.

6. http://www.theserverside.com/home/
(English)
Theserverside is a famous website dedicated to Java server applications.

7. http://www.javaresearch.org/

The Java research organization has many excellent articles and tutorials on Java, especially in JDO.

8. http://www.cnjsp.org/

JSP technology websites have a considerable number of Java articles and resources.

Http://www.jdon.com/

Jdon forum is a personalized Chinese J2EE Professional Technology Forum. Among the many Java Chinese forums, jdon
One is a forum with high technical content and excellent post quality.

Http://sourceforge.net/

Sourgeforge is a base camp for open source software, which also has a very rich set of open source code for Java.
The famous software.

From: http://mabo263.blogchina.com/3764539.html

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.