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

Similar documents
Networks Programming Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000)

Eclipse Tutorial. For Introduction to Java Programming By Y. Daniel Liang

USING THE OOSIML/JAVA COMPILER. With the Command Window

Lecture 1: Introduction to Java

Objectives. Chapter 1 Introduction to Computers, Programs, and Java. What is a Computer?

Supplement H.1: JBuilder X Tutorial. For Introduction to Java Programming, 5E By Y. Daniel Liang

Supplement II.B(1): JBuilder X Tutorial. For Introduction to Java Programming By Y. Daniel Liang

Java Language. Programs. Computer programs, known as software, are instructions to the computer. You tell a computer what to do through programs.

Chapter 1 Introduction to Computers, Programs, and Java

NetBeans Tutorial. For Introduction to Java Programming By Y. Daniel Liang. This tutorial applies to NetBeans 6, 7, or a higher version.

Chapter 1 Introduction to Computers, Programs, and Java

IT151: Introduction to Programming (java)

Chapter 1 Introduction to Computers, Programs, and Java

USING THE OOSIML/JAVA. With a Terminal Window

Chapter 1 Introduction to Java

Chapter 1 Introduction to Computers, Programs, and Java

Chapter 1 Introduction to Computers, Programs, and Java

The Command Shell. Fundamentals of Computer Science

Chapter 1 Introduction to Computers, Programs, and Java

Tiny Instruction Manual for the Undergraduate Mathematics Unix Laboratory

These two items are all you'll need to write your first application reading instructions in English.

3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)

CS335 Graphics and Multimedia

II. Compiling and launching from Command-Line, IDE A simple JAVA program

GETTING STARTED. The longest journey begins with a single step. In this chapter, you will learn about: Compiling and Running a Java Program Page 2

Chapter 1 Introduction to Computers, Programs, and Java. What is a Computer? A Bit of History

Lecture 1: Overview of Java

Lesson 01 Introduction

The Computer System. Hardware = Physical Computer. Software = Computer Programs. People = End Users & Programmers. people

Chapter 1: Introduction to Computers, Programs, and Java

CSC116: Introduction to Computing - Java

Java TM SE 7 Release Notes Microsoft Windows Installation (32-bit)

page 1 Murach s Beginning Java 2 Table of Contents Murach s Beginning Java 2 (Includes Version 1.3 & 1.4) - 2 Introduction - 3

CSC116: Introduction to Computing - Java

JVM interprets the Java bytecode, controls how it interacts with the operating system and manages memory.

