Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Hello, World in Java on Windows Algorithms, 4th edition 1.  Fundamentals 1.1  Programming Model 1.2  Data Abstraction 1.3  Stacks and Queues 1.4  Analysis of Algorithms 1.5  Case Study: Union-Find 2.  Sorting 2.1  Elementary Sorts 2.2  Mergesort 2.3  Quicksort 2.4  Priority Queues 2.5  Sorting Applications 3.  Searching 3.1  Symbol Tables 3.2  Binary Search Trees 3.3  Balanced Search Trees 3.4  Hash Tables 3.5  Searching Applications 4.  Graphs 4.1  Undirected Graphs 4.2  Directed Graphs 4.3  Minimum Spanning Trees 4.4  Shortest Paths 5.  Strings 5.1  String Sorts 5.2  Tries 5.3  Substring Search 5.4  Regular Expressions 5.5  Data Compression 6.  Context 6.1  Event-Driven Simulation 6.2  B-trees 6.3  Suffix Arrays 6.4  Maxflow 6.5  Reductions 6.6  Intractability Related Booksites Web Resources FAQ Data Code Errata Lectures Cheatsheet References Online Course Programming Assignments Hello World in Java on Windows This DrJava-based Java programming environment is no longer being supported (because DrJava in no longer being actively developed and DrJava is incompatible with Java 11). It has been replaced by the following IntelliJ-based programming environment for Windows. This document instructs you on how to set up our Java programming environment for your Windows computer. It also provides a step-by-step guide for creating, compiling, and executing your first Java program using either DrJava or the Command Prompt. All of the software used is freely available. These instructions apply to 32-bit and 64-bit Windows 8, Windows 7, Vista SP1, and XP SP3. 0.   Install the Programming Environment Our installer downloads, installs, and configures the Java programming environment you will be using, including Java SE 7, DrJava, the textbook libraries, and the Command Prompt. Log in to the user account in which you will be programming. Your account must have Administrator privileges and you must be connected to the Internet. Download algs4.exe and double-click it to perform the installation. If you receive a User Account Control alert before the installation, click Yes or Allow; if you receive a Program Compatibility Assistant alert after the installation, click This program installed correctly. If the installation succeeds, you will see the following: A Command Prompt windows containing approximately this execution log. A Standard Drawing window containing a blue bullseye and textbook graphic. Note that the installation can take several minutes or longer if you have a slow internet connection. Delete algs4.exe. 1.   Create the Program in DrJava Now you are ready to write your first Java program. You will develop your Java programs in an application called DrJava. DrJava features many specialized programming tools including syntax highlighting, bracket matching, auto indenting, and line numbering. The installer creates a shortcut on the desktop to DrJava. Double-click it to launch DrJava. If you receive a Windows Security Alert, click either Unblock or Allow Access. In the main DrJava window, type the Java program HelloWorld.java exactly as it appears below. If you omit even a semicolon, the program won't work. public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World"); } } As you type, DrJava does the indenting for you. Finally, click the Save button to save the file. Use DrJava to create the folder C:\Users\username\algs4\hello and name the file HelloWorld.java. The file name is case sensitive and must exactly match the name of the class in the Java program. Here username is your Windows username. 2.   Compile the Program from DrJava It is now time to convert your Java program into a form more amenable for execution on a computer. To do this, click the Compile button. If all goes well, you should see the following message in the Compiler Output pane at the bottom: Compilation completed. If DrJava complains in some way, you mistyped something. Check your program carefully, using the error messages in the Compiler Output pane as a guide. 3.   Execute the Program from DrJava Now it is time to run your program. This is the fun part. Type the following in the Interactions pane at the bottom. By convention, we highlight the text you type in boldface. > java HelloWorld If all goes well, you should see the following message: Welcome to DrJava. Working directory is C:\Users\username\algs4\hello > java HelloWorld Hello, World You may need to repeat this edit-compile-execute cycle a few times before it works. 4.   Command-Line Interface The command-line provides capabilities beyond those available in DrJava, including redirection and piping. You will type commands in an application called the Command Prompt. The installer creates a Shortcut on the desktop to the Command Prompt. Double-click it to launch the Command Prompt. You should see something like the following: Microsoft Windows [Version 6.3.9600] (c) 2013 Microsoft Corporation. All rights reserved. C:\Users\username> To confirm that the Java compiler is installed, type the command in boldface below and check that the output matches: C:\Users\username>javac -version javac 1.7.0_67 To confirm that the Java interpreter is installed, type the command in boldface below and check that the output matches: C:\Users\username>java -version java version "1.7.0_67" Java(TM) SE Runtime Environment (build 1.7.0_67-b01) Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode) If you have a 32-bit machine, the last line will be: Java HotSpot(TM) Client VM (build 24.65-b04, mixed mode, sharing) 5.   Compile the Program from the Command Prompt You will use the javac command to convert your Java program into a form more amenable for execution on a computer. From the Command Prompt, navigate to the directory containing HelloWorld.java, say C:\Users\username\algs4\hello, by typing the cd (change directory) commands below: C:\Users\username>cd C:\Users\username\algs4\hello C:\Users\username\algs4\hello> Compile it by typing the javac command below: C:\Users\username\algs4\hello>javac HelloWorld.java C:\Users\username\algs4\hello> Assuming the file HelloWorld.java is in the current working directory, you should see no error messages. To make our textbook libraries accessible to Java, use the command javac-algs4 instead. For example, to compile TestAlgs4.java, which uses our standard drawing library, the auto-installer issues the the following command: C:\Users\username\algs4>javac-algs4 TestAlgs4.java 6.   Execute the Program from the Command Prompt You will use the java command to execute your program. From the Command Prompt, type the java command below. C:\Users\username\algs4\hello>java HelloWorld Hello, World You should see the output of the program. To make our textbook libraries accessible to Java, use the command java-algs4 instead. For example, to test standard draw and standard audio type the following two commands: C:\Users\username\algs4\hello>java-algs4 edu.princeton.cs.algs4.StdDraw [ displays a graphics window with some geometric shapes and text ] C:\Users\username\algs4\hello>java-algs4 edu.princeton.cs.algs4.StdAudio [ plays an A major scale ] 7.   Static Code Analysis Tools You can use Findbugs and Checkstyle to check the style of your programs and identify common bug patterns. To run Findbugs 3.0.1, type the following command in the Command Prompt: C:\Users\username\algs4\hello>findbugs-algs4 *.class Running findbugs on HelloWorld.class: The argument must be a list of .class files. Here is a list of bug descriptions. To run Checkstyle 6.9, type the following command in the Command Prompt: C:\Users\username\algs4\hello>checkstyle-algs4 *.java Running checkstyle on HelloWorld.java: Starting audit... Audit done. The argument must be a list of .java files. Here is a list of available checks. Troubleshooting I previously used the introcs.exe installer from the textbook Introduction to Programming in Java. Should I use the algs4.exe installer? Yes, we recommend using the algs4.app installer because the introcs.app installer does not install the library algs4.jar and the corresponding commands javac-algs4 and java-algs4. When running the installer, I get an access denied error message. What should I do? Make sure you are using an administrator account. Rerun the installer. Also, it's possible your machine has some kind of encryption software that prevents writing to C:\Users\username\AppData\Local, in which case the auto-installer will abort. The installer doesn't execute. Why? The installer requires PowerShell. Run Windows Update to update your computer. If you are running Windows XP, you must have Service Pack 3. You can manually download PowerShell 2.0 for Windows XP or Vista by clicking the corresponding link under Windows Management Framework Core (WinRM 2.0 and Windows PowerShell 2.0). Can I run the auto-installer on a drive other than C: ? Yes, but you will need to modify the command-line instructions accordingly. The installer doesn't work on my machine and I'm using Kaspersky Anti-Virus. What should I do? You must temporarily disable Kaspersky Anti-Virus. The installer still doesn't work on my machine. What should I do? Please consult a staff member to identify what went wrong. What does the installer do? In short, it downloads, installs, and configures Java, DrJava, Findbugs, Checkstyle, and the textbook libraries. Here is a more detailed list: Downloads and installs Java SE 7 from either java32.zip or java64.zip. This includes the Java Runtime Environment (java.exe) and part of the Java Development Kit (javac.exe and tools.jar). Downloads the textbook library from algs4.jar. Creates wrapper scripts javac-algs4 and java-algs4 that classpath in the textbook libraries. Downloads and installs Findbugs 3.0.1 from findbugs.zip. Downloads our findbugs configuration file from findbugs.xml. Creates the wrapper script findbugs-algs4. Downloads and installs Checkstyle 6.9 from checkstyle.zip. Downloads our checkstyle configuration file from checkstyle.xml. Creates the wrapper script checkstyle-algs4. Downloads and installs the latest stable version of DrJava, from drjava.jar. Creates a shortcut on the desktop to DrJava. Downloads and installs the DrJava configuration file from drjava-config.txt to C:\Users\username\.drjava. Note that this will overwrite any existing .drjava configuration file. Adds C:\Users\username\algs4\java\bin and C:\Users\username\algs4\bin to the user PATH environment variable. Customizes the Command Prompt preferences by enabling QuickEdit and Insert modes and setting the Screen Buffer Size to 80-by-500. Creates a shortcut on the desktop to the Command Prompt. Tests that the installation succeeded by compiling and executing TestAlgs4.java. How do I completely uninstall algs4.exe? Delete the C:\Users\username\algs4 folder (but save any of the .java files you created, if desired). Delete these additions from your user PATH environment variable. C:\Users\username\algs4\bin C:\Users\username\algs4\java\bin Delete the DrJava configuration file C:\Users\username\.drjava. Delete the shortcuts on the desktop to DrJava and the Command Prompt. What happens if I rerun the installer? It will re-download, install, and configure Java, Checkstyle, Findbugs, DrJava, and the textbook libraries. What should I do if I have previously installed DrJava in another location? We suggest deleting it and using the version in C:\Users\username\algs4 by using the newly created DrJava shortcut on the desktop. Can I use a different version of Java? Yes, but you will need to configure the Windows environment variables and DrJava compiler properties yourself. Can I use an IDE other than DrJava? Yes you can use another IDE (such as Eclipse) but you will have to configure the IDE properties yourself (such as the classpath). I have a high-DPI display and the font size used by DrJava's is microscopic. How can I enlarge it? You can change the size of most fonts using Preferences -> Display Options -> Fonts. Unfortunately, there is not currently a good way to change the menubar font. Instead, try changing the look and feel using Preferences -> Display Options -> Look and Feel -> Plastic3DLookAndFeel. When I launch the Eclipse IDE, I get a "Failed to load the JNI shared library" error. How can I fix this? You probably have a 64-bit version of Java and a 32-bit version of Eclipse. The installer installs a 64-bit version of Java if you have a 64-bit machine, which takes precedent over a previously installed 32-bit version of Java. To correct, either update to a 64-bit version of Eclipse or remove the C:\Users\username\introcs\java folder so that Windows uses your previously installed 32-bit version of Java. You can also specify which version of Java to use in the Eclipse.ini file. How do I configure Windows to reveal the .java or .class file extensions? Many Windows machines are configured to hide the file extensions. If this is the case, select Start -> My Computer -> Tools -> Folder Options -> View, uncheck the box next to Hide file extensions for known file types, and click OK. When I enter the command "java -version" or "javac -version" I get an error. First, verify that the following two files exists: C:\Users\username\algs4\java\bin\javac.exe C:\Users\username\algs4\java\bin\java.exe If so, it is likely an issue with the Windows PATH environment variable. From the Command Prompt, type the following command to display it: C:\Users\username> echo %PATH% The PATH environment variable should include an entry for C:\Users\username\algs4\java\bin. When I compile or execute a program from the Command Prompt that uses the textbook libraries I get an error. How can I fix this? Be sure to use the wrapper scripts javac-algs4 and java-algs4. How do I navigate to another drive from the Windows Command Prompt? From the Command Prompt, type H: to switch to the H: drive. Then, use the cd command to navigate to the desired directory. Where can I learn more about Command Prompt? Microsoft maintains a command-line reference. Can I use the Windows PowerShell instead of the Command Prompt? The Windows PowerShell is a more advanced command-line shell. However, it does not currently support the redirection of standard input. What's the sha256sum of algs4.exe? 58207c99fd91b3f7247c234ef6f61e6fe1deef9b56f0307ce6f6c7bd55a124a5 Last modified on August 14, 2019. Copyright © 2000–2019 Robert Sedgewick and Kevin Wayne. All rights reserved.