Running Java Programs

Similar documents
What you need to know about Java and JetTrac Licensing

Programming Principles 1 (CSC131) & 2 (CSC132) Software usage guide

Android Studio Setup Procedure

Welcome to Kmax Installing Kmax

About the Presentations

Ensuring your computer has Java

Using Eclipse for C Programming

Table of Contents. Troubleshooting Guide for Home Users

ADOBE DRIVE 4.2 USER GUIDE

Table of Contents. 1 Introduction Downloads Eclipse SDK Installation Eclipse Workspace Eclipse Preferences...

Eclipse Environment Setup

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

eftp Application User Guide

The QuickCalc BASIC User Interface

Mehran Sahami Handout #5 CS 106A September 27, 2017 Downloading Eclipse

SIS offline. Getting Started

Purpose. Why use Java? Installing the Software. Java

SAM4S Receipt Printer JPOS Driver. Mac OS X Installation Manual

Javac and Eclipse tutorial

Series 40 6th Edition SDK, Feature Pack 1 Installation Guide

Software Installation for CS121

Certified Core Java Developer VS-1036

Streams Version Installation and Registration

SAP GUI 7.30 for Windows Computer

Lecture (01) Getting started. Dr. Ahmed ElShafee

Installing Eclipse (C++/Java)

UNic Eclipse Mini Tutorial (Updated 06/09/2012) Prepared by Harald Gjermundrod

JGuiB User s Guide. JGuiB Development Team. Version 3.0 ( )

Downloading Java Development Kit (JDK), the Offline Client, and Utilizing the Offline Audit Tool

JOGL INSTALLATION. Installing JOGL. System Requirements. Step 1 - Verifying Java installation on your machine

Mehran Sahami Handout #5 CS 106A September 26, 2018 Downloading Eclipse

COPYRIGHTED MATERIAL. Installing Xcode. The Xcode Installer

Chapter 2. Editing And Compiling

Life Without NetBeans

Getting Started with Eclipse/Java

CSCI 201 Lab 1 Environment Setup

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

What s NetBeans? Like Eclipse:

Sentences Installation Guide. Sentences Version 4.0

CS 170 Java Tools. Step 1: Got Java?

How to Install (then Test) the NetBeans Bundle

Manual Update Java 7 25 Mac 64 Bit Offline

ENCM 339 Fall 2017: Editing and Running Programs in the Lab

User Guide NAS 3.0 Adapter (NAS30U2)

Aware IM Version 8.1 Installation Guide

1. The Apache Derby database

Creating Android Apps from Rh10

School Installation Guide ELLIS Academic 5.2.6

TEMPO INSTALLATION I O A. Platform Independent Notes 1. Installing Tempo 3. Installing Tools for the Plugins 5. v0.2.

Standard Edition (SE) application development Enterprise Edition (EE) enterprise development Micro Edition (ME) Internet of Things (IoT) development

Artix Version Installation Guide: Java

Slide 1 CS 170 Java Programming 1 Duration: 00:00:49 Advance mode: Auto

Before you start working with Java, you need to set up a Java development

You should now start on Chapter 4. Chapter 4 introduces the following concepts

This section contains information you should review before using this book. Any updates to the information presented here will be posted at:

Getting Started With NetLogo

For this class we are going to create a file in Microsoft Word. Open Word on the desktop.

XML and API Documentation

Release Date April 9, Adeptia Inc. 443 North Clark Ave, Suite 350 Chicago, IL 60654, USA

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

Installing SensIt, RiskSim, and TreePlan 3.1 INSTALLATION OVERVIEW 3.2 REMOVING PREVIOUS VERSIONS 3.3 THE ADD-IN XLA FILE

Quite Hot 3. Installation... 2 About the demonstration edition... 2 Windows... 2 Macintosh... 3

CS 170 Java Tools. Step 1: Got Java?

User Guide. ThinkFree Office Server Edition June 13, Copyright(c) 2011 Hancom Inc. All rights reserved

i2b2 Workbench Developer s Guide: Eclipse Neon & i2b2 Source Code

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

Getting Started With NetLogo

Laboratory 1: Eclipse and Karel the Robot

JPA - INSTALLATION. Java version "1.7.0_60" Java TM SE Run Time Environment build b19

