Objects First With Java A Practical Introduction Using BlueJ Using Java without BlueJ 1.0.

Slides:



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

Introduction to Java 2 Programming Lecture 3 Writing Java Applications, Java Development Tools.
SOFTWARE AND PROGRAMMING 1
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.
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.
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
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.
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.
Computer Science A 1: 3/2. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated.
1 Further OO Concepts II – Java Program at run-time Overview l Steps in Executing a Java Program. l Loading l Linking l Initialization l Creation of Objects.
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.
LESSON 2 CREATING A JAVA APPLICATION JAVA PROGRAMMING Compiled By: Edwin O. Okech [Tutor, Amoud University]
(C) 2010 Pearson Education, Inc. All rights reserved.  Java programs normally go through five phases  edit  compile  load  verify  execute.
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.
1 Introduction to Java Brief history of Java Sample Java Program Compiling & Executing Reading: => Section 1.1.
UCSC All rights reserved. No part of this material may be reproduced and sold. 1 IT1202-Fundamentals Of Programming (Using JAVA) Interacting with.
Java Spring PImage Let’s look at the PImage class in ProcessingPImage –What are the fields (i.e., variables)? –What methods are available? –What.
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.
CSC204 – Programming I Lecture 4 August 28, 2002.
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
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.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
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.
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.
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.
1 Creating Web Services Presented by Ashraf Memon Hands-on Ghulam Memon, Longjiang Ding.
22-July-2002cse142-13B-Development © 2002 University of Washington1 Development Tools CSE 142, Summer 2002 Computer Programming 1
”Java and JMLfor Dummies” The Java source code is written in a text file using your favourite editor (Notepad) and is saved with extension.java. Be careful.
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.
CIS 234: Java Methods Dr. Ralph D. Westfall April, 2010.
Programming Languages and Paradigms Activation Records in Java.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 5 Methods.
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.
CSC Java Programming, Fall, 2008 Week 3: Objects, Classes, Strings, Text I/O, September 11.
3/5/2002e-business and Information Systems1 Java Java Java Virtual Machine (JVM) Java Application Program Interface (API) HW Kernel API Application Programs.
Methods.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
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.
Chapter 1 Object Orientation: Objects and Classes.
CS 201 Lecture 1 (b) Using an IDE Tarik Booker CS 201: Introduction to Programming California State University, Los Angeles.
Introduction of Java Fikri Fadlillah, S.T.
7 Class documentation and libraries
Programming without BlueJ Week 12
Lecture Note Set 1 Thursday 12-May-05
CompSci 230 Software Construction
Command Line Arguments
File I/O ICS 111: Introduction to Computer Science I
Presentation transcript:

Objects First With Java A Practical Introduction Using BlueJ Using Java without BlueJ 1.0

2 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Quiz public int getValue() { return value; } 1.What is the return type of the method? 2.What kind of a method is this?

3 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Quiz (…cont’d) public int value = 0;... public void setValue(int num) { int smallNum; smallNum = num*num; value += smallNum; } 1.What is the formal parameter here? What is its data type? 2.What kind of a method is this? 3.What is the name of the local variable?

4 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling 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.

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

6 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling The BlueJ file structure bluej.pkg - the package file. Contains information about classes in the package. One per package. bluej.pkh - backup of the package file. *.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.

7 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Standard Java files 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.

8 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) The edit-compile-execute cycle

9 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Editing A file can be edited in any text editor –Notepad, emacs, PFE,... careful with using Word: by default, Word does not save in text format Make sure to save before compiling!

10 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Command line invocation 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.

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

12 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Error messages 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.

13 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Execution 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.

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

15 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling The main method 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!

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

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

18 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Testing to test, test drivers must be written all test method calls must be written into a test method all relevant parameter combination must be tested if tests depend on the results of earlier tests, the test driver must be edited and recompiled the test driver must create the objects