public static void main (String[] args)

Slides:



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

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.
Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.
INTRODUCTION Chapter 1 1. Java CPSC 1100 University of Tennessee at Chattanooga 2  Difference between Visual Logic & Java  Lots  Visual Logic Flowcharts.
Introduction To Java Objectives For Today â Introduction To Java â The Java Platform & The (JVM) Java Virtual Machine â Core Java (API) Application Programming.
Object Oriented Programming in Java George Mason University Fall 2011
Begin Java Pepper. Objectives What is a program? Learn the basics of your programming tool: BlueJ Write a first Java program and see it run Make some.
JAVA BASICS SYNTAX, ERRORS, AND DEBUGGING. OBJECTIVES FOR THIS UNIT Upon completion of this unit, you should be able to: Explain the Java virtual machine.
Introduction to Object-Oriented Programming CS 21a: Introduction to Computing I First Semester,
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.
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.
How to Create a Java program CS115 Fall George Koutsogiannakis.
How do we make our HelloTester.java program do something? The java in our HelloTester.java file won’t do anything by itself. We need to tell the computer.
Introduction to Java Programming
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
Computer Science A 1: 3/2. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated.
Writing Methods. Create the method Methods, like functions, do something They contain the code that performs the job Methods have two parts.
Introduction to Java.
CS0007: Introduction to Computer Programming Setting Up Java.
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
Marlene Galea.  The JDK (Java Development Kit)  An IDE (Integrated Development Environment) ◦ Different IDEs include:  JCreator  NetBeans  BlueJ.
Editing Java programs with the BlueJ IDE. Working environments to develop (= write) programs There are 2 ways to develop (write) computer programs: 1.Using.
Introduction to Java Tonga Institute of Higher Education.
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.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Programming Languages Machine.
UCSC All rights reserved. No part of this material may be reproduced and sold. 1 IT1202-Fundamentals Of Programming (Using JAVA) Interacting with.
FRST JAVA PROGRAM. Getting Started with Java Programming A Simple Java Application Compiling Programs Executing Applications.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
Java and C# [this is a bonus – it is not a required lesson] ACO101: Introduction to Computer Science.
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.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
POS 406 Java Technology And Beginning Java Code
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Java Programming, Second Edition Chapter One Creating Your First Java Program.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Chapter 1 Section 1.1 Introduction to Java Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
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.
EIE375 BlueJ: Getting Started Dr Lawrence Cheung.
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
Lecture 1. Introduction to Programming and Java MIT- AITI 2003.
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.
CSI 3125, Preliminaries, page 1 Compiling the Program.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Today… “Hello World” ritual. Brief History of Java & How Java Works. Introduction to Java class structure. But first, next slide shows Java is No. 1 programming.
First Programs Chapter 2 The Java language (compiler) on CD ROM Create a program using an editor Compile the program Run the program Integrated Development.
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.
3/5/2002e-business and Information Systems1 Java Java Java Virtual Machine (JVM) Java Application Program Interface (API) HW Kernel API Application Programs.
1.1: Objects and Classes msklug.weebly.com. Agenda: Attendance Let’s get started What is Java? Work Time.
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.
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.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
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.
CS210 Intermediate Computing with Data Structures (Java)
Object-Oriented Programming Using Java
Programming without BlueJ Week 12
Writing Methods.
Hands-on Introduction to JAVA
Java Intro.
Outcome of the Lecture Upon completion of this lecture you will be able to understand Fundamentals and Characteristics of Java Language Basic Terminology.
Presentation transcript:

public static void main (String[] args) Java without BlueJ public static void main (String[] args)

Java without BlueJ BlueJ is an Integrated Development Environment (IDE) for Java. BlueJ provides an editor and access to the standard Java compiler and run-time system. Its innovation lies in its capabilities for creating objects and invoking methods on them interactively (supporting the passing of arguments and return of results). This works through a graphical representation of classes and object instances and simple point-and-click operation. This lets us immediately start testing newly written classes without having to write any testing code. Inspectors let us see running results. Additionally, BlueJ provides a mechanism for recording a series of interactive tests on a class together with user-defined correct results for those tests. These recordings can be re-run (with the results checked automatically) on the class each time the class code is changed – regression testing. As code is continually being maintained, this is a huge help! Chapter 6