POOSL IDE Installation Manual

Appendix B. Install Microsoft Personal Web Server

Getting Started. Citrix Load Manager. Version 1.0. Citrix Systems, Inc.

S D K Q U I C K S T A R T

Uninstall Java Manually Mac Os X 10.8 Server

You might think of Windows XP as a set of cool accessories, such as

Installing and configuring an Android device emulator. EntwicklerCamp 2012

CS 209 Spring, 2006 Lab 12: JAR Files Instructor: J.G. Neal

The ImageJ Eclipse Howto

Jerry Cain Handout #5 CS 106AJ September 30, Using JSKarel

Clean & Speed Up Windows with AWO

Online Backup Client User Manual

Installing CWM Client

Recommended Browser Settings

Network Management Utility

Using the Computer & Managing Files Part 2

Wwise Installation and Migration Guide

Vendio Stores WebDAV Setup & Access

500 Business Center Drive Pittsburgh, PA USA Phone: Fax: CAGE Code 1BGJ7

2008 Elluminate, Inc. All Rights Reserved. Installation Guide

Standard Edition (SE) application development Enterprise Edition (EE) enterprise development Micro Edition (ME) Internet of Things (IoT) development

Organizing Screens with Mission Control

Parallels Software International, Inc. Parallels Compressor. Installation Guide. Server

Installing and Building Apps on a Mac

Setting up your Computer

Installing CWM Client

Fiery X3eTY2 65C-KM Color Server. Utilities

XP: Backup Your Important Files for Safety

19 - This PC Inside This PC

Teradata Studio and Studio Express

Installing AppleWorks 6 FOR WINDOWS

Transcription:

Running Java Programs Written by: Keith Fenske, http://www.psc-consulting.ca/fenske/ First version: Thursday, 10 January 2008 Document revised: Saturday, 13 February 2010 Copyright 2008, 2010 by Keith Fenske. All rights reserved. Introduction The same Java program will run on many different operating systems: Linux, MacOS, Solaris, Windows, etc. This is an advantage to the programmer, because only one program needs to be written, and only one package needs to be distributed. This is an advantage to the user, because programs have a similar look and feel no matter where they are run. You must have the Java run-time environment (JRE) installed on your computer. You can download the JRE from Oracle (formerly Sun Microsystems): Java Run-Time Environment (JRE for end users) http://www.java.com/getjava/ Java Software Development Kit (JDK or SDK for programmers) http://www.oracle.com/technetwork/java/ NetBeans IDE (graphical editor for programmers) http://www.netbeans.org/ The JRE lets you run Java programs on your computer. The JDK (or SDK) compiles and tests Java programs. The IDE is for writing new Java programs. Follow instructions on the Java web site, with this advice. When given a choice between an on-line or web installation and an off-line or full installation, download the full setup and save the setup file in case you need it later. During setup, if you are given a choice between a typical or custom installation, choose the custom or complete setup with all optional components selected. The difference in size is small. Turn off automatic updates for Java, which can be found in Control Panel, Java icon, Update tab on Windows 2000/XP/Vista/7. Running Java Programs by: Keith Fenske page 1 of 7

Apple Macintosh An easy way to download Java programs as ZIP files and run them on MacOS is with the Apple Safari browser. Click on the web page s link for a ZIP file. Let Safari download and unpack the contents. The small Safari download window will have a button to show the files, or you can browse to the same location with the Mac Finder. Click on the file name for the main Java class, which is usually obvious or clearly identified in the PDF documentation. This will run the program with its default configuration. For anything more sophisticated, use a Terminal window similar to the command prompt in Windows or shell in Linux, and type a java command yourself with options. Linux and Sun Solaris Download and unpack the distribution or ZIP file into a directory/folder of your choice. Start a command shell and change directory (cd) to where the files are located. Type a java command with options as below. Note that Linux uses a forward slash (/) as a file separator instead of the backslash (\) in Windows. Microsoft Windows Programs compiled for older versions of Java run well on newer versions, so computers should have the latest version of Java supported for each version of Windows: Java 1.4 and 5.0 for Windows 98/ME, Java 6 for Windows 2000, Java 7 for Windows XP, etc. You can check your version of Java from the command line, also known as a console or DOS window. On Windows 98/ME, use Start button, Programs, MS-DOS Prompt. On Windows 2000/XP/Vista/7, use Start button, (All) Programs, Accessories, Command Prompt. Type this command, followed by the Enter key: java -version If Java is installed, the response will be something like: java version "1.6.0_45" Java(TM) SE Runtime Environment (build 1.6.0_45-b06) Java HotSpot(TM) Client VM (build 20.45-b01, mixed mode) Running Java Programs by: Keith Fenske page 2 of 7

