How To Java JDK Microsoft Windows Free BSD
How To Java? • 使用 JDK – Microsoft Windows – Free. BSD / Linux • 使用 Java IDE (注意! 很多仍需 JDK 配合) – – – Visual. Age for Java (IBM) (Eclipse 前身) Eclipse (蝕; 蓋過) Intelli. J IDEA (Jet. Brains) JBuilder (Borland/Codegear) JDeveloper (Oracle ; technet. oracle. com) (JDeveloper是JBuilder補充改寫的 ) – JCreator, Forte for Java, Sun Java Studio, Sun Net. Beans, … – Visual J++ (Microsoft), Visual J# (J Sharp), Visual Studio – Visual Café (Web. Gain, Symantec+BEA; closed at 2002) 交通大學資訊 程學系
Write Java program,you need… 1. 用編輯器 (editor) 寫 Java 程式 2. 用編譯器 (compiler) 把 Java 程式轉成 Java bytecode,也就是 class 檔 3. 用解譯器 (Interpreter) 來執行 Java 的 class 檔 4. 用除錯器 (debugger) 來協助找出程式的問題 Sun 提供一套 Java 程式發展 具集,稱為 JDK (Java Development Kit),具有2, 3, 4的功能。 同時具有上述 4項功能者,稱為整合發展環境 (IDE, Integrated Development Environment) 交通大學資訊 程學系
Download and install JDK • http: //java. sun. com • Download the standard version(J 2 SDK/Java SDK) • Simply double click and then follow the instructions • Configure / prepare your Develop Environment – Set correct command PATH before starting – Batch file / Short cut / Edit System environment variable • Download Java Documentation/Reference manual • Java is good for GUI + Event driven programming • GUI, Graphical User Interface – A way for the computer and the user to communicate via graphics (pictures) on the screen 交通大學資訊 程學系
JDK Installed Directory Tree • The JDK has the directory structure shown below. jdk_<version> ____________|___________ | | | | bin lib | demo | | LICENSE | | | jre | | COPYRIGHT … … | __|__ | README. txt include | | readme. html bin lib Sun 把 JDK 1. 5 改名 5. 0; 所以JDK 1. 6. 1 就是 JDK 6. 1 交通大學資訊 程學系
JDK 的基本組成份子 /bin Java binary programs /docs Java documents /jre/bin Run-time 用的 binary programs /jre/lib 或 /lib Run-time library 重要的是 /jre/lib/rt. jar 這個檔案 早期版本是 /lib/classes. zip 交通大學資訊 程學系
JDK Versions (版本) • Java 1. 1 – jdk 1. 1. 8_16 and older versions • Java 2 (別搞混Language version 與 JDK version) – Standard Edition (J 2 SE) • • j 2 sdk 1. 2 (主要加入 Swing ) j 2 sdk 1. 3. 1_14 j 2 sdk 1. 4. 2_06 j 2 sdk 1. 5. xx (5. 0); 1. 6 (6. 0), 1. 7(7. 0), … – Enterprise Edition (J 2 EE) – Micro Edition (J 2 ME) JDK 1. 5 (5. 0) 開始有支援 Generic type (即 template) Sun 自 JDK 1. 6 (6. 0) 開始已改稱 Java 不再稱 Java 2 交通大學資訊 程學系
Types of Java programs • Java Application – Standalone program • Java Applet – 搭配 HTML 網頁 • Java Servlet – 放在網站且直接會在網站上執行 • JSP -- Java Server Page (類似 ASP, PHP) – HTML 網頁內夾著片片段段的Java程式 • Java MIDLet -- 在手機或手持裝置 • Java ? ? ? Let 交通大學資訊 程學系
JDK 中的 Tools 這些 tools 都擺在 JDK 的 bin 裡面: • javac. exe : Java compiler (編譯器) • java. exe : Java interpreter (解譯器) • appletviewer : Java applet viewer • javap : Class file disassembler (反組譯) 交通大學資訊 程學系
Java Applet • 編譯: Ø javac My. Applet. java • 執行: Ø Win XP 後直接打 My. Page. htm Ø appletviewer My. Page. htm Ø 放網站後用瀏覽器看 My. Page. htm 交通大學資訊 程學系 <HTML> <BODY> <applet code=My. Applet. class name=My. Applet width=320 height=200> </applet> </body> </html>
如何知道系統預設編碼? // File. Encoding. java -- find the default encoding public class File. Encoding { public static void main(String[] args) { System. out. println(System. get. Property("file. encoding")) ; } } D: jtest> javac File. Encoding. java D: jtest> java File. Encoding 交通大學資訊 程學系
可以搜尋的 Java document • http: //www. allimant. org/javadoce. html 交通大學資訊 程學系
Unix 下的 makefile 範例. SUFFIXES: . class. java JAVAC=/usr/local/jdk 1. 4. 1/bin/javac -encoding Big 5 -deprecation -classpath . : /usr/local/jdk 1. 4. 1/jre/lib/rt. jar #JAVAC=/usr/local/jdk 1. 4. 1/bin/javac -encoding Big 5 -deprecation -classpath . . /. . : /usr/local/jdk 1. 4. 1/jre/lib/rt. jar all: File. Encoding. class cd test; make. java. class: $(JAVAC) $< clean: rm -f *. class chmod 644 *. java makefile 交通大學資訊 程學系
dos. Make /make/nmake • http: //java. csie. nctu. edu. tw/~icwu/classes/java/doc/dos. Make. zip • 所有檔案拷貝到JDK安裝目錄的bin裡面,就可以共用PATH 設定,使用 make來編譯、執行程式 • 修改 make. bat set set set rem rem set JAVASDK_HOME=C: j 2 sdk 1. 4. 2bin JAVAC=%JAVASDK_HOME%javac. exe JAVAC_OPTION=-classpath ". ; %JAVASDK_HOME%jrelibrt. jar" JAVA=%JAVASDK_HOME%java. exe JAVA_OPTION=-classpath ". ; %JAVASDK_HOME%jrelibrt. jar" default make action, could be "new", "all", or "clean" DEFAULT_ACTION=all default main class for executing. Leave it blank if you don't want to run your program after make. DEFAULT_MAIN_CLASS= 交通大學資訊 程學系
Using IDEs • An IDE is an Integrated Development Environment • All professional IDEs are similar • Different IDEs meet different needs – Blue. J, Dr. Java are designed as teaching tools • Emphasis is on ease of use for beginners • Little to learn, so students can concentrate on learning Java – Eclipse, JBuilder, Net. Beans are designed as professional-level work tools • Emphasis is on supporting professional programmers • More to learn, but well worth it in the long run 想要節省時間, 必須先花一些時間好好學習使用 具 交通大學資訊 程學系
Java IDEs on Windows 1. Microsoft Visual J++ / Visual Studio 2. Borland(Code. Gear) JBuilder: http: //www. borland. com/products/download_jbuilder. html 3. Eclipse: http: //www. eclipse. org/downloads/index. php 4. Jet. Brains Intelli. J IDEA: (30天試用) http: //www. jetbrains. com/idea/download/index. html Ps. 後三者均有 Unix、Mac 的對應版本 交通大學資訊 程學系
A good IDE should. . (1/2) • Include a “Syntax aware” text editor – different tokens can be colored differently • for catching runaway comments or strings, for example – brace{ }, bracket[ ], and parentheses ( ) matching • whenever a closing brace, bracket or parenthesis is typed the editor shows you the corresponding opening brace, bracket, or parenthesis • clicking on brace, bracket, or parenthesis will show the corresponding block 交通大學資訊 程學系
A good IDE should. . (2/2) • Simplicity – powerful development environment, but the power is hidden – we do not use most of what is there • Debugger is useful and generally intuitive – helpful to the students – useful for demonstrations • Support for the standard libraries 交通大學資訊 程學系
Eclipse (1/58) Eclipse Reference: http: //www. eclipse. org/eclipse/presentation/eclipse-slides. ppt 交通大學資訊 程學系 31
Eclipse (2/58) 交通大學資訊 程學系 Solar Eclipse
Eclipse (6/58) Eclipse Setup again • 安裝外掛 Jigloo SWT/Swing GUI Builder for Eclipse – 讓Eclipse可以像JBuilder. X一樣使用拖拉方式建構 GUI的外掛 – http: //cloudgarden. com/jigloo/index. html 36 交通大學資訊 程學系 36
Eclipse (8/58) Eclipse Workbench ( 作台) • Represents the desktop development environment – It contains set of tools for resource management – It provides common way of navigating through the resources • Multiple workbenches can be opened at the same time 交通大學資訊 程學系 38
Eclipse (9/58) Eclipse Workspace ( 作空間) • Represents users data • It is a set of user defined resources – Files • Contain arbitrary number of bytes – Folders • Contain other folders or files – Projects • Collections of files and folders 交通大學資訊 程學系 39
Eclipse (10/58) Download Eclipse • http: //www. eclipse. org • Main point for finding Eclipse resources – – Downloads Articles Discussion groups Bugs report • Contains various resources for using Eclipse • Contains references to other Eclipse related sites 交通大學資訊 程學系
Eclipse (11/58) Running Different Workspace … • It is possible to run different workspaces using command prompt – -data argument must be used with eclipse. exe – Workspace location must be specified • Useful for grouping project specific data • Multiple workspaces can run at the same time 交通大學資訊 程學系
Eclipse (12/58) … Running Different Workspace • Customize your working directory by creating a shortcut identifying the eclipse. exe and the working directory 交通大學資訊 程學系 42
Eclipse (14/58) Workbench Terminology Menu bar Text editor Tool bar Perspective and Fast View bar Outline view Resource Navigator view Bookmarks view Properties view Message area 交通大學資訊 程學系 Stacked views Tasks view Editor Status area
Eclipse (15/58) Workbench again Menu bar Text editor Tool bar Running Result 交通大學資訊 程學系 Outline view
Eclipse (16/58) Workspace 作目錄 • You can have multiple workspace (working directory) • Specify your workspace when starting Eclipse • You can also switch workspace in Eclipse: File >> Switch Workspace 交通大學資訊 程學系
Eclipse (22/58) 交通大學資訊 程學系 設定 Eclipse Editor 選項
Eclipse (28/58) 交通大學資訊 程學系 Eclipse的 Debug 功能
Eclipse (29/58) 按 Ctrl+Shift+B 設 Break Point 交通大學資訊 程學系
Eclipse (32/58) 切換到 Debug Perspective 交通大學資訊 程學系
Eclipse (34/58) JDT : Java Development Tools • State of the art Java development environment • Included in Eclipse Project releases – Available as separately installable feature – Part of Eclipse SDK drops • Built atop Eclipse Platform – Implemented as Eclipse plug-ins – Using Eclipse Platform APIs and extension points 交通大學資訊 程學系
Eclipse (35/58) Java Perspective (1/3) • Java-centric view of files in Java projects – Java elements meaningful for Java programmers Java project package class field method Java editor 交通大學資訊 程學系
Eclipse (36/58) Java Perspective (2/3) • Browse type hierarchies – “Up” hierarchy to supertypes – “Down” hierarchy to subtypes Type hierarchy Selected type’s members 交通大學資訊 程學系
Eclipse (37/58) Java Perspective (3/3) • Search for Java elements – Declarations or references – Including Libraries and other projects Hits flagged in margin of editor All search results 交通大學資訊 程學系
Eclipse (38/58) Java Editor (1/7) • Hovering over identifier shows Javadoc spec 交通大學資訊 程學系
Eclipse (39/58) Java Editor (2/7) • Method (function) completion in Java editor List of plausible methods 交通大學資訊 程學系 Doc for method 69
Eclipse (40/58) Java Editor (3/7) • On-the-fly spell check catches errors early Click to see fixes Problem Quick fixes 交通大學資訊 程學系 Preview
Eclipse (41/58) Java Editor (4/7) • Code templates help with drudgery Statement template 交通大學資訊 程學系 Preview
Eclipse (42/58) Java Editor (5/7) • Java editor creates stub methods Method stub insertion for anonymous inner types Method stub insertion for inherited methods 交通大學資訊 程學系 72
Eclipse (43/58) Java Editor (6/7) • Java editor helps programmers write good Java code Variable name suggestion Java. Doc code assist Argument hints and proposed argument names 交通大學資訊 程學系 73
Eclipse (44/58) Java Editor (7/7) • Other features of Java editor include – Local method history – Code formatter – Source code for binary libraries – Built-in refactoring 交通大學資訊 程學系
Eclipse (45/58) Refactoring (1/4) • JDT has actions for refactoring Java code 交通大學資訊 程學系
Eclipse (46/58) Refactoring (2/4) • Refactoring actions rewrite source code – Within a single Java source file – Across multiple interrelated Java source files • Refactoring actions preserve program semantics – Does not alter what program does – Just affects the way it does it • Encourages exploratory programming • Encourages higher code quality – Makes it easier to rewrite poor code 交通大學資訊 程學系
Eclipse (47/58) Refactoring (3/4) • Full preview of all ensuing code changes – Programmer can veto individual changes List of changes “before” vs. “after” 交通大學資訊 程學系
Eclipse (48/58) Refactoring (4/4) • Growing catalog of refactoring actions – Organize imports – Rename {field, method, class, package} – Move {field, method, class} – Extract method – Extract local variable – Inline local variable – Reorder method parameters 交通大學資訊 程學系
Eclipse (49/58) Eclipse Java Compiler • Eclipse Java compiler – – – JDK-compliant Java compiler Helpful error messages Generates runnable code even in presence of errors Fully-automatic incremental recompilation High performance Scales to large projects • Multiple other uses besides the obvious – – – Syntax and spell checking Analyze structure inside Java source file Name resolution Content assist Refactoring Searches 交通大學資訊 程學系
Eclipse (50/58) Eclipse Java Debugger (1/2) • Run or debug Java programs Local variables Threads and stack frames Editor with breakpoint marks Console I/O 交通大學資訊 程學系
Eclipse (51/58) Eclipse Java Debugger (2/2) • Run Java programs – In separate target JVM (user selectable) – Console provides stdout, stdin, stderr – Scrapbook pages for executing Java code snippets • Debug Java programs – Full source code debugging – Any JPDA-compliant JVM • Debugger features include – – – – Method and exception breakpoints Conditional breakpoints Watchpoints Step over, into, return; run to line Inspect and modify fields and local variables Evaluate snippets in context of method Hot swap (if target JVM supports) 交通大學資訊 程學系
Eclipse (52/58) Eclipse is a Java IDE • Widely regarded as the Java development environment • With all the bells and whistles… – – – Language-aware editors, views, … Refactoring support Integrated unit testing and debugging Incremental compilation and build Team development support • Out of the box support for CVS – … 交通大學資訊 程學系
Eclipse (53/58) Eclipse is an IDE Framework • Eclipse + JDT = Java IDE – – First class framework for Java Language aware editor Incremental build Integrated debugging • Eclipse + CDT = C/C++ IDE – First class framework for C/C++ – Language aware editor – Refactoring, search • Eclipse + PHP = PHP IDE • Eclipse + JDT + CDT + PHP = Java, C/C++, PHP IDE • … 交通大學資訊 程學系
Eclipse (54/58) Eclipse is a Tools Framework • Extensibility through OSGi implementation – Plug-ins make Eclipse whatever you need it to be • Focus on developing a universal platform of frameworks and exemplary tools • Tools extend the Eclipse platform using plug-ins – – – Business Intelligence and Reporting Tools (BIRT) Eclipse Communications Framework (ECF) Web Tools Project (WTP) Eclipse Modelling Framework (EMF) Graphical Editing Framework (GEF) Test and Performance Tooling Project (TPTP) Plug-in 交通大學資訊 程學系
Eclipse (55/58) Eclipse is an Application Framework • Remove the IDE elements, Java language support, team development support, … and you’re left with a pretty comprehensive general application framework – Support for multiple platforms • Linux, Windows, Mac OSX, UNIX, embedded – Rich widget set, Graphics – Native-OS integration (drag and drop, OLE/XPCOM integration) • A platform for rich clients • Some examples of this later… 交通大學資訊 程學系
Eclipse (56/58) Eclipse Resources • http: //www. eclipse. org – In Eclipse terms, a “drop” is a build and the “platform” is another name for the software… download the Platform and you get Eclipse. Don’t get the SDK unless you know you want it • http: //www. cfeclipse. org – Wiki, how-to, instructions, etc. • http: //www. myeclipseide. org – Excellent set of tools to flesh out Eclipse • http: //labs. macromedia. com – Flex. Builder 2 and RDS plugin • http: //www. dopefly. com/pages/cfeclipse. cfm – WIDE variety of info, how-to, and articles on Eclipse, CFE, plugins, etc. • http: //caterpillar. onlyfun. net/Gossip/Java. Gossip. V 1/Java. Gossip. htm • The Java Tutorials http: //java. sun. com/docs/books/tutorial/ 交通大學資訊 程學系
Eclipse (57/58) Eclipse Plug-in Architecture Eclipse Platform Workbench Help Workspace Team Tool (plug-in) … Tool (plug-in) Platform Runtime 交通大學資訊 程學系
Eclipse (58/58) IBM’s IDE History 1994 Visual. Age for Smalltalk 1996 Visual. Age for Java Open Source project 交通大學資訊 程學系 Visual. Age Micro Edition 2001 Eclipse Project
Jet. Brains Intelli. J 交通大學資訊 程學系
Intelli. J (4/18) 建立單一模組的 Project (Intelli. J IDEA) 交通大學資訊 程學系
Intelli. J (5/18) 選擇 Java Module (Intelli. J IDEA) 交通大學資訊 程學系
Intelli. J (6/18) 設定 Module 名稱(Intelli. J IDEA) 交通大學資訊 程學系
設定 Intelli. J IDEA 交通大學資訊 程學系 Intelli. J (9/18)
Intelli. J (13/18) 在Project中加入檔案(Intelli. J IDEA) 交通大學資訊 程學系
Intelli. J (14/18) 按 F 9 設 Break Point (Intelli. J IDEA) 交通大學資訊 程學系
Intelli. J IDEA 的 Debug 功能 交通大學資訊 程學系 Intelli. J (18/18)
- Slides: 108