Java always has a thousand benefits for you to choose from, but you can find the answer by simply turning over the book or visiting the internet. In this article, I will write some of my experiences and processes in learning Java for beginners to make a reference.
In the course of learning Java, I will focus on the following aspects:
1. Always remind yourself that Java is an OOP language tool, not just code. Only in this way can we grasp and use Java as a whole.
2. In the course of learning, it is best to understand the underlying mechanism of Java, rather than just staying on the surface, rather than running the example on the copybook to get the result. You must be patient in thinking about, debugging, and modifying a simple example.
3. In the course of learning, you must start and write code, instead of holding a book and reading it. Many things and experiences must be done by yourself to truly belong to yourself. It is best to participate in some practical projects.
4. After learning a certain stage, you begin to want to do something you have learned. At this time, you should begin to learn more and more complex knowledge, such as the construction of the J2EE platform and the Development of EJB. For this part, I suggest you find a thin book to understand it first, and have a general understanding in your mind to get a preliminary understanding of more technical terms. I think it is good to see J2EE technical practices at this stage. It can help you understand the various technologies and frameworks contained in J2EE and provide many practical examples to deepen your understanding of J2EE.
Interest and determination in learning Java play a key role. With the above basics, I began to learn Java step by step.
Build a Java environment (Java environment-JSP-mysql-Tomcat configuration)
To run a Java program, you must install JDK. JDK is the core of Java, including the Java compiler, JVM, a large number of Java tools, and Basic Java APIs.
Download jdk1.5133 from http://java.sun.com/j2se/1.5.0/download.jsp.
Decompress and install. Then, set the environment.
Jdk1.5 download URL
Http: // 192.18.97.238/ECOM/ecomticketservlet/tests/-2147483648/651374223/1/531770/531614/651374223/2ts +/westcoastfsend/jdk-1.5.0-oth-JPR/jdk-1.5.0-oth-JPR: 1/jdk-1_5_0-windows-i586.exe
Http://java.sun.com/j2se/1.5.0/download.jsp
Jcreator Pro 2.5 (with registration machine)
Http://www.java-cn.net/javatools/tools/jcpro250.zip
Jdk1.5 + jcreator Pro 2.5 is the best compiler for beginners.
1. Basic JDK Configuration:
Win2000, XP
Right-click "my computer", select "properties", and then select "advanced" to set "environment variables"
Path:
C:/program files/Java/jdk1.5.0 (actual JDK path)/bin;
Set java_home:
C:/program files/Java/jdk1.5.0; // JDK path
Classpath = C:/program files/Java/jdk1.5.0 (actual JDK path)/LIB;
(If you already have path and classpath, do not delete the original value and add it directly later .)
Win98:
In Win9x, modify the path and classpath variables of the autoexec. BAT file in the root directory of the system:
Set Path = % PATH %; C:/JDK 1.5/bin;
Set classpath =.; C:/JDK 1.5/LIB;
Run autoexec. bat again after saving the disk.
The following describes several important JDK commands:
◆ Java execution tool is a command to start JVM (Virtual Machine) and execute the class (byte code) file;
◆ Javac compiler, which is generated by the. Java file. Class file;
◆ Jar Java compression and packaging tools;
◆ Javadoc document builder.
The last step is JDK documentation. This is JDK's online help document and is the most useful and important learning reference document.
2. tomcat configuration:
(1) set environment variables:
Tomcat_home = F:/tomcat
Catalina_home = F:/tomcat
Java_home = C:/program files (installation path, which is the default path)/Java/jdk1.5.0;
Set classpath = F:/tomcat/lib
If you want to start Tomcat with the command line, set Path = "F:/tomcat"
(2) Enter http: // localhost: 8080 or http: // 127.0.0.1: 8080 in the browser.
If you can see the tomcat version 4.0 page, it indicates that Tomcat is successfully installed.
(3) tomcat configuration files are in the/conf directory. The main configuration file is server. xml:
Change the server listening port: Find <parammeter name = "Port" value = "8080"/>. The value of the vaule attribute is the port number,
It can be changed.
Add a virtual path (Service ):
<Context Path = "/Examples" docbase = "Examples" DEBUG = "0"
Reloadable = "true">
<Logger classname = "org. Apache. Catalina. Logger. filelogger"
Prefix = "localhost_examples_log." suffix = ". txt"
Timestamp = "true"/>
<EJB name = "EJB/emplrecord" type = "entity"
Home = "com. Wombat. EMPL. employeerecordhome"
Remote = "com. Wombat. EMPL. employeerecord"/>
<Environment name = "maxexemptions" type = "Java. Lang. Integer"
Value = "15"/>
<Parameter name = "context. Param. Name" value = "context. Param. Value"
Override = "false"/>
<Resource Name = "JDBC/employeeappdb" auth = "servlet"
Type = "javax. SQL. datasource"/>
<Resourceparams name = "JDBC/testdb">
<Parameter> <Name> User </Name> <value> SA </value> </parameter>
<Parameter> <Name> password </Name> <value> </parameter>
<Parameter> <Name> driverclassname </Name>
<Value> org. hsql. jdbcdriver </value> </parameter>
<Parameter> <Name> drivername </Name>
<Value> JDBC: hypersonicsql: database </value> </parameter>
</Resourceparams>
</Context>
<Context Path = "/myexamples" docbase = "F:/myexamples" DEBUG = "0"
Reloadable = "true">
</Context>
In the preceding example, a service is added: path indicates the URL path of the service, and docbase indicates that
Path on the hard disk. Debug indicates whether debugging is allowed, and reloadable indicates whether to automatically reload the servlet.
Using MySQL database: Download The JDBC driver of MySQL, put the MM. mysql-2.0.4-bin.jar (some versions are
Mysql-connector-java-3.0.9-stable-bin.jar) to Tomcat installation path under the lib directory.
The JSP program to be tested is as follows:
<% @ Page contenttype = "text/html; charset = gb2312" %>
<%
// Statement
Java. SQL. Connection sqlconn; // database connection object
Java. SQL. Statement sqlstmt; // statement object
Java. SQL. resultset sqlrst; // result set object
// Register the JDBC driver
Class. forname ("org. gjt. Mm. MySQL. Driver"). newinstance ();
// Connect to the database
Sqlconn = java. SQL. drivermanager. getconnection ("JDBC: mysql: // localhost/MySQL", "root", "root ");
// Create a statement object
Sqlstmt = sqlconn. createstatement (Java. SQL. resultset. type_scroll_insensitive, java. SQL. resultset. concur_read_only );
// Execute the SQL statement
Sqlrst = sqlstmt.exe cutequery ("select * from user ");
%>
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> Linux-JSP-jdbc-mysql test-select </title>
</Head>
<Body>
<Table border = "1" cellspacing = "0" cellpadding = "0" align = "center">
<Tr>
<TH> name </Th>
<TH> age </Th>
</Tr>
<% While (sqlrst. Next () {%>
<Tr>
<TD> <% = sqlrst. getstring (1) %> </TD>
<TD> <% = sqlrst. getstring (1) %> </TD>
</Tr>
<% }%>
</Table>
</Body>
</Html>
<%
// Close the result set object
Sqlrst. Close ();
// Close the statement object
Sqlstmt. Close ();
// Close the database connection
Sqlconn. Close ();
%>
3. install ApacheClick the file apache_2.0.47-win32-x86-no_ssl.msi to install, select the target directory: G:/amicrasy/myweb /... (Several services are installed in this directory ,... the directory name of the corresponding service, as shown in the following figure ).
Go to G:/amicrasy/myweb/Apache Group/apache2/CONF/httpd. conf and modify httpd. conf.
----------------------------------------
# Userdir "My Documents/my website" // added above #
Adddefacharcharset gb2312 // default encoding
Directoryindex index.html index.htm index. php index. jsp // default page
----------------------------------------
Start monitor Apache servers. Apache installation is complete at this time.
4. Install MySQL
Open setup. EXE in the mysql-4.0.12-win directory for installation, and select: G:/amicrasy/myweb /.... After the installation is complete, restart the computer and start winmysqladmin. MySQL can be started at this time.
After MySQL is started, perform the following operations to try MYSQL:
Start-> Run-> "cmd" and enter the following command:
G:
CD amicrasy/myweb/MySQL/bin
MySQL
Show databases;
Use MySQL;
Show tabales
Select host, user, password from user
Select User ();
Create Database mydata;
Drop database mydata;
Quit;
Exit
Through these operations, we can perform simple MySQL operations.
4. PHP installation
Copy the php-4.3.2-Win32 directory to the directory G:/amicrasy/myweb/... and change the directory name to PhP.
Next, configure G:/amicrasy/myweb/PHP, change the file name PHP. ini-Dist to PhP. ini, open PHP. ini, and modify the parameters:
----------------------------------------
Session. save_path C:/Windows/temp
----------------------------------------
Note: C:/Windows/temp. the Windows directory varies depending on the installed operating system. For example, if Win2000 is used, this directory is winnt. This temp directory must exist and will usually exist, this setting is critical because PHP is installed in windows and session configuration fails.
Then copy PHP. ini to C:/Windows (Windows 9x/ME/XP) C:/WINNT (Windows NT/2000 ).
Finally, php4ts. DLL to C:/Windows/system (for Windows 9x/ME) C:/winnt/system32 (for Windows NT/2000) C:/Windows/system32 (for Windows XP ).
So far, PHP installation and configuration are basically complete. Next, you need to configure Apache so that it can use PHP.
Enter G:/amicrasy/myweb/Apache Group/apache2/CONF/httpd. conf to modify httpd. conf and add the following code:
----------------------------------------
Loadmodule php4_module "G:/amicrasy/myweb/PHP/SAPI/php4apache2. dll"
Addtype application/X-httpd-PHP. php
----------------------------------------
// Note that the above G:/amicrasy/myweb/PHP/SAPI/php4apache2. dll varies according to the PHP Directory copied earlier.
At this point, our configuration is complete. Next we will test it:
Compile the test file info. php (copy to the directory G:/amicrasy/myweb/Apache Group/apache2/htdocs/). The file content is as follows: (just one line)
----------------------------------------
----------------------------------------
Restart Apache and start IE. Enter http: // localhost/info. php in the address bar to view the page.
For the installation and configuration of Apache and PHP, see the following two official PHP website Installation Guide: link 1, link 2.
Http://www.php.net/manual/zh/install.apache2.php#install.apache2.windows
Http://www.php.net/manual/zh/install.windows.php
Next we can download some source code programs for PHP + MySQL from the website, and try again. I downloaded a discuz! 2.0 of the Forum tried and completed successfully. All these programs are done online. You only need to configure a configuration file and enter the MySQL account and password. You do not need to set the other configuration files, then run install. PHP, including databases and tables, will help you build a PHP + MySQL Forum. Then, download an article program and a message program in the zone and modify the interface, A good personal website is coming out. Haha.
We have introduced the installation of Apache + MySQL + PHP on Windows systems. Next we need to enable Apache to run JSP.
Start writing your own code
Now that the environment is ready, you should write a simple code for testing. Or from the classic "Hello word.
1. First Use the editor to write a code (I use the Linux VI ):
[Stone @ coremsg work] $ VI hello. Java
Public class Hello {
Public static void main (string [] argc ){
System. Out. println ("Hello word! ");
}
}
2. Compile:
[Stone @ coremsg work] $ javac hello. Java
3. Execute:
[Stone @ coremsg work] $ Java hello
Hello word!
Successful! This is my first Java program. Since then, I know that I have started to enter the Java World, and then I will rely on my own efforts. In this process, I think there are several points worth attention.
Learning a new language is inseparable from reference books. My advice is to find a short getting started book to learn the simplest and most basic things, including learning Java syntax. At the same time, debugging should be performed on the simplest program. Think about the result if you change it? Why must I write that? Think more about these problems and then perform operations, which will give you more gains. It is useful to think over and over again. In addition, you should also look at the online help of JDK at this stage to learn as much as possible about the Java basic class library API provided by JDK.
After you have basic knowledge and can write some simple programs, you can start reading thinking in Java. It fully introduces Java syntax, object-oriented features, core class libraries, and so on. Through this level of learning, we can deepen our understanding of Java and the use of underlying principles, while at the same time, we can fully understand the entire Java System. At this stage, we should focus on learning the features of Java's object-oriented programming language, for example, inheritance, constructor, abstract class, interface, method polymorphism, overload, overwrite, Java exception handling mechanism, etc. You must have a very clear understanding of the above concepts. The purpose of doing so is to apply these technologies to practice for rational programming (for example, you will consider whether a class is designed using abstraction or interfaces ). This requires that you must apply and learn in a large number of practices. This is also the advice that many of my friends gave me.
Learn more
If you want to use Java to complete a variety of more powerful tasks, you need to learn more than the language.
1. Java Web Programming
For Java Web programming, you must be familiar with and master the HTTP protocol. For details, refer to chapter 3 of the TCP/IP explanation by Steven S. Java Servlet technology provides the ability to generate dynamic web page content, which is one of the most basic functions in your Java project, so you must learn. Through this phase of learning, you should master the WEB programming of Servlet/JSP.
2. J2EE Learning
There are too many technologies in J2EE. If you want to sit next to a table and hold a lot of books to learn, it will not be very effective. I suggest that you follow the steps below when you start learning at this stage. The general idea is "overall control, break through each other ".
◆ Understand the meanings of technical terms in J2EE.
I think there are a lot of technologies involved in the J2EE standard. It would be unrealistic and ineffective to learn them one by one at the beginning. My suggestion is to have a rough understanding of the technologies, such as EJB, javaidl, and JTA. Maybe you don't know how to write an EJB, but you need to know what EJB is and what it can do. With this concept, it will be much faster to learn it purposefully. I want to repeat it again-it must be done in practice.
◆ Understand the design pattern in J2EE, which helps you grasp J2EE as a whole.
The MVC development mode has been proved to be one of the effective solutions. It can separate data access and data performance. You can develop a scalable and scalable controller to maintain the entire process. At this level of learning, when you are facing a project, you should first grasp its overall architecture design and decide which technologies adopt the J2EE standard.
◆ Understand some typical cases of the J2EE platform and deepen the concept and understanding of this technology.
I usually pay more attention to this aspect. I am familiar with some typical cases and analyze why it should be used at that time? What is the purpose of doing so? Then contact your project for reference.
◆ Learn various technologies under J2EE.
After several stages of learning, you can build a J2EE platform and start learning each technology. You can participate in company-related projects or build a platform on your own. At this time, you should find related books to learn them step by step. There is no shortcut. If you are not satisfied with this, you should also learn more about UML and design patterns.