And if Java is not installed, the response on Windows 2000/XP/Vista/7 will be: 'java' is not recognized as an internal or external command, operable program or batch file. Windows 98/ME will just say Bad command or file name. To close the command prompt (DOS window), type this command followed by the usual Enter key: exit Most small Java programs run from the command line. The same command line is what runs programs for desktop icons and Start menu items. Large packages may have installers to hide these details from you, but you shouldn t be afraid of the command line. Downloading Java Software Java programs on this web site are in ZIP files. Support for ZIP archives is built into Windows XP/Vista/7 and later. (Windows 2000 and earlier need separate ZIP software.) Once you have downloaded and saved a ZIP file, in a folder that you can find again such as My Documents, then you can show the contents of the ZIP file on Windows XP/Vista/7 by double clicking on the file name in My Documents or Windows Explorer (opens up like a regular subfolder), or you can extract files by right clicking on the ZIP file name, left clicking on Extract All, and following the prompts. You may need to do some cleaning up and/or moving of files to where you want them. Put the program files into a folder (directory) on your hard drive. The name of the folder and the location are your choice, except it is easier if the name does not include spaces, because spaces are a problem on command lines unless you quote arguments (something you probably don t want to know about). Assume that files will go into a C:\Java folder, that is, a main-level folder called Java in the root directory of the C: disk drive, which is easy to find and use from DOS. Unpack the ZIP file into this folder. For the FileChecksum application, the program files look like this: FileChecksum3.au (3 KB, barking dog sound) FileChecksum3.class (21 KB, executable program) FileChecksum3.doc (32 KB, documentation in Microsoft Word format) FileChecksum3.gif (14 KB, sample program image) FileChecksum3.ico (87 KB, icon for Windows) FileChecksum3.jar (12 KB, archive file with same class files inside) FileChecksum3.java (64 KB, source code) Running Java Programs by: Keith Fenske page 3 of 7

FileChecksum3.manifest (1 KB, main class manifest for archive file) FileChecksum3.pdf (72 KB, documentation in Adobe Acrobat format) FileChecksum3User.class (1 KB, helper class for main program) GnuPublicLicense3.txt (35 KB, legal notice) RunJavaPrograms.pdf (60 KB, these notes about running Java) You really only need to know the name of the main program (FileChecksum3) and where the files are located (C:\Java). Running Class Files Small Java programs are distributed as class files. One of the class files has the main program, usually the file with the simplest name that matches the name of the distribution package. For the FileChecksum example above, the main program is in a FileChecksum3.class file. To run this program on Windows, start a command prompt. Change to the folder with the program files and run the program with a java command: c: cd \java java FileChecksum3 The first line switches to the C: disk drive, if not already there. The second line switches to the folder containing the Java program files. The third line runs the program. The program name FileChecksum3 must appear exactly as shown; uppercase and lowercase letters are different in Java names. In this particular case, FileChecksum3 will open a graphical user interface or GUI window. When you are finished and close/exit the program, then you will return to the command prompt. You may close the command prompt with the exit command as shown above. Running JAR Files Larger Java applications are bundled in JAR files (meaning, Java archive). JAR files are really ZIP files with a manifest, if you want to rename them and look inside. They are used because major applications can have hundreds or thousands of class files far too many to unzip into a regular directory. Assume that you download an application called FluffySnakes3 in a JAR file. Then change the command line above to: c: cd \java java -jar FluffySnakes3.jar Running Java Programs by: Keith Fenske page 4 of 7

