Java learning experience

Source: Internet
Author: User
Tags object serialization
Share some experiences with Java learners

I have been studying Java for two years. I never dare to say how proficient I am, but I also want to talk about my feelings and write it to my colleagues at the Software Institute, this helps you avoid detours on the technical road. I hope everyone will compete for the Software Institute. In fact, the most important thing is the improvement of your own progress.

1. About the Dynamic Loading Mechanism --
Learning Java is easier to understand the idea of OOP than C ++. After all, C ++ has a lot of process-oriented components. Many people can back up the features of the Java language, the so-called dynamic loading mechanism, and so on. However, the concept is often first remembered and then digested. How many people have actually realized the dynamic loading mechanism and tried to find details? You can use the following methods:
When running a Java program in the command line window, add this useful parameter:

Java-verbose *. class

This will clearly print the loaded class files, most of which are required for jdk's own operation. The last few lines will clearly see the order in which the class files used are loaded. Even if you declare a class object, it will not be loaded without instantiation. It means that the loading will only be executed when the class instance is actually used, that is, the object. In this case, do you understand a little bit about dynamic loading? Pai_^

2. Principles of searching for class files --
It is recommended that you compile and run in the command line window at the beginning, instead of using JCreator, Eclipse, and other IDE To help with those tasks. Try to do this yourself:
Javac-classpath yourpath *. java
Java-classpath yourpath *. class
Many people may understand that the purpose of setting classpath is to tell the compiler where to find your class file. however, at least I understand the principle of JVM to query classes today. The compiler must load classes by classloader. The classloader has three levels, from high to low, which are BootClassLoader (the name may be inaccurate ), extClassLoader, AppClassLoader.

These three loaders correspond to the compiler to find the class file priority and different paths: bootclassloader corresponds to the JRE/classes path, which is the place where the compiler first looks for the class
Extclassloader corresponds to the JRE/lib/EXT path, which is the place where the compiler first looks for the class.
Appclassloader corresponds to the current path, so it is also the place where the compiler finds the class by default.

In fact, you can write a simple program for testing, for any class, such as,
Call New A (). getclass (). getclassloader (). tostring () to print it out. If you put the class file in a different path and execute it again, you will see the difference. Note that if it is printed as null, it indicates the highest level of bootclassloader, because it is written in C ++ and does not have the name of the Class Loader corresponding to Java.

The order of search is a kind of thought, that is, if this level cannot be found, it can only be found above this level, rather than looking down. However, it seems that the features from jdk1.4 to jdk1.6 have changed and no details are found. So we will not give an example. I would like to tell you that sun designed this system as a technology core Mr. Gong Li, a purebred Chinese! Pai_^

In this way, we hope that you will not be confused why class files cannot be found in the general error reports, whether written by yourself or imported third-party jar files (which often needs to be imported in J2EE ).

3. About JDK and JRE --
You must choose whether to install a separate JRE when installing JDK. It is usually installed together. I also recommend that you do this. This helps you better understand the differences between them:

JRE is the Java Runtime Environment and the runtime environment of Java programs. Since it is running, of course it should contain JVM, that is, the familiar virtual machine, and all the class files of Java class libraries are packaged into jar in the lib directory. You can verify it by yourself. Which file is the virtual machine on windows? Anyone who has learned MFC knows what DLL files are. So let's see if there is a JVM. dll in JRE/bin/client? That is, virtual machines.

JDK is a Java development kit and a Java development kit that contains various class libraries and tools. Of course, it also includes another JRE. So why should we include another JRE? In addition, JDK/JRE/bin contains both the client and server folders and a JVM. dll. There are two virtual machines. I don't know if you have noticed this yet?

I believe everyone knows that JDK's bin contains the commands required by various Java programs. The most obvious difference with the bin directory of JRE is that javac is available under JDK, which is very understandable, because JRE is just a runtime environment. It has nothing to do with development. Because of this, JDK's own JRE with the development function will have a client JVM and a server JVM, in the JRE environment, only client JVM is required. DLL is enough.

Do you remember to set the JDK/bin path in the environment variable path? This should be the first step for everyone to learn java. The teacher will tell everyone that javac and Java will not be used if they are not set. The JDK/bin directory contains all the commands. But have you ever wondered whether the Java commands we use are not under the JDK/bin directory but under the JRE/bin directory? Do not believe that you can create an experiment. You can cut the java.exe file in the JDK/bindirectory to another place and run the Java program. What did you find? Everything is OK!

So someone will ask? I have not set the JRE/bin directory to the environment variable?

If Java is provided to most people, they don't need JDK for development, but they only need JRE to run the Java program, so every customer needs to manually set the environment variable. How troublesome is it? When jreinstallation is used, the installation program automatically adds jrejava.exe to the system variables. The verification method is simple. You can see that the system environment variable path is configured with "% SystemRoot %" system32; % SystemRoot %; "at the beginning, so let's go to Windows/system32 and check out what we found? There is a java.exe.

If JDK/bin can be forcibly moved to the front of the System32 variable, of course, the Java in JDK/JRE can also be forced. However, unless necessary, I do not recommend that you do this. Using a separate JRE to run a Java program is also a test in the customer environment.

Now, we should be more clear about the connection and differences between JDK and JRE?

PS: In fact, I still have many feelings to sum up. I am afraid that everyone will throw bricks to death at a time, and I am so sorry. We should be more steadfast and more pragmatic in doing some research and sharing experiences with each other. The general direction and too-cutting technology discussions are necessary, but we 'd better not be too many. After all, we have not laid a solid foundation yet, talking about the latest version is actually a major obstacle to progress!

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.

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 learning 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 no new things, 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, 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 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 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 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, 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 constitute, what are the purposes of these classes, and what functions are completed 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 remember the class method calls, but to understand, java provides us with classes, where each class is used, and 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 the HTTP protocol. The HTTP protocol has nothing to do with Java. If you are not familiar with the HTTP protocol, you can also learn Servlet/JSP programming well, but it cannot reach the same level. 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 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 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 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 implement them in different ways, 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 analyze them based on the 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, I didn't understand staic, public, private, Exception, try {} catch {} finally {} and so on at the beginning. They all succeeded in running the example above the reference books, then, I began to destroy it and constantly rewrite the program based on my questions to see if it could run, what it was like to run, and whether it could get the expected results. This is time-consuming, but an example program is destroyed several times in this way. I have completely learned the relevant knowledge. Sometimes you may even intentionally write some wrong code to run it and see if you can get the 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

It can be displayed where classes are loaded by JVM in sequence during command execution. These valuable debugging information can 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. If you encounter similar problems, just Copy & Paste, Search & Replace in the code library, which greatly improves the development speed. The ideal situation is to abstract some common routines to form a common class library and encapsulate them. 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 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 Java programs and 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.