Java entry and FAQ

xiaoxiao2021-03-06  128

Java entry and FAQ

I. Getting started 1, download and install J2SDK http://java.sun.com/j2se/1.4.1/download .html 2 java vm 3 API http://java.sun.com/api/index.html 1 first download J2SDK installation a Update Path environment variables for You can perform Java commands (such as Javac, Java, etch) in any directory, you need to put Java's bin directory into the PATH environment variable. For Windows95 / 98, open the Start menu, select "Run", enter the command sysedit (call the system configuration editor), find the PATH settings in the C: /autoexec.bat window (C: /JDK1.3.1) _01 / bin) For Windows NT and Windows 2000, enter the Start menu, select Set / Control Panel / System. For Windows NT, select the Environment page, for Windows 2000, select "Advanced" page, add in the user variable bar in the environment variable setting (if there is no PATH) or modify the PATH environment variable, make it included in C: / JDK1 .3.1_01 / bin path. b Update ClassPath Environment Variables In order to enable the system to find user-defined classes, you need to place the directory where the user class is located (usually the current directory is added to the classpath) is placed in the ClassPath variable. The specific changes method is used to modify the process, just to find the ClassPath environment variable for modification. Environment variable settings under JDK WIN2000

There is an environment variable setting in the advanced option of the properties of My Computer. 1) Adding a bin access path after the system environment variable Path parameter. For example, if it is directly installed under the C disk, add C: /jdk1.3.1/bin after the Path parameter. The results of the addition is generally:% systemroot% / system32;% systemroot%;% systemroot% / system32 / wbem; c: /jdk1.3.1/bin. 2) Creating a new system environment variable ClassPath, assigns its value to:.; C: /jdk1.3.1/lib/tools.jar; C: /jdk1.3.1/lib/dt.jar; C: /JDK1.3.1/ JRE / lib / dt.jar; D: / javaprogramming / where D: / javaprogramming / is the storage directory of the Java source program. Note: In the name of the source program of the source program, the name of the source program of the source, the same, that is to say that the java command is not ignored. In addition, the program name behind the java command is not to bring .class!

c Confirm that the system is installed under the DOS prompt, enter the set command to see if the PATH and CLASSPATH settings are successful (if it is 98 to run autoexec.bat to make the modified settings take effect if it is 2000 to turn DOS to turn off Re-Run) 2 Run your first Java program to write a class saved as .java file must remember if you save the name of the Notepad Editor, choose Save Types for all types and file names and your class names or you can Name .java plus quotation marks to avoid saving to .java.txt type 3 Frequent Error handle If you run the javac command When can not read xxx.java appears to see if your file is saved as .java.txt type. (The expansion name in the right point file is remembered, remember to save the file name .java plus quotation marks. If you run the java command, prompt Exception in Thread "Main" java.lang.noclassdeffounderroe: The exception indicates that you have not added in your classpath.

2 Exception in thread "main" java.lang.noclassdeffounderroe: indicating that you have not joined in your classpath.

3 Where is the difference between "==" and "equals ()"?

"==" is a fixed operator in Java, used to determine whether it is equal, and the usage comparison is single because of the basic type (int, char, boolean et al.), And "==" compares the object. In fact, it is the handle of the object (or the comparison of the address), so even if the content of the object is the same as "==", it is also different (unless: Object a = new Object () ojbect b = a ; if (a == b) system.out.println ("true"); in the case of the above program, the execution result is printed "TRUE"). Equals () methods have all objects in Java, because all classes in Java extends Object, so all classes may override the equals () method (object-oriented polymorphism), so equals () The method is also a comparison of two objects, but because the implementation methods in each class are different, it is not the same, as the content of the comparison is different, just like the String object of the upstairs String object () is used to compare the string object The contained string value is equal. Conclusion: == Usage Compare Single, is a inherent operator equals () method is a certain feature that can compare two objects as needed, very wide

4 StringBuffer S1 = New StringBuffer ("a"); StringBuffer S2 = New StringBuffer ("a"); S1.Equals (S2) // Why is FalseString S1 = New String ("a"); string s2 = new string "a"); s1.equals (s2) // Why is TRUE

In fact, it is very simple, I will summarize it. First, String's Equals method is to override Object, so string a = new string ("ss"); string b = new string ("ss"); generated two objects, but a.equals (b) = true, Compare the value. Second, StringBuffer's equals method does not override the object of Object, so StringBuffer a = new stringbuffer ("ss"); StringBuffer B = New StringBuffer ("ss"); "SS"); , Compare the address. Third, the equal sign is the address, string a = "a"; string b = a; only one object A == B true. StringBuffer A = New StringBuffer ("a"); stringbuffer b = a; also generates an object a == b true. Fourth, string a = "ss"; string b = "s"; a.equals (b) = true a == b true because it is also an object. This is because only one object "SS" is generated when compiling. String a = new string ("ss"); string b = new string ("ss"); a.equals (b) = true, no doubt, a == b false. Because A, B is an object that is generated at runtime, two objects have been generated. Important: Compile objects and run objects. 5. What is Java Web Start? See here http://java.sun.com/products/javawe...adme_zh_cn.html

6 Trim () function usage

Use an object. Such as: string aa; aa = "aaaa"; AA = aa.trim (); aa return "aaaa". It is the front and rear spaces of the string.

7 How to extract the system time?

Date mydate = new date (system.currenttimemillis ()); // this time format is your local time format.system.out.println (MyDate.ToString ()); // used the simple format to get the string you want. // The Valid String, You CAN Reference The JDK DocSimpleDateFormat SDATEFORMAT = New SimpleDateFormat ("YYYY / MM / DD HH: MM: SS"); system.out.println (sdateformat.format (mydate);

Use Date and SimpleDateFormat to get any format time, and a stronger class is Calendar, which will be discussed below.

9 Date display formatted