Java without BlueJ But what if we don’t have BlueJ? How do we get anything written, compiled and run? How do we test stuff? Write (using any editor) each Java class in a separate file, whose name is the class name with the suffix: .java For example, the Date class goes in the file Date.java To compile, we need a command window (e.g. Command Prompt in Windows Accessories – or any Unix window). Change directory (cd) to wherever the .java files are.

Java without BlueJ But what if we don’t have BlueJ? How do we get anything written, compiled and run? How do we test stuff? Change directory (cd) to wherever the .java files are. To compile, use the command: javac Date.java If no errors, this produces the file: Date.class .class files contain Java byte code. Don’t try to look at it – these files don’t hold anything humans can read!

Java without BlueJ But what if we don’t have BlueJ? How do we get anything written, compiled and run? How do we test stuff? .class files contain Java byte code. Don’t try to look at it – these files don’t hold anything humans can read! How do we create class objects and execute their methods? The standard Java Development Kit (JDK) provides no way (outside of a Java program) to construct objects! But it does have a way to invoke a (very particular) static method – for which, of course, we only need the class (not an object).

Java without BlueJ class DemoMain { public static void main (String[] args) { } } Only a static method called main, with exactly the above signature, can be run with the standard command.

Java without BlueJ class DemoMain { /** * Print arguments supplied to this program. */ public static void main (String[] args) { for (String s : args) { System.out.println (s); } } } class DemoMain { public static void main (String[] args) { } } Only a static method called main, with exactly the above signature, can be run with the standard command.

Java without BlueJ % javac DemoMain.java % java DemoMain class DemoMain { /** * Print arguments supplied to this program. */ public static void main (String[] args) { for (String s : args) { System.out.println (s); } } } compile % javac DemoMain.java % java DemoMain % javac DemoMain.java % % % javac DemoMain.java invoke main

Java without BlueJ compile invoke main class DemoMain { /** * Print arguments supplied to this program. */ public static void main (String[] args) { for (String s : args) { System.out.println (s); } } } compile % javac DemoMain.java % java DemoMain % java DemoMain one two:a-b –three one two:a-b –three % % javac DemoMain.java % java DemoMain % % javac DemoMain.java % java DemoMain % java DemoMain one two:a-b –three % javac DemoMain.java % java DemoMain invoke main

Java without BlueJ For example, the BlueJ project tech-support-complete: InputReader Responder SupportSystem With BlueJ, we make a SupportSystem object, then click the start() method.

Java without BlueJ For example, the BlueJ project tech-support-complete: With BlueJ, we make a SupportSystem object, then click the start() method. Without BlueJ, we have to program: With BlueJ, we make a SupportSystem object, then click the start() method. class TechSupportMain { /** * Print arguments supplied to the program */ public static void main (String[] args) { new SupportSystem ().start (); } }

Java without BlueJ compile invoke main class TechSupportMain { /** * Print arguments supplied to the program */ public static void main (String[] args) { new SupportSystem ().start (); } } compile % javac TechSupport.java % java TechSupport Welcome to the DodgySoft Technical Support System. Please tell us about your problem. We will assist you with any problem you might have. Please type 'bye' to exit our system. > Your software is a load of rubbish ... I need a bit more information on that. % javac TechSupport.java % java TechSupport Welcome to the DodgySoft Technical Support System. Please tell us about your problem. We will assist you with any problem you might have. Please type 'bye' to exit our system. > % javac TechSupport.java % java TechSupport Welcome to the DodgySoft Technical Support System. Please tell us about your problem. We will assist you with any problem you might have. Please type 'bye' to exit our system. > Your software is a load of rubbish ... % javac TechSupport.java % java TechSupport invoke main

public static void main (String[] args) Java without BlueJ Review The compiler from Sun’s standard Java Development Kit. This compiles .java files to .class files. javac Launches the Java Virtual Machine (JVM), which invokes the main method of the class to which it is applied. We give it the name of the class only (no .class suffix). java The main method of the class to which java is applied must have the header: public static void main (String[] args)