Java entry knowledge

xiaoxiao2021-03-06  109

What is java? Why java?

Everything you have learned from Java, basically Java is a better object-oriented language, API rich

It is the current comparative mainstream programming language, J2SE / J2ME / J2EE has developed well in various development fields.

Java will not replace other development languages ​​or development platforms, such as C / C / C # or Delphi / .NET

Without the best language, there is only a relatively suitable language under certain applications.

JRE

Java 2 Runtime Environment, Java runtime environment

Includes Java Virtual Machine (JVM), and must-have libraries

It is a must-have environment running Java programs and web applets

It is included in J2SDK or downloaded separately (about 10m)

download link:

http://java.sun.com/getjava/download.html

JDK / SDK / J2SE

Java 2 Software Development Kit, Standard EDTION

It is an essential environment for developing Java, including tools such as compilers and a large number of libraries, and they will also bring them in general IDE.

download link:

http://java.sun.com/j2se/downloads.html

J2EE

Java 2 Platform, Enterprise Edition

It is the main technology of Java in enterprise applications, and it is also the most important application in Java.

Including JAXP, JAXR, JAX-RPC, Saaj, Jaas, JavaMail, JMS, JSF, JSP / Servlet, etc.

Develop J2EE, you can download the J2EESDK development package, and you will also bring it in general IDE.

Related Links:

http://java.sun.com/j2ee

J2ME

Java 2 Platform, Macro Edition

It is the main technique for Java applications to embedded systems (such as mobile phones)

Related Links:

http://java.sun.com/J2ME

Development method

The IDE (integrated development environment) on the market can greatly improve the development efficiency

But if you begin a Java, we recommend JDK EditPlus or UltraEdit

Although it is very simple, it can learn more solid

Premature dependence IDE will only let you give a little water, a semi-solving.

Even unable to master the basic syntax of Java

After mastering a solid foundation, it is easy to choose an IDE for development.

Learning or using Java, more Javadoc is very important (recommended using javadochelper, similar to MSDN interface)

Many problems in the version, in fact, slightly book is not a problem

Set an environment variable

After installing JDK, configure environment variables

WINDOWS 2000

My Computer -> Properties -> Advanced -> Environmental Variables

Add the following environment variables (assuming your Java installed in d: /java/j2sdk1.4.2)

Variable name value

Java_Home D: /java/j2sdk1.4.2

Represents the current directory, search the current directory

PATH ...;% java_home% / bin ... Represents the original PATH value

New open a DOS window, type Java and Javac test

Linux

The following is the redhat, Bash is slightly different, and the settings of the environment variable are available in the UNIX / Linux version.

Modify the .bash_profile in the user directory, such as vi ~ / .bash_profile

Java_home = / usr / local / java / j2sdk1.4.2

Classpath =.

PATH = $ PATH: $ java_home / bin

Export Java_Home ClassPath

Re-login, make this setting take effect, enter the Java Javac test on the terminal to test a simple test program

Code: --------------------------------

Public class test {

Public static void main (String [] args) {

System.out.println ("Hello World!");

}

}

-------------------------------------

Write with Tools such as Notepad, save it into test.java

note,

If your Windows setup 'does not show a known extension',

It is very likely to be saved into test.java.txt

Then in the command line tool, CD to Test.java, execute

Javac Test.java

Java Test

About Java learning

Getting started with Java, please see a system to explain Java books.

Book in this area, there are many markets in the market, the same size is different, and it doesn't matter.

But try to pick a book that speaks the grammar for high versions, don't choose "VJ Getting Started to Jing".

Recommended books such as Java in a nutshell, Java University tutorial, Java core technology, Java programming ideas, etc.

System learning Java's basic knowledge, must have practical practice, give yourself some to do some opportunities

Moderately remember some common API, do not over-reliance on the IDE code prompt

development tools

JBuilder

One of the most mainstream IDEs in the industry is the big brother of Java development tools.

The latest version of JBuilder 2005

Regardless of the development J2SE, J2ME, J2EE or XML / WebService is a tool

Foundation Edition can be downloaded for free, but less functionality

There is a circular version of the Internet, in order to avoid unnecessary trouble, please use carefully (especially in the company)

Related Links:

http://www.borland.com/products/jbuilder

Eclipse

Emerging Java IDE, free, open source, cross-platform, powerful, fast running speed

At the same time, you can extend the functionality of existing plugins by developing new plugins, such as adding in an existing Java development environment.

Enter the Tomcat server plugin.

Related Links:

http://www.eclipse.org

Ant