Example: Import java.util. *; Import java.text. *; Public class formatdate {public static void main (string [] args) {Date now = new date ();

DateFormat defaultFormat = DateFormat.getDateInstance (); DateFormat shortFormat = DateFormat.getDateInstance (DateFormat.SHORT); DateFormat mediumFormat = DateFormat.getDateInstance (DateFormat.MEDIUM); DateFormat longFormat = DateFormat.getDateInstance (DateFormat.LONG); DateFormat fullFormat = DateFormat. getDateInstance (DateFormat.FULL); String defaultDate = defaultFormat.format (now); String shortDate = shortFormat.format (now); String mediumDate = mediumFormat.format (now); String longDate = longFormat.format (now); String fullDate = Fullformat.format (now); system.out.println ("(default) Today:" defaultdate); system.out.println ("(Short) Today:" shortdate); system.out.println ("(Medium ); System.out.println ("(long) Today:" longdate); system.out.println ("(full) Today:" fulldate);}}

Run results: D: / javamail> Java formatdate (default) Today: 2003-6-15 (short) Today: 03-6-15 (Medium) Today: 2003-6-15 (long) Today: June 2003 15th (full) Today: Sunday, June 15, 2003

10 What is the difference between static and non-static nesses?

Static Internal Class Means: 1 Create an object of the Static internal class, no need to access an external class object from an object from one Static internal class

11 How to judge the input Dongdong is a character or a number?

Float.Parsefloat (String Data) is parsed to have NumberFormatexception throwing is not a number.

If you use streamTokenizer, there is streamTokenizer.ttype, you can judge whether it is a number. You can also determine if there is a number of characters. CHARACTER Class STATIC Boolean Isdigit (Char CH) determines if the specified character is a digit.

Static Boolean Isletter (Char CH) DETERMINES IF THE SPECified Character Is A Letter.

Static Boolean IsletterOrdigit (Char CH) DETERMINES IF THE SPECified Character Is A Letter or Digit.

Static Boolean IsWhitespace (Char CH) DETERMINES IX SPECified TO JAVA.12 FINALIZE () and System.gc () Difference

Finalize () is automatically called by JVM, you can use system.gc (), but JVM does not necessarily execute immediately, and JVM feels that the memory is limited, and finalize () will begin to perform the number of new objects and The number of collected is different because the collected object is only related to JVM's garbage collection strategy, and Finalize () is just a method in chair (), which is not associated with CHAIR ().

13 How to enter 2 on the keyboard .... actually printed 50 ??? system.in.read () usage

Import java.io. *; public class test {public static void main (string [] args) throws ioException {int S [] = new int [10]; s [0] = system.in.read (); // Correct should be changed to s [0] = integer.parseint (args [0]); system.out.println (s [0]);}}

Printing is an ASCII code value corresponding to characters on the keyboard, such as you enter A. The output is 97. In addition: Integer.Parseint (String) is a string to make a parameter, return the symbolful INT type, system.in.read () is an integer between 0-255, to represent the ASCII code, although both Int, but the meaning is different.

What is an object-oriented design idea?

What is an object-oriented design idea? There may also have many beginners who don't understand this concept, especially this era in the alternating thought, many people have just learned that it seems to be eliminated.

Language. Their brain has not been detached from the binding of process thoughts, but looking up, "object-oriented" has already been popular

Open, this strange word is flourishing. Just pick up a popular computer technology book, there will be no "object-oriented"

Word eye! So I am confused: What is "object-oriented"? Don't be interested, have passed;

The development of development, hurry to find a book for books, what is "object-oriented". However, to break through the shackles of thought,

It is not difficult to say that it is not easy to understand. After doing some lightweight work, I am very concerned.

Get, not afraid of ridiculous, writing has been made by the majority of peers.

"Object", the word "Object), as early as the nineteenth century, there is a phenomenological master Hussell proposed and defined. Object is the world

The image of the object in the human brain is the reason why people's conscious reflection is to be a concept.

Things to read, it also includes people's will. For example. When we realize a new object, it is a tree,

It has formed a tree concept in our consciousness. This concept will always exist in our thinking and will not

It disappeared for this tree. This concept is the image of the object in the real world in our consciousness. We

It can also have our own will, although we don't need to achieve it - as long as you think this tree in your mind

Cut off the table, stool, etc. - we call it intention. So, the object is the object of object in the world in the human brain.

Image and human intention. As long as this object is there in our thinking consciousness, we can judge the same kind of east.

WEAT. For example, when we see another tree is, it will not know this tree because the first tree seen is not losing the reference template. When we come into contact with certain new things, our awareness will establish an object for these things.

. Of course, this process is formed, that is not what we can discuss.

The objects mentioned above have a general problem, so it can be pushed to everything. We often

The "object", a class refers to the method of solving problems encountered in the information field. Especially for application software technology

Problem method. As we often encounter, object-oriented programming, right-oriented

Object-Oriented Analysis, object-oriented design (Object-Oriented Design). application

The concepts of the objects described above can be further analyzed for these issues. In the face of more complex systems, I

They can analyze it as an object. A system (a full set of solutions to a problem) as a

Objects can be composed of multiple parts. Again, this object can also be composed of multiple objects. For similar things,

Expressed by an object. The benefits of doing this are obvious, it is flexible and efficient, can greatly reduce designers

The workload, simplifies the actual model. for instance. In the design of the relational database, we can put a yuan

The group is treated as an object to define a set of operation methods. These methods will apply to all tuples, so we don't have to be larger

Delicate different tuples in the range (if it is legal if it is legal): because they have a set of public

The method of itself, they "I can" solve "my own problems. More on the last layer can be a table, view

Wait. Table objects have their own methods on the basis of tuple objects, such as increasing, deleting, etc. From this level,

It only needs to do "own" things, because there is a support of the group object, it does not need to consider whether or not the elements are legal.

Best. Even, sometimes in order to meet the elements or table groups as timing objects and define their own methods.

This makes it possible to display object-oriented advantages.

The above discussed can be said to be an object-oriented analysis method. In the specific design process, it should also be appropriate.

The way. Because of the object-oriented thought is very advanced, if you do bad, you can also achieve the expected results.

This is mainly manifested in the relationship between processing objects and objects, and the object is not clear. As mentioned above

Relational database, exemplified, if the object is too much in the meta level, a table object is considered, or a surface layer

The objects on the face consider the factors of a tuple object, and even consider the factors on the element level, these are not good.

Object-oriented design method. This, in terms of language implementation, Java is more advantageous than C because it does not allow multiple

Reinforcement, thus makes the relationship between the objects more clear. No one will deny that C is more powerful, but it has to be

Pay great costs - When the code library has developed to a certain level, the hierarchical relationship between an object will be

Being abnormally complicated, given a lot of difficulties, it is difficult to understand, it is difficult to understand. In addition, although

C has an object-oriented processing power, but it still retains a lot of process. Can not use C

Object-oriented ideas for programming, of course, people will not do this - except for those who just regard C as c

The initiator expanded, this buried hidden dangers for future development. On the one hand, Java's limit is more. Be

Point is far from enough. What is developed is human, and the development method is determined by people. To apply an object-oriented approach to developing excellent software, you must ask the developer to have a good object-oriented thought. Good engineers can use the appropriate tools to open

Send excellent software - not the language tools he use - Java, C , Object Pascal, ADA, etc.

It is necessary to apply systematic analysis, design, implementation (programming), first requiring developers.

The member knows what is an object, what is an object-oriented concept, otherwise it is not to apply the application for object-oriented ideas to engage in software development

. I hope that the reader can see that I am not very strict, detailed discussion, can be paired by one.

A preliminary understanding also hopes to have a criticism with different opinions. Second, it also requires developers to have a relatively rich opening.

Experience. Otherwise, the theory of light talk is not to truly understand the meaning of "object-oriented". Despite this, we are still

The general rules can be set. Those out of other stages of the life cycle, the following can generally perform the following

Process:

First, first apply the object-oriented thought to systematically analyze. Careful division of the system, clarify it

The hierarchical relationship between them, and then various parts are functionally analyzed as an object. For example, to design a use

The user interface, it may consist of several major forms: main form mainframe, functional sub-form FunctionFrame

And dialog dialog Dialog. Among them, MAINFRAME may also include menus, toolbars, text boxes, status bars, etc.

Windows components. For components to complete some important features, we can treat it as an object alone.

In the specific implementation, use a single class alone. And some are not very important, just the group you need in the process

For you can integrate them into other objects. To clarify each object's own task - don't let it have a defect,

You can't get it more. The relationship between the objects is achieved by coupling process, content, and function.

In fact, if you develop with Java, you will find that the Swing component itself is very easy because they

The relationship is very clear - you don't have to understand the complex relationships as components in C . Develop you

When you have a component, you also need to achieve this effect.

Second, the application of object-oriented thinking is used for system design. In fact, after really doing systematic analysis,

It is relatively easy to design. This time as long as it further determines the function of each object and the relationship between the various objects

. In order to better help realize people understand the relationship between the objects, you can use some tools to put these components

The relationship is expressed, unified model language (UML) is such a good east

WEAT. It can not only help developers understand the entire system, but also provide a file file for future maintenance work.

Greatly, it provides huge convenience.

Third, implement (encoding). This is not too much to say. In my next article, it will give a relatively simple

Single instance, I hope to be inspired by the reader.

When you engage in software development, the code is not the most important. Analysis, design is the most important. Maybe when we accept one

After some more advanced thinking, it will be more understanding. I hope that our China's software developers can apply object-oriented

The idea has developed an excellent software with international competitiveness.

How to get the IP of this unit

Import java.net. *; public class getselfip {public getselfip () {} public static void main (String [] args) {inetaddress host = inetaddress.getByname (null); // Get the local ip address ..... ...}}}} inetaddress The following three methods: getAllByName (String), getByname (String), getLocalHost ()

What is the difference between Throw and Throws? Throw is used to throw Exception, in the method, and throws is used to declare the possible Exception, in the statement of the class or method

How to generate .jar files?

Usage: jar {ctxu} [VFM0M] [JAR- File] [Manifest- File] [-c Directory] File Name ... Option: -c Create a new archive -T list of the list of archived contents -X Expand Named (or all) file -U update existing archive -V generation detailed output to standard output -f specified archive file name -M contains flag information from the indicate file - 0 only storage method; unused zip compression Format -M does not generate a list of all items (Manifest) file-i generates index information -c to change to the specified directory for the specified JAR file, and contains the following file: If a file name is a directory, it will be recursively processed. The list (manifest) file name and archive file name need to be specified, press the same order as specified by 'm' and 'f' flags. Example 1: Archive two Class files into the archive file called 'classes.jar' : JAR CVF CLASS.JAR FOO.CLASS BAR.CLASS Example 2: Archive all files in the foo / directory into a archive file named 'Classes.jar' with an existing list (manifest) file 'mymanifest'. JAR CVFM Classes.jar mymanifest -c foo /. example 3: jar -cvf zhz.jar Hello.class

Excellent article website recommendation: 1 How to quickly become a Java master [Tomjava original] http://www.java.com.cn/showtopic.as...719&Forum_id=31

2. If an old engineer (giving the ten advice of young electronic engineer) http://www.pconline.com.cn/pcjob/it...312/261734.html

3. A large number of Java program examples, Examples for Almost All Java Classeshtp: //javaalmanac.com/egs/

4. The Java Tutorial on sunhttp: //java.sun.com/docs/books/tutorial/

5. Talk to Java's learning direction (reproduced) http://www.430000.net/printpage.asp?teliciD=46

6. Java learning path http://www.9cbs.net/develop/author/cxy/way_to_java.shtm

7. Java Program Code Specification from Suncode Conventions for The Javatm Programming Languagehttp: //java.sun.com/docs/codeconv/h...onvtoc.doc.html

8. Java program code specification from IBMHTTP: //www-900.ibm.com/developerWor...ard/index.shtml9. 50 advice to C beginners Good for java toohttp: //post.baidu.com/ f? kz = 647098

10. Articles useful for beginners http://www.mifun.net/pengjie/myweb/...?id=95&sort=jsp

11. Question Wisdom How To ask quest: http://www.catb.org/~esr/faqs/smart-questions.html Chinese version: http://alfredy.myetang.com/

12. From Coding Fan to the real technical expert http://www.chinajavaworld.net/forum...ic=12814&show=0

Java novice must read, some entry knowledge

1, JDK is J2SE, JDK1.1.8 version changed to J2SE, download address: http://java.sun.com/j2se/downloads.html2,jre is a Java runtime environment (JRE after JDK1.3) You don't have to download 3 separately, set the environment variable After installing JDK, you want to configure the environment variable My Computer -> Properties -> Advanced -> Environment Variable Add the following environment variable (assuming your Java installation in c: /jdk1.3) java_home = C: /jdk1.3classpath = .; c: /jdk1.3/lib/dt.jar; c: /jdk1.3/lib/tools.jar; (.; can not be less, because it represents the current path) Path = C: /jdk1.3/bin newly open a DOS window, type Java and Javac test 4, simple test programs

Code: ------------------------------------------------ -------------------------------- Public Class Test {public static void main (string args []) {system.out .Println ("Hello World!");}} ---------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------

Javac Test.javajava Test

5, Java, J2EE, XML development common tool introduction

J2SDK installer and Java API DOC J2SDK-1_4_0 for WIN J2SDK-1_4_0 for Linux J2SDK-1_4_0-DOC J2SDKEE-1.3-DOC

Can go to http://java.sun.com/j2ee/download.html download

6. Build Tool Ant: Ant is a Java-based cross-platform build tool. The reason that Ant can cross the platform because Ant no longer needs you to write shell commands, Ant's profile is XML-based task tree, which allows you to run a variety of tasks, the task run is the implementation of a specific task interface Objects are completed.

http://jakarta.apache.org/ant

7. Development tool (IDE, integrated development environment) 1. Development tools preferred two 1. JBuilder - don't have to say 2, NetBeans (download address www.netbeans.org, free), Forte is Sun Ee and NetBeans Similar (estimated to be rewritten using NetBeans), but NetBeans (3.4 version) I think it is better to integrate with Tomcat and CVS, but the only shortcomings cannot develop EJB. Forte is ok, but can't give Out of our own writings (i.e., the methods after the way is the system, and our own way, FAINT) Other development tools Eclipse: Names the future of any language developed IDE integrator. Eclipse is the next-generation IDE development environment that replaces IBM Visual Age for Java (hereinafter referred to as Ivj), but its future goal is not only a IDE environment specializing in developing Java programs, but it can expand according to the eclipse architecture, it can expand To any language, it can even be a tool drawn. Currently, Eclipse has begun to provide a function plug in C language development. It's more difficult to expensive, Eclipse is an open source project, anyone can download the source code of Eclipse, and develop its own function plugin on this basis. That is to say, as long as someone needs it, there will be a development plugin that is built in languages ​​such as COBOL, Perl, Python, Eclipse. At the same time, you can extend the functionality of the existing plug-in by developing new plugins, such as adding Tomcat server plugins in an existing Java development environment. You can expand unlimited, and there is a unified look, operation, and system resource management, which is also the potential of Eclipse. Http://www.eclipse.org8, professional XML editing tool XMLSPY: Support SOAP; support Oracle XML Schema extension; support MSXML4, etc., provide three XML document views: structure display and editing, original code view, support CSS, XSL Preview. Supports the latest Schema standard, can convert Different Schema versions of the SCHEMA document into a document that meets the latest SCHEMA specification according to the SCHEMA Version XML document, can convert DTDS, XML-DATA, or BIZTALK Schemas to W3C Xmlschema from database connection (ADO, ODBC) The XML Schema can directly access the database, providing the transition between the database and XML to provide a user interface similar to Office XP Compatible provides a more convenient user interface customization method. The editor supports the text editing of the younsorship, based on Form Data input, graphic elements, etc., including a graphical XSLT generator, can generate a style document for Schema or DTD, and finally applied to the corresponding XML document.

Can go http://www.xmlspy.com/download.html to download 9, Framework

COCOON: XML Framework Cocoon is a content publishing framework written in 100% pure Java. CoCoon allows you to provide web content with the latest technology (DOM, XML, XSL) of W3C. The new Cocoon mode fully separated document content, style, processing logic, allowing these three layers to be independently designed, created and managed, thereby reducing management overhead, strengthening the reuse of work, reducing development time.

Source: http://xml.apache.org/cocoon

9, Struts: JSP Framework Struts is the open source of the open source of the web application using Java Servlet / JavaServer Pages technology. The Struts can develop an application architecture based on MODEL-View-Controller design mode. Struts has the following main functions: • Contains a Controller Servlet to send the user's request to the corresponding Action object. · JSP free Tag library, and provides association support in the Controller Servlet to help developers create interactive form applications. · Provides a range of practical objects: XML processing, automatically handle JavaBeans property, international tips and messages through Java Reflection APIs. Source: http://jakarta.apache.org/struts

10, Turbine: Servlet Framework Turbine is a servlet-based Framework, making experienced Java developers to quickly build web applications. With Turbine, you can integrate existing template techniques (such as Velocity, Webmacro, Java Server Pages (JSP), FreeMarker, Cocoon by creating Screen of Templates using specific services.

Source: http://jakarta.apache.org/turbine 11, Demo

Java Pet Store: J2EE Application Sample Java Pet Store is a J2EE enterprise application sample for Java Software Blueprint Planning. It demonstrates how to apply the power of J2EE platform to build a flexible, stretchable cross-platform business application. You can get the latest information and learning materials from java.sun.com/blueprints/enterprise/, the latest version is based on J2EE 1.3 1.3_01.

Source: http://java.sun.com/blueprints/enterprise/

12, Database

PointBase: A new army into the enterprise-class database market. PointBase is the first 100% pure Java database that can be used for any platform for any Java 2 Standard Edition Virtual Machine (JVM).

Source: http://www.pointbase.com/13, j2ee server1, j2sdkee1.3.1 Referrence Implement (J2EE Reference Implementation), a good learning J2EE tool, remember, this is a learning tool is not a The tools developed by the company, because of its efficiency, safety, etc., so you can't use it to do projects or products. http://java.sun.com/j2ee/download.html2,weblogic and WebSphere don't have to say more! 3, Sun One Application Server --- strongly recommended inside is a comparative completion J2EE development platform 1, Sun One Studio 4 (predecessor Forte) 2, Tomcat 43, Sun ONE Application Server A better J2EE Server4, And J2EE RI integration 5, PointBase is the first authenticated 100% pure Java database These tools can develop any Java products, the most important thing is that it is a free J2EE server, and is free than JBoss For it, I don't know where to go, haha, this live will be sent! ! ! http://wwws.sun.com/software/download/app_servers.html14,uml Tools

1. Rational Rose Big Brother's large-level UML design tools are very powerful. 2, together can think is the best Java UML design tool, can generate Java code according to class diagrams, after design is completed, the system's framework is coming, cool!

15. Guide book 1, don't introduce some books, "Java programming ideas", starters do not recommend 2, Java Programmer recommended to see << Java Programming Thoughts > 3, Java Designer Recommended << Java and Modes >> (New Book, Chinese Writing, Not Translated, Chinese people can write such a deep IT book, very rare)

1. What is Java's Path and ClassPath?

ClassPath and Package in Java

Preface:

Because these two questions are more asked, and the answer is more zero, it is difficult to unify it, so I wrote a one directly, please forgive me.

text:

First, class path (Class Path)

When you are full of Java, then write a Hello World, then compile, run, wait for the two beautiful words to appear in front of you, but unfortunately, only see CAN't Findclass HelloWorld or Exception in thread "Main" java.lang.nosuchmethoderror: main. Why? Compile good Class clearly. Let's take a look at the Java program running process. We already know that Java is through Java

Sender: Supermmx (laughing 天子), letter area: Java Title: [Solving] Java Class Path and Package Send Station: BBS Shuimu Tsinghua Station (Mon Apr 9 08:15:01 2001)

ClassPath and Package in Java

Preface:

Because these two questions are more asked, and the answer is more zero, it is difficult to unify it, so I wrote a one directly, please forgive me.

text:

First, class path (Class Path)

When you are full of Java, then write a Hello World, then compile, run, wait for the two beautiful words to appear in front of you, but unfortunately, only see CAN't Findclass HelloWorld or Exception in thread "main" java.lang.nosuchmethoderror: main. Why? Compile good class clearly. Let's take a look at the Java program running process. We already know that Java explains through Java virtual machines. Running, that is, through the java command, Javac compile generation .Class file is the code to be executed, called bytecode, the virtual machine is loaded with these bytelings through ClassLoader, which is usually Class. This is a problem, where is the ClassLoader know where Java itself class library and user's own class? Or a default value (current path). Or there is a user specified variable to indicate, this Variables are classpaths, or pass parameters to virtual machines when running. This is to indicate three ways of ClassPath. The process of compiling the process and running process is similar, just to find it, the other is to find it. Loading. In fact, Java virtual machine is initialized by Java Luncher, which is also the program for Java (or Java.exe). The virtual machine searches and loads all the needs of the needs in order: 1, Boots: Composition Java Platform Class, including the class in rt.jar and i18n.jar. 2, extended class: Use the Java extension mechanism to be located in the extended directory ($ java_home / jre / lib / ext). JAR file package .3 User classes: Developers defined or unused third-party products using Java extended mechanisms. You must use the -classpath option in the command line or use the ClassPath environment variable to determine the location of these classes. We are above the user yourself The class is specifically referring to these classes. In this way, users only need to specify the location of the user class, the boot class, and the extension class are "automatic". So what to do? User class path is some of the included files The list of directories, .jar, .zip files, as for the class specific to find, because the problem involves Package, the following will be said, it can be considered as long as this category is found. According to the different separators of the platform, the system of UNIX is basically ":": ", Windows is mostly"; "; its possible source is:

* ".", The current directory, this is the default value.

* ClassPath environment variables, once the settings are overwritten. * Command line parameters - CP or -ClassPath, once specified, the upper two is overwritten. * By the -jar parameter specified. Jar file package, put all other The value is overwritten, all classes are from this specified file package. Due to generating executable .jar files, there are other knowledge, such as Package, there are specific configuration files, this article will be mentioned. See some examples of JDK.

We give examples of HelloWorld. Let's do the following assumptions: * The current directory is / helloworld (or C: / HelloWorld, after using the previous one) * JDK version is 1.2.2 (linux) * PATH environment variable settings Correct. (This can be used in any directory) * The file is HelloWorld.java, the content is:

Public class helloworld {public static void main (string [] args) {system.out.println ("Hello World! / N"); system.exit (0);}}

First of all this file must be written, if you are familiar with C, it is likely to be written as this:

Public static void main (int argc, string [] argv) {....

This is wrong, I can try it if I don't believe it. Since there is no Java specification, I don't have the following conjecture: Java's Application program must start with public static void main (string []), other different are not the same. So far, we set up only Path.

1. The current path means you .class file in the current directory,

[HelloWorld] $ javac helloworld.java // This step will not have a problem, [HelloWorld] $ java helloworld // This step may have problems.

If there is a problem like starting, first make sure it is not wrong because it is wrong. If you don't have a wrong command, then do it:

[HelloWorld] $ Echo $ ClassPath or

C: / helloworld> echo% classpath%

See if the ClassPath environment variable is set, if set, then the following command:

[HelloWorld] $ classpath = or c: / helloworld> set classpath =

To make it empty, then run. This time the user class path is ".", So there should be no problem. There is also a method to put "." Add to ClassPath.

[/] $ ClassPath = $ ClassPath :. or C: / HelloWorld> Set ClassPath =% ClassPath%;

It can also be successful. Good luck.

2, when your program requires third-party library support, and more commonly used, you can use this method. For example, the common database driver, write servlet package required by servlet, etc. The setting method is to join the ClassPath in the environment variable. Then you can compile it directly. Or use HelloWorld as an example, such as you want to run it in the root directory, then you can do it directly under the root directory

$ Java HelloWorld or C: /> Java HelloWorld

This will definitely make an error, if your classpath has no change. I think everyone should know why it is wrong, so how to change? I have said that the user path is some directory that contains the class you need, .jar file package , .zip package. There is no generating package, so I have to add the directory where helloWorld.class is located, according to the previous practice, then run once, see, huh, success, change the path, success !! Not only You can only run the class directly. When you want to Import, you can do it. Don't know if you think there is no, with your system's constant expansion, (of course, you need Java things) If you are added to this environment variable, this variable will get more bloated, although the environment variable space can be opened, always feel some uncomfortable. Take a look at a method below.

3. Indicate the ClassPath in the command line parameters.

Or is there the same goal above, perform HelloWorld in any directory, how to implement this method?

[/] $ java -cp / helloWorld HelloWorld or

C: /> java -cp c: / helloworld HelloWorld

It is OK. This is the easiest application of this method. When you use another package, you can use this method. For example:

$ javac -classpath apath / apackage.jar :. myjava.java $ java -cp apath / apackage.jar :. myjava or c: /> javac -classpath apath / apackage.jar ;. Myjava.javac: /> java -cp Apath / apackage.jar ;. Myjava

This method also has an inconvenient place that when the path is located in the third party, it is very difficult to write a long time, it is very inconvenient, which is very inconvenient. For example, an example:

Compile (file, permissions to executable, current directory) $ CAT Compile --------------------------- #! / bin / bash

Javac -classpath apath / apackage.jar: anotherpath / anotherpage.jar :. myjava.java ---------------------------

Run (file, permissions to executable, current directory)

$ CAT RUN --------------------------- #! / bin / bash

Java -cp apath / apackage.jar: anotherpath / anotherpage.jar :. myjava ---------------------------

or:

Compile.bat

C: / helloworld> Type compile.bat ----------------------- javac -classpath apath / apackage.jar: anotherpath / anotherpackage.jar :. Myjava.java -------------------------

Run.bat

C: / helloworld> Type run.bat ---------------------- Java -cp apath / apackage.jar: anotherpath / anotherpackage.jar :. Myjava ------------------------ Yes. Try it. Previous mentioned the expansion class, what is the extension class? Java extension class is the application Developers are used to extend the Java classes of the core platform (or native code). The virtual machine can use these extensions like using the system class. Some people suggest that the package can be placed in the extended directory, so that ClassPath is not set It's not to be specified, isn't it very convenient? It is indeed possible to run correctly, but individual people think that this is not good, can't put it in it, some standard expansion packs can, such as Javaservlet, Java3d, etc. It is recommended to add an environment variable, such as the Jarpath, specify a directory, and store the user's JAR ZIP and other packages. This should wait for Sun.

Under Windows 98, I originally installed, I can't install it. I always crack it. It is not easy to install it. The default is that I can't run correctly, then put Tool.jar into the classpath. It works fine. Now test, remove it It is still correct. After many tests, I found that if I have installed JDK, I will crash when I have installed it, and it can be installed several times. If you find it correctly, you can't work properly. Just add Tools.jar to ClassPath and try it.

Second, packages

"Package" in Java is a more important concept, and Package is defined in this:

................ ..

That is: a package is a collection of related classes and interfaces that provide access protection and name spatial management. The purpose of using the package is to make the class easy to find usage, prevent naming conflicts, and control access. Here we don't discuss too much about the package Things, only discuss and compile, run, class path-related things. As for the other content of the package, please check your relevant documentation yourself.

Simply put, the package is a directory, the following subpack is the subdirectory, this package is the file in this directory. We use an example to explain that the directory structure is as follows: PackageTest / Source /, The directory refers to the packagetest directory, and our source program is placed in the Source directory. The source program is as follows:

Packagetest.java

Package pktest;

Import pktest.subpk. *;

Public class packagetest {private string value; public packagetest (string s) {value = s;}

Public void printvalue () {system.out.println ("Value of PackageTest IS" Value);

Public static void main (string [] args) {packagetest test = new packagetest ("this is a test package"); test.printValue (); packagesecond second = new packagesecond ("I am in packagetest");

Second.printValue (); packagesub sub = new packagesub ("i am in packagetest"); Sub.printValue (); system.exit (0);}}

Packagesecond.java

Package pktest;

Public class packagesecond {private string value;

Public packagesecond (string s) {value = s;}

Public void printvalue () {

System.out.println ("Value of PackageSecond IS" Value);}}

PackageSub.java

Package pktest.subpk;

Import pktest. *;

Public class packagesub {private string value;

Public packagesub (string s) {value = s;}

Public void printvalue () {packagesecond second = new packagesecond ("I am in subpage.");

Second.printValue (); System.out.Println ("Value of Packages" value);

}

Main.java

Import pktest. *; import pktest.subpk. *;

Public class main () {PUBLIC static void main () {packagesecond second = new packagesecond ("I am in main"); second.printvalue (); packagesub sub = new packagesub ("i am in main"); Sub.PrintValue (); System.exit (0);}}

Among them, main.java is a program other than the package to test the classes in the package access package, and PackageTest.java belongs to the pktest. The PackageSecond.java is also pktest, and packages is under pktest. Subpk package, that is, pktest.subpk. For detailed usage, please visit the source program. Ok, first put the source program in the source directory, so that the source becomes the current directory, then compile, huh, it is wrong,

Main.java: 1: package pktest not found in import.import pktest. *;

Here, we have seen how to find the package path. We have done a little assumption: "Just contain this class, even if you find this class, now there is a problem. In fact, JDK tools Javac Javajavadoc need to find classes, see The directory is considered to be the name of the package. For the import statement, a package corresponds to a directory. In this example, IMPORT PKTEST. *, We know that the class path can contain a directory, then take that directory as root, such as some Directory / MyClass, then lookup / myclass / pktest directory and the class. All are available, if not, it will be reported. Because the current classpath only has the current directory, there is no pktest directory in the current directory, so It will be wrong. The classpath can also contain .jar .zip files, these are the compressed packages that can be taking the directory, you can see the .jar .zip file as a virtual directory, then treat it as the directory. Ok, you should Know how to do it, the modified directory structure is as follows: packagetest || __source main.java || __pktest packagetest.java packagesecond.java || __subpk packagesub.java

Then recompile, run, haha, pass. Let's run PackageTest.

[Source] $ java pktest / packagetest

How come again?

Exception in thread "main" java.lang.noclassdefounderror: pktest / packagetest

This is the case, Java wants to run a class name, which can find this class like you are in the same place, so it looks a pkTest / packagetest as a class name. Of course, it will be wrong, should do this,

[Source] $ java pktest.packagetest

Everyone should understand the reason, I will not say much. Note that Javac is different, you can specify the path path, Javac is only compiled, not running, and the lookup class is only in the source file, it will be done, The package where the source file is located, it seems to have some bad place, how to generate .class files so dispersed, watching true twists, don't worry, javac has a -D command line parameter, you can specify a directory, put The generated .class file is in this directory in this directory according to the package.

[Source] $ mkdir classes [Source] $ javac -d classes pktest / packagetest.java [Source] $ javac -d classes main.java

So how do you run it?

[Source] $ cd classs [classes] $ java pktest.packagetest [classes] $ java main

It is possible. In fact, the key is simple, powerful, powerful, not used or wrong, it is not the tool, the key is to understand some of the principles and necessary knowledge behind the tool. The integrated environment is very good, but It shields a lot of underlying knowledge, not wrong, once an error, if there is no such necessary knowledge, it is very difficult, I have to ask, others only tell the specific way you solved, the next time I encountered a slight change The problem doesn't understand. So don't be stamped in the tool, Java's tool combination,

Small projects (560 classes) or will be available.

Third, JAR file

Below. Jar .zip is seen as a .jar file.

1. From the front we can see that JAR files are very important in Java, which greatly facilitates the user's use. We can also do your own .jar package. Or use the previous example, main.java is something outside of the package, Used in the pktest package, we now have to make a pktest into a .jar package, very simple, just we have set up .class in pktest,

[Classes] $ jar -cvf mypackage.jar pktest

Just generate mypackage.jar files, test, the main.class we have generated is in the class content, so you can know from the front: [Classes] $ java -cp mypackage.jar :. main

You can run it.

2, if you have seen the example of JDK, you will know, .jar can also run directly,

[/ deco] $ java -jar ajar.jar

Well, let's try it,

[Classes] $ java -jar mypackage.jarfailed to load main-class manifest Attribute fromMypackage.jar

It seems that our JAR and its JAR are still different. Is there something different? Take it an example, recompile, generate .jar files, then discovery, is .jar compression package Meta-inf / manifest.mf The file is different, more lines, main-class: xxxxx, then look at the wrong information, it is not specified as a main-class, look at the jar command, find a parameter -M,

-M include Manifest Information from Specified Manifest File

It is a bit related to the error message, it seems to read a formulated file. I have to write one by the cat.

[Classes] $ CAT Mymanifestmanifest-Version: 1.0

Main-class: pktest.packagetestcreated-by: 1.2.2 (Sun Microsystems Inc.)

[classes] $ jar cvfm mypackage.jar mymanifest pktestadded manifestadding: pktest / (in = 0) (store = 0) Adding: pktest / packagesecond.class (in = 659) (out = 395) (deflated 40) %) Adding: pktest / subpk / (中 = 0) (store = 0) Adding: pktest / subpk / packagesub.class (in = 744) (out = 454) (Deflated 38%) Adding: pktest /PackageTest.class (In = 1041) (out = 602) (Deflated 42%)

[Classes] $ java -jar mypackage.jarvalue of PackageTest is This is a Test Packagevalue of PackageSecond is I am in PackageTestvalue of PackageSecond is I am in subpackage.value of PackageSub is I am in PackageTest

Ok, success, this will do a .jar file that can be performed directly. You can try it yourself to do the executable JAR as mainly.

summary:

In this article, we discussed the basics such as Class Path, Package, Jar in Java, but more important things, mainly Class Path. It is not a simple ClassPath's full spirituality, but trying to let readers understand its principle. I think I have to do it myself. In fact, most things have there, I only talk about it in the Java DOC, I just talk about it, I hope to help. Due to the limited conditions, JDK1.2.2 is tested in 98 and Linux situation, other versions of JDK and platform please test it yourself, it is inevitable, please refer to it.

Here are some questions that need attention:

1. If you need to use .jar files in the class path, you must put the file name of the JAR file in the class path instead of its directory. 2, at any time, class name must have a complete package, 3, "." The current directory is best in your class path. Below is some common compilation and running modes.

4. To Compile HelloWorld.java App in The Default package in C: / mydir, usecd /mydirc :/jdk1.3/bin/javac.exe -classpath. HelloWorld.java5. To Run a helloworld.class app, in the default Package In C: / MyDir, Usecd / MyDir

C: /jdk1.3/bin/java.exe -classpath. HelloWorld6. To Run A HelloWorld.class App, in The Default Package In A Jar In C: / MyDir, Usecd /myDirc:/JDK1.3/bin/java . .exe -classpath HelloWorld.jar HelloWorld7 To compile a HelloWorld.java app in C: / MyPackage, in package MyPackage, useCD /C:/jdk1.3/bin/Javac.exe -classpath MyPackage / HelloWorld.java8 To.. Run a helloworld.class app in c: / mypackage, in package mypackage, usecd /c:/jdk1.3/bin/java.exe -classpath. mypackage.helloworld9. to run a helloworld.class app in c: / mypackage, In a jar in package mypackage, usecd /mydirc:/jdk1.3/bin/java.exe -classpath helloWorld.jar mypackage.helloworld

(Note: DEFAULT PACKAGE refers to not specifying any packages in the program).

The last small suggestion, put Sun's JDK Tools Document. TION looks well, put JDK's tools Java Javac Javadoc Jar JavaP JDB ... It will be good. The Simplest Is The Best.

2. How to add all the .jar in a directory to ClassPath again.

Tomcat's practice Tomcat.bat...set _libjars = for %% I in (% Tomcat_Home% / lib / *. jar) do call% Tomcat_Home% / bin / cpappend.bat %% i ...

//cpappend.batset _libjars =% _ libjars%;% 1

3. What is the default value of ClassSpath?

In JDK 1.2, there are three search paths for finding classes: 1) The first location of the Java search class is the bootstrap path. The value of the path can be checked by calling System.GetProperty ("Sun.Boot.class.Path"). Note that the prefix "Sun." Shows at least until now, this property is a SUN implementation. 2) The second location of the Java lookup class is the expansion directory. You can check the directory list by calling System.GetProperty ("java.ext.dirs"). 3) The third location of the Java lookup class is the application class path. The value of the path can be checked by calling System.GetProperty ("java.class.path").

You can get: 1) java_base / jre / lib / rt.jarjava_base / javy / lib / i18n.jarjava_base / jre / classes2) Java_Base / JRE / LIB / EXT

4. How to find the class that runs the program to run?

When compiling, use the option javac -verbose ******* to see which classes in the class library are used.

Java -verbosejavac -verbose is a good debugging function of JDK

5. How is PATH and CLASSPATH under Linux? Modify file / etc / profileclasspath = pathaathbathcexport ClassPath

Java_home is similar to the main difference set under Windows should be on the separator

6. How to modify PATH and CLASSPATH?

Method 1: Enter the console with CMD, enter the set command, you will see the name and value of all environment variables on your machine! Then enter the set classpath = you want to set up. Yes! ! ! Method 2: 2000, Control Panel - System - Environment - Environment Variables - System Variables, if there is no ClassPath variable, new XP: Start -> My Computer -> Properties -> Advanced -> Environment Variables -> New Java_HomeClassPathPath

Java Help and API Document 1. What is the Java API Reference? API is an HTML format to find a package from Sun's website including API and user guide. This site is made into .CHM format easy to find. The API reference is the use of the JDK tool Javadoc is a must-have documentation for developers. 2. Where is the source code of the Java Basic Class Library? Source code src.zip in JDK installation directory

What is the difference between LIB under the development environment 1. JRE LIB under the JDK? JRE is a subset of JDK. Provide a running environment. JDK's lib directory is used for JDK, such as some tools under JDK, possibly with files in this directory. For example, a compiler, etc. The LIB directory of JRE is JVM and is running. Includes all standard bitter, and expansion classes

2. My JBUILDER cursor is not neat?

Everyone often said that there is a problem with the cursor misplaced in the Chinese system, which is considered to be a bug in jbuilder. In fact, this is really jetful! Everyone discussed the solution without more than two: 1. Change the editor's font to the Song body. The question brought by this method is that the English font under the Song is really ugly. Reading is not pleasing to the eye; 2, It is to remove the bold attributes of the editor font, which also affects the readability of the code. In fact, the problem that caused JBuilder cursor misplaced problems is not Borland's mistake, but the sins of Java's master - SUN! Everyone must know I18n? In different locults, JDK automatically calls the corresponding Properties file, and in the JDK, there is a problem with the Properties file corresponding to the Chinese system, and there is no distinguished English font.

Often, bold and italic, resulting in the above problems, the solution is simple, as long as this Properties file is modified correctly, the modification method is as follows: Find the font.properties.en file in the jre / lib directory Edit this file and modify it as follows: # @ (#) font.properties.zh1.16 00/10/06 ## AWT Font Default Properties for Chinese Windows # # t

dialog.plain.0 = Arial, ANSI_CHARSETdialog.plain.1 = / u5b8b / u4f53, ?????? _ CHARSETdialog.plain.2 = WingDings, SYMBOL_CHARSET, NEED_CONVERTEDdialog.plain.3 = Symbol, SYMBOL_CHARSET, NEED_CONVERTEDdialog.bold.0 = Arial Bold, ANSI_CHARSETdialog.bold.1 = / u5b8b / u4f53, ?????? _ CHARSETdialog.bold.2 = WingDings, SYMBOL_CHARSET, NEED_CONVERTEDdialog.bold.3 = Symbol, SYMBOL_CHARSET, NEED_CONVERTED

Dialog.italic.0 = arial italic, ANSI_CharsetDialog.italic.1 = / u5b8b / u4f53, ?????? _ charsetdialog.italic.2 = Wingdings, Symbol_charset, NEED_CONVERTED

Dialog.italic.3 = Symbol, Symbol_Charset, NEED_CONVERTED

dialog.bolditalic.0 = Arial Bold Italic, ANSI_CHARSETdialog.bolditalic.1 = / u5b8b / u4f53, ?????? _ CHARSETdialog.bolditalic.2 = WingDings, SYMBOL_CHARSET, NEED_CONVERTEDdialog.bolditalic.3 = Symbol, SYMBOL_CHARSET, NEED_CONVERTED

dialoginput.plain.0 = Courier New, ANSI_CHARSETdialoginput.plain.1 = / u5b8b / u4f53, ?????? _ CHARSETdialoginput.plain.2 = WingDings, SYMBOL_CHARSET, NEED_CONVERTEDdialoginput.plain.3 = Symbol, SYMBOL_CHARSET, NEED_CONVERTED

dialoginput.bold.0 = Courier New Bold, ANSI_CHARSETdialoginput.bold.1 = / u5b8b / u4f53, ?????? _ CHARSETdialoginput.bold.2 = WingDings, SYMBOL_CHARSET, NEED_CONVERTEDdialoginput.bold.3 = Symbol, SYMBOL_CHARSET, NEED_CONVERTED

dialoginput.italic.0 = Courier New Italic, ANSI_CHARSETdialoginput.italic.1 = / u5b8b / u4f53, ?????? _ CHARSETdialoginput.italic.2 = WingDings, SYMBOL_CHARSET, NEED_CONVERTEDdialoginput.italic.3 = Symbol, SYMBOL_CHARSET, NEED_CONVERTED

dialoginput.bolditalic.0 = Courier New Bold Italic, ANSI_CHARSETdialoginput.bolditalic.1 = / u5b8b / u4f53, ?????? _ CHARSETdialoginput.bolditalic.2 = WingDings, SYMBOL_CHARSET, NEED_CONVERTEDdialoginput.bolditalic.3 = Symbol, SYMBOL_CHARSET, NEED_CONVERTEDserif. plain.0 = Times New Roman, ANSI_CHARSETserif.plain.1 = / u5b8b / u4f53, ?????? _ CHARSETserif.plain.2 = WingDings, SYMBOL_CHARSET, NEED_CONVERTEDserif.plain.3 = Symbol, SYMBOL_CHARSET, NEED_CONVERTED

serif.bold.0 = Times New Roman Bold, ANSI_CHARSETserif.bold.1 = / u5b8b / u4f53, ?????? _ CHARSETserif.bold.2 = WingDings, SYMBOL_CHARSET, NEED_CONVERTEDserif.bold.3 = Symbol, SYMBOL_CHARSET, NEED_CONVERTED

serif.italic.0 = Times New Roman Italic, ANSI_CHARSETserif.italic.1 = / u5b8b / u4f53, ?????? _ CHARSETserif.italic.2 = WingDings, SYMBOL_CHARSET, NEED_CONVERTEDserif.italic.3 = Symbol, SYMBOL_CHARSET, NEED_CONVERTED

Serif.Bolditalic.0 = Times New Roman Bold italic, ANSI_CHARSET

Serif.BolditalicIC.1 = / u5b8b / u4f53, ?????? _ charsetserif.bolditalic.2 = WINGDINGS, SYMBOL_CHARSET, NEED_CONVERTEDSERIF.BOLDITALICICICITALICITALICIC.3 = SYMBOL, SYMBOL_CHARSET, NEED_CONVERTED

sansserif.plain.0 = Arial, ANSI_CHARSETsansserif.plain.1 = / u5b8b / u4f53, ?????? _ CHARSETsansserif.plain.2 = WingDings, SYMBOL_CHARSET, NEED_CONVERTEDsansserif.plain.3 = Symbol, SYMBOL_CHARSET, NEED_CONVERTED

sansserif.bold.0 = Arial Bold, ANSI_CHARSETsansserif.bold.1 = / u5b8b / u4f53, ?????? _ CHARSETsansserif.bold.2 = WingDings, SYMBOL_CHARSET, NEED_CONVERTEDsansserif.bold.3 = Symbol, SYMBOL_CHARSET, NEED_CONVERTED

sansserif.italic.0 = Arial Italic, ANSI_CHARSETsansserif.italic.1 = / u5b8b / u4f53, ?????? _ CHARSETsansserif.italic.2 = WingDings, SYMBOL_CHARSET, NEED_CONVERTEDsansserif.italic.3 = Symbol, SYMBOL_CHARSET, NEED_CONVERTEDsansserif.bolditalic. 0 = arial bold italic, ANSI_CHARSETSSSSERIF.BOLDITALICICIT = / U5B8B / U4F53, ?????? _ charsetsserif.bolditalic.2 = WINGDINGS, SYMBOL_CHARSET, NEED_CONVERTED

Sansserif.Bolditalic.3 = Symbol, Symbol_Charset, NEED_CONVERTED

monospaced.plain.0 = Courier New, ?????? _ CHARSETmonospaced.plain.1 = / u5b8b / u4f53, ?????? _ CHARSETmonospaced.plain.2 = WingDings, SYMBOL_CHARSET, NEED_CONVERTEDmonospaced.plain.3 = Symbol, Symbol_Charset, NEED_CONVERTED

monospaced.bold.0 = Courier New Bold, ?????? _ CHARSETmonospaced.bold.1 = / u5b8b / u4f53, ?????? _ CHARSETmonospaced.bold.2 = WingDings, SYMBOL_CHARSET, NEED_CONVERTEDmonospaced.bold.3 = Symbol , Symbol_Charset, NEED_CONVERTED

Monospaced.italic.0 = Courier new italic, ?????? _ charsetmonospaced.italic.1 = / u5b8b / u4f53, ?????? _ charsetmonospaced.italic.2 = Wingdings, Symbol_Charset, NEED_CONVERTEDMONOSPACED.ITIC.3 = Symbol , Symbol_Charset, NEED_CONVERTED

monospaced.bolditalic.0 = Courier New Bold Italic, ?????? _ CHARSETmonospaced.bolditalic.1 = / u5b8b / u4f53, ?????? _ CHARSETmonospaced.bolditalic.2 = WingDings, SYMBOL_CHARSET, NEED_CONVERTEDmonospaced.bolditalic.3 = Symbol, Symbol_Charset, NEED_CONVERTED

# Name aliase ## alias.timeesroman = serif # alias.helvetica = Sansserif # alias.courier = monospaced

# for backward compatibility # TimeSroman.0 = Times new Roman, ANSI_CHARSET # Helvetica.0 = arial, ANSI_CHARSET # Courier.0 = Courier New, Ansi_CharsetzaPfdingBats.0 = Wingdings, Symbol_Charset

# Font filenames for reduced initialization time # filename. / U5b8b / u4f53 = SIMSUN.TTFfilename.Arial = ARIAL.TTFfilename.Arial_Bold = ARIALBD.TTFfilename.Arial_Italic = ARIALI.TTFfilename.Arial_Bold_Italic = ARIALBI.TTF

FILENAME.COURIER_NEW = COUR.TTF

FILENAME.COURIER_NEW_BOLD = court.ttffilename.courier_new_italic = couri.ttffilename.courier_new_bold_italic = courti.ttf

FILENAME.TIMES_NEW_ROMAN = TIMES.TTFFILENAME.TIMES_NEW_ROMAN_BOLD = TIMESBD.TTTFFILENAME.TIMES_NEW_ROMAN_ITALIC = Timesi.ttffilename.TIMES_NEW_ROMAN_BOLD_ITALIC = TIMESBI.TTF

FILENAME.WINGDINGS = WINGDING.TTFFILENAME.SYMBOL = Symbol.ttf

# Default font definition # default.char = 2751

# Static fontcharset info. ## fontcharset.dialog.0 = sun.io.chartobytecp1252fontcharset.dialog.1 = sun.io.Chartobytegbkfontcharset.dialog.2 = sun.awt.windows.Chartobytewings

Fontcharset.dialog.3 = sun.awt.chartobytesymbol

# Fontcharset.dialoginput.0 = sun.io.CharToByteCp1252fontcharset.dialoginput.1 = sun.io.CharToByteGBKfontcharset.dialoginput.2 = sun.awt.windows.CharToByteWingDingsfontcharset.dialoginput.3 = sun.awt.CharToByteSymbol

# Fontcharset.serif.0 = sun.io.CharToByteCp1252fontcharset.serif.1 = sun.io.CharToByteGBKfontcharset.serif.2 = sun.awt.windows.CharToByteWingDingsfontcharset.serif.3 = sun.awt.CharToByteSymbol

# Fontcharset.sansserif.0 = sun.io.CharToByteCp1252fontcharset.sansserif.1 = sun.io.CharToByteGBKfontcharset.sansserif.2 = sun.awt.windows.CharToByteWingDingsfontcharset.sansserif.3 = sun.awt.CharToByteSymbol

# Fontcharset.monospaced.0 = sun.io.CharToByteCp1252fontcharset.monospaced.1 = sun.io.CharToByteGBKfontcharset.monospaced.2 = sun.awt.windows.CharToByteWingDingsfontcharset.monospaced.3 = sun.awt.CharToByteSymbol # Exclusion Range info. # Exclusion.dialog.Plain.0 = 00a0-f8ffExclusion.dialog.italic.0 = 00A0-F8ffExClusion.dialog.Bold.0 = 00A0-F8ffExClusion.dialog.bolditalic.0 = 00A0-F8FF

Exclusion.dialoginput.Plain.0 = 00A0-F8ffExClusion.dialoginput.italic.0 = 00A0-f8ffExClusion.dialoginput.bold.0 = 00A0-F8ffExClusion.dialoginput.bolditalic.0 = 00A0-F8FF

Exclusion.serif.plain.0 = 00A0-f8ffExclusion.serif.italic.0 = 00A0-F8ffExClusion.serif.Bold.0 = 00A0-F8FFEXClusion.serif.Bolditalic.0 = 00A0-F8FF

Exclusion.sansserif.plain.0 = 00A0-f8ffExclusion.sansserif.ITalic.0 = 00A0-F8ffExClusion.sansserif.bold.0 = 00A0-F8ffExClusion.sansserif.bolditalic.0 = 00A0-F8FF

Exclusion.monospaced.bold.0 = 00a0-f8ffExClusion.Monospaced.Bold.0 = 00A0-F8ffExClusion.monospaced.bolditalic.0 = 00A0-F8FF

# Charset for text input # inputtextcharset = ?????? _ charset

After saving, everything is solved! This method is also applicable to any of the same issues.

[Question out] This error should really reflect, I hope that what they do will test better, otherwise ...

3. What should I do if the JDK version conflict?

To determine which JDK (win2000), change the registry: hkey_local_machine / software / javasoft / java development Kit / currentVersion, you want to decide which JDK you can use in Project Properties. 4.EDitPlus compiles Java? How to set it? First install the Java's running environment and debug it. First, from the menu tool (Tools "->" Configure User Tools ... "to enter the User Tool Settings. Expand "Tool" Strip Menu -> User Tools in Categories, Select "Group 1" in Group and Tools Projects, click "Group Name ..." button on the right side of the panel to modify the text "group1" "Compiled Java Program". Then select the modified group "Compile Java Program", click "Add New Tool" button, select the program, create a new program, select it. Then is the most important step (modified attribute): 1. Add the contents of the "Menu Text" to modify "Javac"; "Command" Select the compiler JavaC.exe in the bin directory after installing JDK, if the JDK installation path For "C: / JDK", this path is "c: /jdk/bin/javac.exe"; "Parameters" select "file name", which is displayed as "filename"; "Initial Directory" Select " File Directory, displayed as "filedir"; select the "Capture Output" check box. 1.2 Adding the contents of the execution function "Menu Text" to modify to "Java"; "Command" Select the compiler java.exe in the bin directory after installing JDK, the path is "c: /jdk/bin/java.exe"; "Parameter" Select "file name (excluding extension)", "即 (filenamenoext)"; "Initial Directory" selection "file directory", displayed as "filedir"; select "Capture Output" Selection box. This completes the basic configuration. Upcasting is Upcasting is traceable. That is to say, a subclass is treated as its parent class, such as: Method void do (Object obj) {...}, you can put Any object is called as a parameter.

Compile operation 1. How to compile multiple .java source files into a .class? Java -d. A.java b.java2. DEPRECIATED API is what? Java is too fast, so you should use the latest API as much as possible, But old API is still compatible, so return to WANing you Deprecated API3. How to compile all Java files in a directory? Ant or JBuilder, or write scripts yourself. 4. How do you do a DOS window when you execute a program? JavaW5. How to run JAR files? Java -jar ***. JAR6. How to remove Java's memory limit plus -XMX parameter to set up Maximum Java Heap Size, such as: Java -XMS10M Myclass

Data Type and Conversion 1.int, Char, Double and Byte How to Translate? INT, CHAR, DOUBLE and BYTE Mutual Translation Program // Integer to Byte Array Conversion Public Static Byte [] INTTOBYTE (Int Number) {Int Temp = Number; Byte [] b = new byte [4]; for (int i = b.length-1; i> -1; i -) {b [i] = new integer (TEMP & 0xFF) .Bytevalue (); // Save the highest bit Temp = TEMP >> 8; // shift 8 digits to the right} Return B;}

// By array to integer conversion public static int referenceOint (byte [] b) {int S = 0; for (int i = 0; i <3; i ) {IF (B [i]> = 0) s = S B [I]; Elses = S 256 B [I]; S = S * 256;} if (b [3]> = 0) // The last one is not multiplied, because it may overflow S = S B [3]; Elses = S 256 B [3]; Return S;

// Character to byte conversion public static Byte [] Chartobyte (CHAR CH) {INT TEMP = (int) ch; Byte [] b = new byte [2]; for (int i = B.Length-1; i> -1; i -) {b [i] = new integer (temp & 0xff) .Bytevalue (); // Save the highest bit Temp = TEMP >> 8; // shift 8 digits} Return B; }

// byte to character conversion

Public static char byteochar (byte [] b) {INT S = 0; if (b [0]> 0) s = b [0]; Elses = 256 b [0]; s * = 256; if (b [ 1]> 0) S = B [1]; Elses = 256 B [1]; char CH = (char) S; return ch;}

// Floating point to byte transformation public static Byte [] DouBletobyte (double d) {byte [] b = new byte [8]; long l = double.douBletolongBits (d); for (int i = 0; i > 8;

} Return B;

// Byte to floating point conversion public static double bytetoDouble (byte [] b) {long L;

L = B [0]; L & = 0xff; L | = ((long) b [1] << 8); l & = 0xffff; l | = ((long) B [2] << 16); l & = 0xfffffffFFF ; l | = ((long) B [3] << 24); l & = 0xfffffff1; L | = ((long) B [4] << 32); l & = 0xffffffffl;

L | = ((long) B [5] << 40); l & = 0xffffffffffl; L | = ((long) B [6] << 48);

L | = ((long) B [7] << 56); return double.longbitstodouble (L);}

2. The converter between BYTE ARRAY?

In communication, the numerical value is often required to convert the byte stream to a value. The procedures provided below can perform conversions between int and Byte Array.

The floating point and the double-precision floating point number and the byte stream will be prepared in the later period of time and share it with you. Welcome testing and comment.

/ **** intconverter ** this class provides method Int int rt intete array and * byte array back inT. ** /

Public class intconverter {/ **** Method Converting int @Param Number the int value to be converted. ** /

Public static byte [] TobyTearray (int Number) {int Temp = Number; Byte [] b = new byte [4]; for (int i = B.LENGTH - 1; I> -1; i -) {b [ I] = new integer (Temp & 0xFF) .Bytevalue (); TEMP = TEMP >> 8;} return b;}

/ ***

* Method Converting Byte Array Int. ** @Param the byte array to be converted. ** /

Public static int tointeger (byte [] b) {int S = 0;

For (int i = 0; i <3; i ) {if (b [i]> 0) s = s b [i]; elses = s 256 b [i]; s = s * 256;}

IF (B [3]> 0) S = S B [3]; ELSE

S = S 256 B [3];

Return S;

// Testing program.

Public static void main (string [] args) {intconverter abc = new intconverter (); int S = -1121115678; Byte [] b = abc.tobyteaRray (s); for (int i = 0; i <= 3; i ) ) System.out.println (B [i]);

s = abc.tointeger (b); system.out.println (s);}}

3. String and INT conversion? A1 = Integer.Parseint (S1); S1 = INTEGER.TOSTRING (A1); 4. How to get a random integer? First use random () to get a random floating point number, then multiply The maximum value of the integer you want to get, and finally take the result. 5. How to convert the string type into a 16-en-genex integer? Public static void main (string args []) {string x = "0x300c8"; int y = integer.decode (x) .intValue (); system.out. Println (y);} 6.int and java.lang.integer, and difference? INT is data type, Integer is more functional, can convert integers to floating point calculations, in this strong type language in Java It is very useful. An integer is built with an Integer's constructor integer (int). Similar classes include Float, Short, Long, etc.

Data Structure 1. How to implement two-dimensional vector? Vector vector1 = new vector (); vector vector2 = new vector (); ..... hashtable number = new hashtable (); NumBers.put ("Vector1", Vector1); NumBers.Put ("Vector2", Vector2); 2. How to get the current system time in Java? For example, current Date, Date Today = New Date (System.currentTimeMillis ()); 3. How to transform java.util.date For java.sql.date? Transformation: java.sql.date sd; java.util.date ud; // initialize the ud such as ud = new java.util.date ();

SD = new java.sql.date (ud.gettime ());

If you want to insert into the database and the corresponding field is the Date type, you can use the predua.sql.date method to get the above method.

You can also use the database to provide a To_date function such as existing UDTO_DATE (New SimpleDateFormat (). Format (UD, "YYYY-MM-DD HH: MM: SS"), "YYYY-MM-DD HH24: MI: SS") Note Java Different in the format provided by the format and database

System Related 1. How to start a program in Java? String strands; string cmd = "cmd"; if (! System.getproperty). Equals ("Windows NT")) CMD = "Command"; CMD = cmd "/ c" strcommand; try {runtime.getRuntime (). EXEC (CMD);} catch (ioException ex) {}

STRCOMMAND is the command string, how to use under the DOS, how can I use 2. How to get the application's path in Properties System.getProperties () How do I get the current system time? 1. SimpleDateFormat Formatter = new SimpleDateFormat ("YYY- MM-DD "); string time = formatter.format (new date ()); 2.calendar cal = calendar.getInstance (); int year = ca.get (calendar.year); Month = ..

Input and output 1. Can I use a pure Java write program to access the serial port? Sun provides a Package called Javax.comm, which is specifically used to operate the Serial Port. 2.WriteUTF and WRITE Difference WRITEUTF is UTF8 encoding a string Mode Output Data You can read by Readutf. It is not recommended to handle the output of single-byte characters.

3. How do I use FileWritrel to wrap in text? / r / n

Network Related 1. How to make my program access to external networks through Proxy? System.SetProperty ("Java.ProxyHost", "Your Proxy Here");

Local related 1. How to call local DLL? JNI2. How to write a scanner program with Java? Example: Javatwain May Be a Powerful Solution, You Can Go To www.gnome.sk to Download The Newest Package. JavatWain Version 5.1 Is A Part of The Morena 6.0 framework ?????

BELOW IS An Simple Example: / ** $ ID: Exampleshow.java, V 1.5 2002/07/15 13:48:55 Mmotovsk EXP $ ** CopyRight (C) 1999-2002 Gnome Spol. S Ro All Rights Reserved. * * This software is the confidential and proprietary information of * Gnome spol. s ro you shall not disclose such Confidential * Information and shall use it only in accordance with the terms * of the license agreement you entered into with Gnome. * /

// javatwain package version 5.1

/ ** Exampleshow Demonstrates How To Scan An Image Using Defaultsfrom The Twain Source.
* /

Import java.awt. *; import java.awt.event. *; import sk.gnome.twain. *;

Public Class Example; Public Void Paint (Graphics G) {if (null! = image) g.drawImage (image, 0, 0, this);}

Windowlistener Windowadapter = new windowadapter () {public void windowclosing (windowevent e) {system.exit (0);}}

public ExampleShow () {try {addWindowListener (windowAdapter); setTitle ( "ExampleShow Frame Application"); // Open TWAIN select source dialog box // and initialize the source selected by the user TwainSource source = TwainManager.selectSource (null).; image = Toolkit.getDefaultToolkit () createImage (source);. // wait for the image to be completedMediaTracker tracker = new MediaTracker (this); tracker.addImage (image, 0); // this is the moment the scanner user interface pops Upsystem.err.println ("Start Loading Image ..."; try {tracker.waitForll ();} catch (interruptedException e) {system.err.println ("Image Loading Was Interrupted!"); E.PrintStackTrace );} tracker.RemoveImage (image); system.err.println ("Image loaded ..."); setsize (Image.GetWidth (this), Image.getHeight (THIS)); setVisible (TRUE); TWAINMANAGER.CLOSE ();} catch (twainexception e) {E.PrintStackTrace ();}} public static void main (String [] args) {new exampleshow ();}}

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

New Post(0)