Lesson 04: Our First Java Program (W01D4

CHAPTER 1. Introduction to JAVA Programming

Certified Core Java Developer VS-1036

Introduction to Linux. Fundamentals of Computer Science

Instructions. First, download the file

WA2452 Node.js Software Development. Classroom Setup Guide. Web Age Solutions Inc.

Ibis RMI User s Guide

Life Without NetBeans

Introduction to Java. Lecture 1 COP 3252 Summer May 16, 2017

History of Java. Java was originally developed by Sun Microsystems star:ng in This language was ini:ally called Oak Renamed Java in 1995

Software Installation for CS121

IQTIDAR ALI Lecturer IBMS Agriculture University Peshawar

Index. Course Outline. Grading Policy. Lab Time Distribution. Important Instructions

Special Edition Using Java Installing the JDK and Getting Started

Slide 1 Java Programming 1 Lecture 2D Java Mechanics Duration: 00:01:06 Advance mode: Auto

Sams Teach Yourself Java 2 in 21 Days, Fourth Edition. Copyright 2004 by Sams Publishing. International Standard Book Number:

Eclipse. JVM, main method and using Eclipse. Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics

Eng. Mohammed Alokshiya

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Introduction to Java. Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.

Chapter 2 Author Notes

Department of Computer Science. Software Usage Guide. CSC132 Programming Principles 2. By Andreas Grondoudis

Sun ONE Integrated Development Environment

Java Programming Language Mr.Rungrote Phonkam


Introduction. SSH Secure Shell Client 1

Chapter 1: Introduction to Computers, Programs, and Java

Welcome to Kmax Installing Kmax

Command-driven, event-driven, and web-based software

Section 2.2 Your First Program in Java: Printing a Line of Text

CSC116: Introduction to Computing - Java

WA2579 Technical Introduction to Microservices. Classroom Setup Guide. Web Age Solutions Inc.

Programming Studio #1 ECE 190

Introduction to Java

Visual C++ Tutorial. For Introduction to Programming with C++ By Y. Daniel Liang

Introduction. Overview of the Course on Java. Overview of Part 1 of the Course

Lab 1 1 Due Wed., 2 Sept. 2015

CS520 Setting Up the Programming Environment for Windows Suresh Kalathur. For Windows users, download the Java8 SDK as shown below.

WA2442 Introduction to JavaScript. Classroom Setup Guide. Web Age Solutions Inc. Copyright Web Age Solutions Inc. 1

Guided Tour (Version 3.3) By Steven Castellucci as Modified by Brandon Haworth

Unit 10. Linux Operating System

You should see something like this, called the prompt :

Outline. Introduction to Java. What Is Java? History. Java 2 Platform. Java 2 Platform Standard Edition. Introduction Java 2 Platform

Operating Systems and Using Linux. Topics What is an Operating System? Linux Overview Frequently Used Linux Commands

CSE 421 Course Overview and Introduction to Java

Introduction to Computers, Programs, and Java. CSE 114, Computer Science 1 Stony Brook University

Programming Studio #1 ECE 190

Getting Started with Command Prompts

Soot overview/disassembling classfiles

Programming. Syntax and Semantics

WA2493 What's New in Java 8. Classroom Setup Guide. Web Age Solutions Inc.

Advanced Object-Oriented Programming Introduction to OOP and Java

Programming by Delegation

WA2423 JavaScript for Web 2.0 Development. Classroom Setup Guide. Web Age Solutions Inc. Copyright Web Age Solutions Inc. 1

WA1278 Introduction to Java using Eclipse. Classroom Setup Guide. Web Age Solutions Inc. Copyright Web Age Solutions Inc. 1

LAB 1 INTRODUCTION TO LINUX ENVIRONMENT AND C COMPILER

WA day Java prereq for Selenium. Classroom Setup Guide. Web Age Solutions Inc. Copyright Web Age Solutions Inc. 1

McGill University School of Computer Science Sable Research Group. *J Installation. Bruno Dufour. July 5, w w w. s a b l e. m c g i l l.

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M

C++ Spring Break Packet 11 The Java Programming Language

Section 2.2 Your First Program in Java: Printing a Line of Text

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

WA1884 Introduction to Java. using Oracle JDeveloper 11g. Classroom Setup Guide. Web Age Solutions Inc. Copyright Web Age Solutions Inc.

Introduction to Cygwin Operating Environment

Agenda. Announcements. Extreme Java G Session 2 - Main Theme Java Tools and Software Engineering Techniques

Transcription:

Supplement B Creating, Compiling and Running Java Programs from the Command Window For Introduction to Java Programming, 5E By Y. Daniel Liang This supplement covers the following topics: Opening a Command Window Using Simple DOS Commands (create, change directories, display files, delete files and directories) Creating and Editing Programs Using Notepad and WordPad Compiling and Running Programs Common Errors 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 5.0 can be downloaded from http://java.sun.com/j2se/1.5.0/download.jsp. See Supplement A, Installing JDK 5.0, on how to install JDK 5.0. 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, Programs, MS-DOS Prompt in Windows 98, or Programs, Accessories, Command Prompt in Windows NT/2000/ME/XP, as shown in Figure 1.1. 1

Figure 1.1 You can start the command prompt 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 A, Installing JDK 5.0, to 2

configure JDK 5.0. 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. 3

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. 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. 4

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: 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 1. I tried to run the program from the DOS prompt, but got java.lang.noclassdeffounderror exception. What is wrong? 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 5

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. 2. I tried to run the program from the DOS prompt, but got java.lang.nosuchmethodfounderror exception. What is wrong? The class does not have a main method or the main method signature is incorrect. 6