Using Java without BlueJ 5.0. 2 BlueJ projects A BlueJ project is stored in a directory on disk. A BlueJ package is stored in several different files.

Slides:



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

1 Copyright © 2002 Pearson Education, Inc.. 2 Chapter 2 Getting Started.
Introduction to programming in java. Input and output to screen with Java program Structure of Java programs Statements Conditional statements.
Foundations of Programming and Problem Solving Introduction.
Introduction to Programming Java Lab 1: My First Program 11 January JavaLab1.ppt Ping Brennan
SOFTWARE AND PROGRAMMING 1
11-Jun-14 The assert statement. 2 About the assert statement The purpose of the assert statement is to give you a way to catch program errors early The.
More Sophisticated Behaviour 1 Using library classes to implement more advanced functionality.
5.9 + = 10 a)3.6 b)4.1 c)5.3 Question 1: Good Answer!! Well Done!! = 10 Question 1:
Chapter 10 Ch 1 – Introduction to Computers and Java Streams and File IO 1.
Introduction To Java Objectives For Today â Introduction To Java â The Java Platform & The (JVM) Java Virtual Machine â Core Java (API) Application Programming.
How do we make our Welcome.java program do something? The java in our Welcome.java file won’t do anything by itself. We need to tell the computer to execute.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 4.0.
1 Fall 2008ACS-1903 Chapter 1 Topics Java History Java Programs Why Program? Computer Systems: Hardware and Software Programming Languages What Is a Program.
How to Create a Java program CS115 Fall George Koutsogiannakis.
Java Programming Working with TextPad. Using TextPad to Work with Java This text editor is designed for working with Java You can download a trial version.
String Concatenation (operator overloading) 3.0.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 1 “ Introduction to Java and OOP”
Java Intro. A First Java Program //The Hello, World! program in Java public class Hello { public static void main(String[] args) { System.out.println("Hello,
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.
Using Java without BlueJ
Lab 1 Instructor: Jolanta Soltis.
Introduction to Java.
Lecture 1: Overview of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++ Designed.
CS0007: Introduction to Computer Programming Setting Up Java.
CMSC 341 Introduction to Java Based on tutorial by Rebecca Hasti at
public static void main (String[] args)
From BlueJ to NetBeans SWC 2.semester.
(C) 2010 Pearson Education, Inc. All rights reserved.  Java programs normally go through five phases  edit  compile  load  verify  execute.
Basics Programming Concepts. Basics A computer program is a set of instructions to tell a computer what to do Machine language = circuit level language.
SOFTWARE AND PROGRAMMING 1 Lecture: Gor B4 7:40-9:00 (from ) Lab: SH131, BBK536 6:00-7:30 (from ) [each student must have obtained access.
UCSC All rights reserved. No part of this material may be reproduced and sold. 1 IT1202-Fundamentals Of Programming (Using JAVA) Interacting with.
Java Introduction to JNI Prepared by Humaira Siddiqui.
1 CSC204 – Programming I Lecture 2 Intro to OOP with Java.
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
POS 406 Java Technology And Beginning Java Code
CMSC 150 INTRODUCTION TO COMPUTING CS 150: Wed 11 Jan 2012.
Introduction to Java Programming with Forte Y. Daniel Liang.
1 COS 260 DAY 2 Tony Gauvin. 2 Agenda Questions? Class roll call Blackboard Web Resources Objects and classes 1 st Mini quiz on chap1 terms and concepts.
COP 3330 Notes 1/12. Today's topics Downloading Java and Eclipse Hello World Basic control structures Basic I/O Strings.
Object Oriented Programming Lecture 3. Introduction  In discussing Java, some items need to be clarified  The Java programming language  The Java virtual.
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.
SOFTWARE AND PROGRAMMING 1 Lecture: MB33 7:30-9:00 (except 11& ) Lab: B43, MB321, MB536 6:00-7:30 (from ) [each student must have obtained.
SOFTWARE AND PROGRAMMING 1 Lecture: UCL BC57:30-9:00 (9& – from 6:00) Lab: SH 131, SH B12 6:00-7:30 (from ) (students will be assigned.
Preliminaries CS 310: Object-oriented Programming Java API.
EIE375 BlueJ: Getting Started Dr Lawrence Cheung.
CSE S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing with Graphics.
SOFTWARE AND PROGRAMMING 1 Lecture: MB33 7:30-9:00 (11& – from 6:00) Lab: B43, MB321, MB536 6:00-7:30 (from ) EACH student must have obtained.
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.
Java Programming, Second Edition Appendix A Working with Java SDK 1.4.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Overview of Java CSCI 392 Day One. Running C code vs Java code C Source Code C Compiler Object File (machine code) Library Files Linker Executable File.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Introduction to Java Programming. 2 Chapter 1 Introduction to Java and Forte F What Is Java? F Getting Started With Java Programming –Create, Compile.
THE C PROGRAMMING ENVIRONMENT. Four parts of C environment  Main menu  Editor status line and edit window  Compiler message window  “Hot Keys” quick.
3/5/2002e-business and Information Systems1 Java Java Java Virtual Machine (JVM) Java Application Program Interface (API) HW Kernel API Application Programs.
Objects First With Java A Practical Introduction Using BlueJ Using Java without BlueJ 1.0.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
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.
CS 201 Lecture 1 (b) Using an IDE Tarik Booker CS 201: Introduction to Programming California State University, Los Angeles.
7 Class documentation and libraries
Compiling and Running a Java Program
Programming without BlueJ Week 12
Hands-on Introduction to JAVA
File I/O ICS 111: Introduction to Computer Science I
Java Intro.
Presentation transcript:

Using Java without BlueJ 5.0

2 BlueJ projects A BlueJ project is stored in a directory on disk. A BlueJ package is stored in several different files. Some files store the source code, some store the compiled code, some store additional information. BlueJ uses standard Java format for some files and adds some additional files with extra information. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

3 The BlueJ directory structure Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling UserInterface CalcEngine Calculator project: calculator c:\bluej\calculator\ Calculator.java Calculator.class Calculator.ctxt CalcEngine.java CalcEngine.class CalcEngine.ctxt package.bluej UserInterface.java UserInterface.class UserInterface.ctxt

4 The BlueJ file structure package.bluej – the the package file. Contains information about classes in the package. One per package. *.java - standard Java source file (text). One per class. *.class - standard Java code file. One per class *.ctxt - BlueJ context file. Contains extra information for a class. One per class. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

5 Standard Java files Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling source files: *.java Java source files contain the source code in readable form, as typed in by the programmer. class files: *.class Java class files contain byte code (a machine readable version of the class). They are generated by the compiler from the source file.

6 The edit-compile-execute cycle Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling source file class file editor compiler (javac) virtual machine (java)

7 Editing Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling A file can be edited in any text editor –Notepad, emacs, jEdit, PFE, vi,... Don't use Word: by default, Word does not save in text format Make sure to save with a.java filename before compiling!

8 Command line invocation Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Compilation and execution of Java in JDK are done from a command line On Microsoft systems: DOS shell On Unix: Unix shell Must make sure that the commands for compiler and runtime are in the command path.

9 Compiling Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Name of the JDK compiler: javac To invoke: javac compiles and all classes it depends on Example: cd C:\bluej\zuul javac Game.java

10 Error messages Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling C:\bluej\zuul> javac Game.java Game.java:22: ';' expected. private Parser parser ^ 1 error C:\bluej\zuul> The programmer has to open the file in the editor, find the line number, fix the error and recompile.

11 Execution Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling C:\bluej\zuul> java Game java starts the Java virtual machine. The named class is loaded and execution is started. Other classes are loaded as needed. Only possible if class has been compiled.

12 Problem: Execute what? Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling If we try: C:\bluej\zuul> java Game Exception in thread "main" java.lang.NoSuchMethodError: main The problem: how does the system know which method to execute?

13 The main method Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling The answer: The java system always executes a method called main with a certain signature: public static void main(String[] args) {... } For this to work, such a method must exist!

14 The main method Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling main must exist. main must be public. main must be static (class method). main must have a String[] parameter. Only main can be invoked.

15 Main method - example Consider placing in a separate class, containing just this. The main method should –create an object –call the first method Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling public static void main(String[] args) { Game game = new Game(); game.play(); }