Introduction to Java 2 Programming Lecture 4 Writing Java Applications, Java Development Tools.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 5 Quick Recap; Error-handling.
Advertisements

Introduction to Java 2 Programming Lecture 2 Java Syntax, Robocode.
Introduction to Java 2 Programming Lecture 3 Writing Java Applications, Java Development Tools.
Using Java without BlueJ BlueJ projects A BlueJ project is stored in a directory on disk. A BlueJ package is stored in several different files.
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Design By Contract Using JMSAssert.
Packages Sudhir Talasila Preeti Navale. Introduction Packages are nothing more than the way we organize files into different directories according to.
Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.
Programmer-defined classes Part 2. Topics Returning objects from methods The this keyword Overloading methods Class methods Packaging classes Javadoc.
Using Eclipse. Getting Started There are three ways to create a Java project: 1:Select File > New > Project, 2 Select the arrow of the button in the upper.
Dale Roberts Introduction to Java - First Program Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Introduction To Computers and Programming Lecture 2: Your first program Professor: Evan Korth New York University.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
1 Introduction to Java and Applet Lecture 3 from Chapters 1 and 2 of the complete reference.
1 Introduction to Java and Applet. 2 Download Java Compiler (1)
Object-Oriented Enterprise Application Development Javadoc Last Updated: 06/30/2001.
1 Applets Chapter 1 To understand:  why applets are used to extend the capabilities of Web pages  how an applet is executed and know about the restrictions.
Winter 2005Jason Prideaux1 Apache ANT A platform independent build tool for Java programs.
01 Introduction1June Introduction CE : Fundamental Programming Techniques.
Using Java without BlueJ Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling BlueJ projects A BlueJ.
Using Java without BlueJ Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling BlueJ projects A BlueJ.
1 More on Arrays Arrays of objects Command line arguments The ArrayList class Javadoc Review Lecture 8 notes and L&L 7.1 – 7.2 Reading for this lecture:
Using Java without BlueJ
Applying OO Concepts Using Java. In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The.
Introduction to the JDK Java for Computational Finance
public static void main (String[] args)
Java and Project Delivery E&CE 250 Winter 2002
ACM/JETT Workshop - August 4-5, Guidelines For Using BlueJ.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Java Introduction to JNI Prepared by Humaira Siddiqui.
CSCE 2013L: Lab 1 Overview  Java Basics The JVM Anatomy of a Java Program  Object-Oriented Programming Overview  Example: Payroll.java JDK Tools and.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
COP 3330 Notes 1/12. Today's topics Downloading Java and Eclipse Hello World Basic control structures Basic I/O Strings.
CS591x A very brief introduction to Java. Java Developed by Sun Microsystems was intended a language for embedded applications became a general purpose.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
EE2E1. JAVA Programming Lecture 3 Java Programs and Packages.
DOS and the Command Line CS 21a: Introduction to Computing I First Semester,
22-July-2002cse142-13B-Development © 2002 University of Washington1 Development Tools CSE 142, Summer 2002 Computer Programming 1
CS 4244: Internet Programming Network Programming in Java 1.0.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Chapter 2© copyright Janson Industries Java ▮ Java/PC programming environment ▮ Java syntax rules ▮ Java documentation ▮ Java/RAD coding example.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Java Class Structure. Class Structure package declaration import statements class declaration class (static) variable declarations* instance variable.
Georgia Institute of Technology Creating Classes part 4 Barb Ericson Georgia Institute of Technology May 2006.
CreatingClasses-SlideShow-part41 Creating Classes part 4 Barb Ericson Georgia Institute of Technology Dec 2009.
A brief introduction to javadoc and doxygen. What’s in a program file? 1. Comments 2. Code.
Lecture 2 February 3, Installing PFE Just unzip the file you download into any directory, such as C:\Program Files\PFE You may right-click on pfe32.exe.
Classes, Interfaces and Packages
CPRG 215 Introduction to Object-Oriented Programming with Java Module 1-Introduction to Java Topic 1.3 Write Your First Java Program Produced by Harvey.
Creating Web Services Presented by Ashraf Memon Presented by Ashraf Memon.
In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The import statement and using prewritten.
C. Thomas Wu An Intro O-O Java Programming javadoc Utility.
Objects First With Java A Practical Introduction Using BlueJ Using Java without BlueJ 1.0.
1 Applets Programming. Introduction Java programs are divided into two main categories, applets and applications. An application is an ordinary Java program.
Today Javadoc. Packages and static import. Viewing API source code. Upcoming Topics: –protected access modifier –Using the debugger in Eclipse –JUnit testing.
Using Java without BlueJ BlueJ projects A BlueJ project is stored in a directory on disk. A BlueJ package is stored in several different files.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
CS-140 Dick Steflik Lecture 3. Java C++ Interpreted optimized for the internet Runs on virtual ized machine Derived from C++ Good object model Widely.
Introduction to javadoc
Applying OO Concepts Using Java
Anatomy of a Java Program
Introduction to javadoc
Java IDE Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
Developing Java Applications with NetBeans
Developing Java Applications with NetBeans
Corresponds with Chapter 5
Presentation transcript:

Introduction to Java 2 Programming Lecture 4 Writing Java Applications, Java Development Tools

Overview Java Programming Tools Command-Line Applications Practical Exercises

Java Programming Tools Javac – the Java Compiler Java – the Java Executable (virtual machine) Javadoc – Java Documentation generator Jar – Java ARchive creator All found in %JAVA_HOME%\bin

Javac – the Java Compiler Generates bytecode (.class files) from source code (.java files) –One class file per source file –Usage example: javac MyApplication.java javac com\ldodds\intro2java\Robot.java Javac expects source code to be organised into directories according to package structure –One directory per dotted portion of package

Sample Directory Structure E.g: package com.ldodds.intro2java;

Java – the Virtual Machine Executes the virtual machine and loads one or more classes into it Specify the class name (including packages) as a parameter –Dont indicate the class file, but the class name Examples: java MyApplication java com.ldodds.intro2java.Robot

Javadoc – the Documentation Generator Automatically generates HTML documentation from Java source code –Very efficient way to produce development documentation for your application. –E.g: javadoc com\ldodds\intro2java\Robot.java Output can be customised in a number of different ways, –usually by adding special tags to the source code –List of useful tags in the Tools Reference handout

Javadoc Example /** * A simple Calculator * Leigh Dodds */ public class Calculator { /** * Adds two numbers together and returns the result */ public int plus(int x, int y) { return x + y; }

Jar Tool Java ARchive –Basically a zip file, used to package java classes –E.g. for delivery as an applet or application Usually contain a Manifest –An index of the contents of a jar file –Major benefit is indicating which class holds the main method –Allows an application to be launched automatically from a jar file E.g. by double-clicking the archive

The CLASSPATH The CLASSPATH is –How Java finds compiled classes –A system property –A list of directories and/or jar files (similar to PATH) –A common source of frustration! –E.g: CLASSPATH=c:\classes;c:\applications\app.jar Classify Java tools into three groups: –File based –CLASSPATH based –And mixed mode (I.e. use both)

File based tools Javadoc, jar Accept command-line parameters referring to files. Read the directory structure to find related files javadoc c:\intro2java\src\intro2java\*.java Result in file-based errors

CLASSPATH based tools java, javap Refer to classes and not files Ignore the file-system, except for those directories mentioned in the CLASSPATH –Starts at those directories and walks down to find the correct.class files –Can look inside JAR files to do the same Result in exceptions or errors, e.g. ClassNotFoundException ; NoClassDefFoundErrors

CLASSPATH based tools Example: E.g. CLASSPATH=c:\src java com.ldodds.intro2java.Robot

Mixed mode tools javac Accept parameters referring to files BUT, Read the CLASSPATH to find related classes javac c:\intro2java\src\intro2java\*.java Results in file errors (relating to parameters), and cannot resolve symbol errors (relating to missing classes)

CLASSPATH Tips Always add the current working directory to the CLASSPATH SET CLASSPATH=%CLASSPATH%;. Good idea keep classes and source separate (e.g. bin and src directories) –But need to be careful when compiling Use a global classes directory, e.g. c:\classes –Add this to the CLASSPATH –Always compile into that directory SET CLASSPATH=%CLASSPATH%;c:\classes javac –d c:\classes *.java

Overview Java Programming Tools Command-line Applications Practical Exercises

Command Line Applications Java has no notion of executable –Just loads classes into the virtual machine Starting a Java application involves calling a method –Which may then create objects, call other methods, etc, etc –There needs to be a starting point to trigger the application to run

The main method To turn a class into an application, give it a main method: public static void main(String[] args) Must be of this format (otherwise Java cant find it) Can then be invoked from the command-line –Do all the work to initialise the app (create objects, etc) in this method –Minimise the amount of code in there: just create an object or two, and call their methods.

Command Line Parameters Parameters are passed in as an array E.g.: java MyApplication param1 param2 param3 Can also use System Properties –Parameters global to the whole virtual machine –Get them with the System.getProperty() method //the command line java –DpropertyName=propertyValue MyApplication //In the code String value = System.getProperty(propertyValue);

Overview More Syntax –Constants, Strings, Arrays The Object Lifecycle Java Programming Tools Practical Exercises

The Calculator