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.

Slides:



Advertisements
Similar presentations
Introduction to programming in java. Input and output to screen with Java program Structure of Java programs Statements Conditional statements.
Advertisements

compilers and interpreters
Dale Roberts Introduction to Java - First Program Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
Chapter 1 Introduction to JAVA. Why Learn JAVA? Java is one of the fastest growing programming language in the world. Java is one of the fastest growing.
Chapter 1: Introduction
CPSC150 Fall 2008 Dr. L. Lambert. CPSC150 Overview Syllabus Use Textbook, ask questions, extra thorough, I will post sections covered All information.
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.
Using JOptionPanes for graphical communication with our programs. Pages Horstmann 139.
How to Create a Java program CS115 Fall George Koutsogiannakis.
Lecturer: Fintan Costello Welcome to Hdip 001 Introduction to Programming.
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.
CHAPTER 1 INTRODUCTION GOALS  To understand the activity of programming  To learn about the architecture of computers  To learn about machine code and.
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,
01 Introduction1June Introduction CE : Fundamental Programming Techniques.
 2003 Prentice Hall, Inc. All rights reserved. Customized by Sana Odeh for the use of this class. 1 Introduction to Computers and Programming in JAVA.
1 Programming Languages Translation  Lecture Objectives:  Be able to list and explain five features of the Java programming language.  Be able to explain.
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
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.
Welcome to COMP 1001 First Year Computer Science Lecturer: Fintan Costello.
Methods: a first introduction Two ways to make tea: 1: boil water; put teabag into cup;... etc : tell your younger brother: makeTea(1 milk, 0 sugar);
Introduction to Java.
Chapter 1 - Introduction. Ch 1Goals To understand the activity of programming To learn about the architecture of computers To learn about machine code.
Programming a computer. What does programming a computer mean ? Programming a computer: Since a computer can only execute machine instructions (encoded.
IB Computer Science II Paul Bui
“Introduction to Programming With Java”
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
Introduction to Java Tonga Institute of Higher Education.
CSCI 273: Processing An Introduction. Programming Languages –An abstract "human understandable" language for telling the computer what to do –The abstract.
Basics Programming Concepts. Basics A computer program is a set of instructions to tell a computer what to do Machine language = circuit level language.
COMP 110: Introduction to Programming Tyler Johnson January 14, 2009 MWF 11:00AM-12:15PM Sitterson 014.
An intro to programming. The purpose of writing a program is to solve a problem or take advantage of an opportunity Consists of multiple steps:  Understanding.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Programming Languages Machine.
Welcome to the Lecture Series on “Introduction to Programming With Java”
©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 1 Chapter 1 Introduction.
FRST JAVA PROGRAM. Getting Started with Java Programming A Simple Java Application Compiling Programs Executing Applications.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
1 CSC204 – Programming I Lecture 2 Intro to OOP with Java.
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.
Week 1 - Friday.  What did we talk about last time?  Our first Java program.
Python From the book “Think Python”
Clement Allen, PhD Florida A&M University SUMMER 2006.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture.
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.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
8/31: Intro to Java, Languages, and Environments Types of programming languages –machine languages –assembly languages –high-level languages Java environment.
Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
Introduction to Python Lesson 1 First Program. Learning Outcomes In this lesson the student will: 1.Learn some important facts about PC’s 2.Learn how.
Chapter 1 Introduction. Chapter Goals To understand the activity of programming To learn about the architecture of computers To learn about machine code.
CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To learn about the architecture of computers To learn about machine code.
Lecture1 Instructor: Amal Hussain ALshardy. Introduce students to the basics of writing software programs including variables, types, arrays, control.
Compilers and Interpreters
CS 177 Recitation Week 1 – Intro to Java. Questions?
1/16: Intro to Java, Languages, and Environments Types of programming languages –machine languages –assembly languages –high-level languages Java environment.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to Computers,
Introduction to Object Oriented
Introduction to programming in java
Object-Oriented Programming Using Java
Chapter 3 GC 101 Java Fundamentals.
Comp Sci 200 Programming I Jim Williams, PhD.
String Output ICS 111: Introduction to Computer Science I
Hands-on Introduction to JAVA
Introduction to Algorithm Design
Computer Programming-1 CSC 111
Presentation transcript:

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 the program in the file. This is a two-stage process. First stage: Compile the program into a concise set of instructions your computer can carry out directly >javac Welcome.java Second stage: Tell the computer to carry out the compiled instructions >java Welcome Welcome to Java javac stands for java compiler Tells the computer to execute the compiled java instructions in Welcome.class javac puts the compiled instructions in a new file Welcome.class

Translating from high to low..... Human speaks English Programmer encodes problem in a high-level Language (Java) Compiler Translates Java into compiled code Computer executes machine code instructions

public class Welcome { public static void main(String[] args){ System.out.println(“Welcome to java”); } Java source code in file Welcome.java 3%(*$&£.... (*&£*&£ *(&^^!__£+ (£()*&(*H###~}{}{} (*(*(*(*£ Java bytecode in file Welcome.class Program instructions carried out JAVAC compiles the source code JAVA virtual machine executes code

Writing your first program Open a new file in Notepad (or any other simple editor; not Word, tho!). You’ll find Notepad under Programs\Accessories. Type the Welcome.java code into this new file. Save the file in the Java folder in your home directory, with the name Welcome.java You have now written and saved your first draft of the program. Next you need to compile your program (convert it into a form that can do something), and once compiled, to run it (see what it does). Exit Notepad.

Compiling your program Open the command prompt on your computer. You’ll find this under Programs\Accessories. The command prompt is a window that allows you to type commands directly to the computer. Type cd H:\Java  at the command prompt (this command puts you in the Java folder of your Home ( H: ) directory) Type dir  to get a dir ectory of all files in H:\Java (you will see Welcome.java)

Compiling your program (continued) Type dir  to get a dir ectory of all files in H:\Java (you will now see Welcome.java and Welcome.class, if there were no compilation errors) Type javac Welcome.java  The javac command compiles your high-level Welcome.java file into low-level bytecode program in a file Welcome.class If there are any “grammatical” errors in your Welcome.java program (and there often are!) javac will print them out.

Running your compiled program Type java Welcome  to run the Welcome program The java command gets the file Welcome.class and executes the bytecode commands in that file. If your Welcome.java program compiled correctly (with no errors), you will now have a Welcome.class file that can be run. If you give commands like java Welcome.class or java Welcome.java they won’t work because the java command will look for Welcome.class.class or Welcome.java.class If your Welcome program is written correctly, when run it’ll display Welcome to java on the command prompt

Methods: a first introduction Two ways to make tea: 1: boil water; put teabag into cup;... etc : tell your younger brother: makeTea(1 milk, 0 sugar); A method is a short way of calling a bunch of other statements

Built-in classes and methods Printing things on the screen is actually quite complicated (we’d need to know how to draw the characters, where to put them, how to move to a new line, and so on.) Java has built-in System.out classes that other programmers have written to handle all these complications. These classes contain methods like println or print that we can call to execute the series of statements needed to print something on the screen. There are a lot of such built-in classes and methods in Java that do all sorts of useful things. We will learn many of them

More on methods System.out.println("Hi there"); Method: makeTea; println Carried out by: Younger brother; System.out Arguments: 1 Milk, 0 sugar; "Hi there" We need to know 1) the method we want to execute; 2) the class that can carry out that method; 3) the arguments the method takes.

Programs and classes Each class describes a thing that does certain actions. Large programs can contain multiple classes describing different things. public class Foo { public static void main(String[] args) { // your code in here } This would be placed in a file called Foo.java. A java file always has the exact same name as the class containing main. Smallest possible Java program: 1 class containing 1 (main) method & 0 statements

How do we develop programs? understand the problem design an algorithm (semi-formal) implement the algorithm (write Java) compile and test Debug (fix mistakes)

Edit... Compile... Debug cycle Write/edit Java code Compile and run Debug (find the mistakes)

Homework Read Liang, pp (top of page) Do review questions, p. 26: You will also be doing programming exercises in your practicals.