Supplement I.C. Creating, Compiling and Running Java Programs from the Command Window



Similar documents
Supplement I.B: Installing and Configuring JDK 1.6

Supplement I.B: Installing and Configuring JDK 1.6

For Introduction to Java Programming, 5E By Y. Daniel Liang

Appendix A Using the Java Compiler

Opening a Command Shell

Java Software Development Kit (JDK 5.0 Update 14) Installation Step by Step Instructions

Right now, the latest and greatest version of Java available for download is Start with this link to find out more about it

How to Install Java onto your system

Eclipse installation, configuration and operation

Packaging and Deploying Java Projects in Forte

File Manager User Guide

LAB 1. Familiarization of Rational Rose Environment And UML for small Java Application Development

Attachments Internet Explorer

Creating a Java application using Perfect Developer and the Java Develo...

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

Installing Java. Table of contents

WA Continuous Integration with Jenkins- CI, Maven and Nexus. Classroom Setup Guide. Web Age Solutions Inc. Web Age Solutions Inc.

Java Language Tools COPYRIGHTED MATERIAL. Part 1. In this part...

Practice Fusion API Client Installation Guide for Windows

GridWorld Installation Guide

JAVS Scheduled Publishing. Installation/Configuration... 4 Manual Operation... 6 Automating Scheduled Publishing... 7 Windows XP... 7 Windows 7...

File Manager Pro User Guide. Version 3.0

Working With Your FTP Site

Quest Soft Token for Windows Phone User Guide

Installing Ruby on Windows XP

Notepad++ The COMPSCI 101 Text Editor for Windows. What is a text editor? Install Python 3

WebDisk Essentials How to Post & Retrieve Files From Your Own Online Storage Area

Human Resources Installation Guide

WA1826 Designing Cloud Computing Solutions. Classroom Setup Guide. Web Age Solutions Inc. Copyright Web Age Solutions Inc. 1

S. Bouzefrane. How to set up the Java Card development environment under Windows? Samia Bouzefrane.

System requirements for ICS Skills ATS

AUSTRALIAN CUSTOMS AND BORDER PROTECTION SERVICE TYPE 3 CERTIFICATE 2014 INSTALLATION GUIDE

Introduction to Gear VR Development in Unity APPENDIX A: SETUP (WINDOWS 7/8)

Magrathea Root Certificate Authority (Root CA) installation

Chapter 1: Getting Started

Omnixx Client Installer for TXDPS

A Java Crib Sheet. First: Find the Command Line

Click Start > Control Panel > System icon to open System Properties dialog box. Click Advanced > Environment Variables.

About Java Plug-ins. Installing or Uninstalling the Java Plug-in CHAPTER

To begin, visit this URL:

Installing C++ compiler for CSc212 Data Structures

Adding Digital Signature and Encryption in Outlook

5.4.8 Optional Lab: Managing System Files with Built-in Utilities in Windows 7

Informatics for Integrating Biology & the Bedside. i2b2 Workbench Developer s Guide. Document Version: 1.0 i2b2 Software Release: 1.3.

Introduction to Gear VR Development in Unity APPENDIX A: SETUP (MAC OS X)

Using ProjectWise Explorer for File Transfer

GE Intelligent Platforms. Activating Licenses Online Using a Local License Server

Jenkins on Windows with StreamBase

Click to begin. Maitre'D Full System Backup & Restore

Buildstation 5.4 SLA Machine Control Software Release Notes

STATISTICA VERSION 10 STATISTICA ENTERPRISE SERVER INSTALLATION INSTRUCTIONS

Introduction to Eclipse

A Short Introduction to Writing Java Code. Zoltán Majó

A Step-by-Step Patient Guide to Upload Medical Images to the Cleveland Clinic Neurological Institute

ABS2020 Moving Airfreight Forward

Anti-Spyware Enterprise Module software

Installation Guide - Client. Rev 1.5.0

ATBONLINE BUSINESS. Customer User Guide Exporting Account Information to.ofx Format Software (Simply Accounting).

How To Encrypt A Traveltrax Report On Gpg On A Pc Or Mac Or Mac (For A Free Download) On A Thumbdrive Or Ipad Or Ipa (For Free) On Pc Or Ipo (For An Ipo)

Installing SQL-Ledger on Windows

F-Secure Mobile Security for Nokia E51, E71 and E75. 1 Installing and Activating F-Secure Client 5.1

How to Run Java Programs Using Microsoft J++

How To - Install and configure the Symbience AL3 Download Client

GAUSS 9.0. Quick-Start Guide

MySQL Quick Start Guide

SafeNet KMIP and Google Cloud Storage Integration Guide

JAVA WEB START OVERVIEW

An Introduction to Using the Command Line Interface (CLI) to Work with Files and Directories

To reduce or not to reduce, that is the question

Download and Installation Instructions. Android SDK and Android Development Tools (ADT) Microsoft Windows

Configuring ICVMLT32.EXE as a Windows Service

IBM WebSphere Application Server Version 7.0

STATISTICA VERSION 9 STATISTICA ENTERPRISE INSTALLATION INSTRUCTIONS FOR USE WITH TERMINAL SERVER

WS_FTP Pro for Windows 95/98/NT

How to install and use the File Sharing Outlook Plugin

Troubleshooting AVAYA Meeting Exchange

Using Actian PSQL as a Data Store with VMware vfabric SQLFire. Actian PSQL White Paper May 2013

Enabling Java and ActiveX Settings of Internet Explorer:

CS506 Web Design and Development Solved Online Quiz No. 01