It is popular Java Build tool, "Everyone Should Use Ant"

Ant is not an IDE, but you can do a lot of IDE, such as compilation / packaging / deployment / unit test / CVS, etc.

For projects above medium-size, it must rely on many class libraries and have complex bag structures.

Treatment with Ant is excellent choice

Related Links:

http://ant.apache.org

JSP

Java Server Page, a technology for Java web development, and JavaScript has no relationship.

Servlet

Dynamic web technology appeared in JSP, similar to CGI, but using multi-threaded process requests.

JSP / Servlet and Java relationship

Servlet just inherits the Httpservlet's Java class, and JSP will eventually be compiled into servlet and execute.

Many problems encountered when developing Web, in fact, and JSP / servlet itself has no relationship, but ordinary Java asked

question. A qualified JSP / servlet programmer should first be qualified Java programmers.

It is recommended to take a solid Java foundation before learning and using JSP / servlet.

The following questions are not part of JSP / Servlet

Using the use of API, such as "How to get the int" How to get Current Time "" How to create thread "

. JDBC use and related precautions, such as "how to access mysql" "Why do I insert data is garbled". Other J2EE technology use, such as "How to use JavaMail" "How to Access EJB"

Recommended books

If possible, please read a system book to guide you to learn this technology.

I only have seen "JSP Advanced Programming" (Machinery Industry 2001, Liao Ruoxue)

The books published in other large publishers should be good, such as Wrox, O'Reilly, or domestic publishing house

When you choose a book, you should use JSP 1.2, servlet 2.3 specification or above.

Tomcat

This is an open source JSP / servlet server, which is a reference implementation of JSP / Servlet, suitable for beginners.

Homepage

Http://jakarta.apache.org/tomcat/

Tomcat 4.1 and Tomcat 5 are currently stable versions, the latter supports the latest JSP / Servlet standard

It is recommended to download the Zip version, decompress, run bin / starup.bat, you can display the server startup

If the startup fails, make sure that the Java environment of this machine is correct, see Java_Home and Path configuration

In the confed directory, the server is configured. WebApps is a directory for deploying websites.

Where should I write from the Java Class written?

Suppose your index.jsp location is x: /test/index.jsp, x: / test is your project directory

Test.class location should be x: /test/web-inf/classes/test.class

Where should liblic?

X: /test/web-inf/lib/mylib.jar

How to write a servlet

Package testservlet;

Import java.io. *;

Import javax.servlet.servletException;

Import javax.servlet.http. *;

Public class fooservlet extends httpservlet {

Protected Void Doget (HTTPSERVLETREQUEST REQ, HTTPSERVLETRESPONSE RESP)

Throws servletexception, ioException {

Resp.Getwriter (). Println ("Hi, I'm a servlet);

}

}

Compiled this Javac-ClassPath Servlet-Api.jar Fooservlet.java

Among them, this JAR can get from Tomcat-5.0.19 / Common / lib / servlet-api.jar

Compiled Class in x: /test/web-inf/classes/testServlet/fooservlet.class

Among them, TestServlet your name, you should try to write package, avoid inexplicably troublesome

Compile x: /test/web-inf/web.xml, modified

2.3 // en ""

http://java.sun.com/dtd/web-app_2_3.dtd ">

test

testservlet.fooservlet

test / foobar

Deploy this program to the server, such as copying x: / test / * to Tomcat / WebApps / Test / *

Open browser access

Http: // localhost: 8080 / test / foobar, will see a line of words smoothly

JSP shows what is garbled?

JSP's Chinese issues // do not include Chinese issues for JDBC read and write databases

1. The Chinese written in the JSP, such as

Chinese , but cannot be displayed

Solution to join the first line of JSP

<% @ Page ContentType = "text / html; charset = GB2312"%>

2. A Chinese is written in the form, such as

But you can't accept <% system.out.println (Request.GetParameter ("a"));%>

Solution to add one before processing parameters in JSP or Servlet

Request.SetCharacterencoding ("GB2312");

3.

http://host/a.jsp? Name = Name in the URL in Chinese is not available

Workaround should use the java.net.urlencoder class to turn this string to ASCII

How to achieve file upload

Common Java file upload API has

Jakarta Commons Fileupload

http://jakarta.apache.org/commons/fileupload/

COS

Smartupload

Download related files, usually Demo

JSTL and EL

Java Standard Tag LIB and Expression Language, respectively, respectively

It can greatly simplify the regular JSP development and make the page more concise, rather than full of Scriptlet

转载请注明原文地址:https://www.9cbs.com/read-102889.html

New Post(0)