The only possible difference from the previous example is a scary error message saying: Failed to load Main-Class manifest attribute from FluffySnakes3.jar which means that the creator of the JAR file didn t correctly identify the class file for the main program. Many systems will run a JAR file by clicking (or double clicking) on the JAR file name while viewing a directory in your file browser (i.e., Windows Explorer). Unfortunately, some archive utilities associate themselves with the.jar suffix and prevent this from happening. The command line is the only guaranteed way of running a Java program. Java Run-Time Options For a list of run-time options for Java, use the following command line: java -help The -X option shows additional, non-standard options. One of the most useful of these on Windows is -Xmx to increase the amount of memory available to an application. The default is -Xmx64M or 64 megabytes (MB) for Java 1.4 and 5.0, and up to 256 MB for Java 6 and 7. Running an application with a command like: java -Xmx500M FileChecksum3 would give the program a maximum of 500 MB of memory for temporary data. Please note that options to Java itself come after the java command and before the program name. Many Java programs have their own options after the program name. The CLASSPATH Question One complication may arise when trying to run a Java program. Java looks for an environment variable called CLASSPATH. If it finds this variable, then that is a list of folders where it looks for class files. It won t look anywhere else, not even in the current directory, unless the path contains. as one of the choices. The symptom is an error message that says: Exception in thread "main" java.lang.noclassdeffounderror: FileChecksum3 To find out if your system has a CLASSPATH variable defined, type the following command in a DOS window: Running Java Programs by: Keith Fenske page 5 of 7

set CLASSPATH To temporarily change the CLASSPATH variable to the current directory when running a program, use a command line similar to the following: java -cp. FileChecksum3 Remember to use the correct program name, of course! To permanently change the CLASSPATH, you must find where it is being set. This is in Control Panel, System, Advanced, Environment Variables on Windows 2000/XP/Vista/7. The CLASSPATH is actually a good idea; it s just different than the way Windows likes to do things. If you don t already have a CLASSPATH variable, then create one in Control Panel with the value: C:\Java;. assuming that the Java program files are in C:\Java as per the examples above. Then, no matter what your current directory is in a DOS window, Java will always look for Java program files in C:\Java first, then in the current directory (. ) if it doesn t find them in C:\Java. Feel free to put the current directory before C:\Java:.;C:\Java If you already have a CLASSPATH from previous applications, insert C:\Java in the order that you want Java to search for program files, with semicolons (;) between folder names. This will make desktop icons and Start menu items much easier (next section). Desktop Icons and Menu Shortcuts Should you find a Java program to be popular, you can create a Start menu item or desktop shortcut on Windows 2000/XP/Vista/7. This works well for graphical applications; it does not apply to applications that run in console mode (command-line interface only). For a desktop icon, right click anywhere on the background (not on a program window), left click on New, then left click on Shortcut. For a Start menu item, create a shortcut in the system folder containing your personalized Start menu (which may be hidden, and varies with each version of Windows). You will first be asked to type the location of the item. Type a partial Java command like: java.exe FileChecksum3 Running Java Programs by: Keith Fenske page 6 of 7

Then click the Next button. You will be asked to type a name for this shortcut. You may type any name that you want. Then click the Finish button. Windows will create the desktop icon or menu shortcut. You can review the settings by right clicking on the icon or name, and left clicking on Properties. You will notice that Windows has expanded the partial command line: %windir%\system32\java.exe FileChecksum3 with the program starting in a folder called %windir% (a substitution for C:\Windows on most computers). If you have a CLASSPATH variable defined (as recommended above), the starting folder isn t important. If you don t have a CLASSPATH, then the starting folder must be the location of the Java class files. If there is a mistake when you try to run the icon or the menu item, you will briefly see a black DOS window, which immediately closes after printing an error message that you don t have time to read. If you don t want to see a DOS console window while the Java program is running, then choose the Run: Minimized option on the Shortcut dialog tab. An additional property is the Change Icon button. Use this to set a specific program icon, such as an icon that came with the program in an ICO file. Removal or Uninstall For Java programs on this web site, remove the programs from your computer by deleting the installation files. If the folder that contained the files is now empty, you may also delete the folder... if you created the folder, of course, not the system. If you created desktop shortcuts or Start menu items, then delete those too. Unless otherwise said, there are no hidden configuration or preference files, and no information is stored in the Windows system registry. You don t need an uninstall program. file: RunJavaPrograms.doc 2017-02-18 Running Java Programs by: Keith Fenske page 7 of 7