Word 2010: Mail Merge to with Attachments

Tutorial 5: Developing Java applications

How to Configure Microsoft System Operation Manager to Monitor Active Directory, Group Policy and Exchange Changes Using NetWrix Active Directory

Industrial Security Facilities Database (ISFD) Troubleshooting Tips

1. Product Information

Viewing and Troubleshooting Perfmon Logs

Advanced Digital Imaging

WinSCP PuTTY as an alternative to F-Secure July 11, 2006

new Business Online Technical Troubleshooting Guide

Course 2277: Implementing, Managing, and Maintaining a Microsoft Windows Server 2003 Network Infrastructure: Network Services

Quest Soft Token for Windows Mobile User Guide

Microsoft Diagnostics and Recovery Toolset 7 Evaluation Guide

Configuring the BBj Jetty Web Server (rev10.02) for OSAS

CS170 Lab 11 Abstract Data Types & Objects

Microsoft Visual Studio 2010 Instructions For C Programs

Job Scheduler User Guide IGSS Version 11.0

Accessing Restricted University Online Resources Using Network Connect. on the Secure Remote Access Service

CafePilot has 3 components: the Client, Server and Service Request Monitor (or SRM for short).

Oracle Enterprise Single Sign-on Logon Manager Best Practices: Packaging ESSO-LM for Mass Deployment Release E

Download and Installation Instructions. Android SDK and Android Development Tools (ADT)

Transcription:

Supplement I.C Creating, Compiling and Running Java Programs from the Command Window For Introduction to Java Programming By Y. Daniel Liang This supplement covers the following topics: Opening a Command Window ( 1.2). Using Simple DOS Commands (create, change directories, display files, delete files and directories) ( 1.3). Creating and Editing Programs Using Notepad and WordPad ( 1.4). Compiling and Running Programs ( 1.5). Common Errors ( 1.6). 1.1 Introduction Sun releases each version of Java with a Java Development Toolkit (JDK). This is a primitive command-line tool set that includes software libraries, a compiler for compiling Java source code, an interpreter for running Java bytecode, and an applet viewer for testing Java applets, as well as other useful utilities. JDK 7 can be downloaded from http://java.sun.com/javase/downloads/index.jsp. See Supplement I.B, Installing and Configuring JDK, on how to install JDK 7. 1.2 Opening a Command Window Using JDK from Windows, you have to type the commands from the command window. Assume you have successfully installed JDK. Start a Command window by clicking the Windows Start button and choosing Run to open the Run dialog box, as shown in Figure 1.1. Enter cmd in the Open field and click OK to display a command window, as shown in Figure 1.2. 1

The Run dialog Figure 1.1 You can start the command window from the Windows Start button. You will see the command prompt window displayed as shown in Figure 1.2. Figure 1.2 You can type the JDK commands in the command window. Now type javac in the DOS prompt. If your JDK is configured properly, the command displays the usage of the command, as in Figure 1.3. Otherwise, an error message is displayed to indicate that the command is not found, as shown in Figure 1.4. Please refer to Supplement I.B, Installing and Configuring JDK, to configure JDK 7. 2

Figure 1.3 The javac command displays the usage of the command. Figure 1.4 The javac command is not found if JDK is not properly configured. 1.3 Simple DOS Commands To work with JDK on Windows, you need to know some simple DOS commands. Here are several frequently needed commands: dir -- Lists all files in the directory. mkdir dirname -- Creates a new directory named dirname. cd dirname -- Changes to the specified directory. For example, cd c:\ changes to the directory c:\ cd.. -- Changes to the parent directory. del filename Deletes a file. For example, del Test.java deletes the file named Test.java in the current directory. del *.* Deletes all files in the directory. [Caution: files deleted from the command window cannot be recovered.] rmdir dirname Deletes the specified directory dirname. 3

type filename.java Displays the contents of the specified file. 1.4 Creating and Editing Programs Using Notepad and WordPad You can create programs using Windows Notepad or WordPad. To do so, first open a command window; change the directory to where your programs should be stored, and type notepad filename.java or write filename.java to create a file for Java source code. For example, the following command starts Notepad to create or edit Welcome.java: notepad Welcome.java If Test.java does not exist, a dialog box is displayed to alert you that it is a new file, as shown in Figure 1.5. Figure 1.5 The Notepad alerts you that the specified file is new. Click Yes to create a new file. You can type the code for the program in the Notepad, as shown in Figure 1.6. Choose File, Save to save the file. Figure 1.6 You can use Notepad to create and edit Java source files. 1.5 Compiling and Running Java Programs To compile the source code, use the javac command. For example, the following command compiles Welcome.java: 4

javac Welcome.java To run the class, use the java command. For example, the following command runs Welcome: java Welcome Figure 1.7 shows a sample run. Figure 1.7 Use the javac command to compile and java to programs. 1.6 Common Errors Question 1. I tried to run the program from the DOS prompt, but got java.lang.noclassdeffounderror exception. What is wrong? Answer: The class file is not found. There are several reasons: 1. the class has been compiled; 2. the classpath was not set properly. You need to set classpath to.;%classpath%. 3. If the class has a package statement, you didn t invoke it with the full class name including the complete package name. For example, if the class path is c:\liang and the package for the class is chapter1, you have to type java chapter1.classname from the c:\liang directory. Question 2. I tried to run the program from the DOS prompt, but got java.lang.nosuchmethodfounderror exception. What is wrong? Answer: The class does not have a main method or the main method signature is incorrect. 5