Using the Java programming language compiler. Review of relevant material from previous lectures From previous lectures: A computer can only execute machine.

Slides:



Advertisements
Similar presentations
An Introduction to Programming By :- Vishal Hirani B.Tech II year (CSE)
Advertisements

CSCE 145: Algorithmic Design I Chapter 1 Intro to Computers and Java Muhammad Nazmus Sakib.
Introduction to the gedit editor. gedit: the Gnome editor Gnome: Gnome is a freely available (i.e., no cost) desktop environment for the UNIX system The.
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.
Lecture 2: Do you speak Java?. From Problem to Program Last Lecture we looked at modeling with objects! Steps to solving a business problem –Investigate.
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.
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.
1 Programming Languages b Each type of CPU has its own specific machine language b But, writing programs in machine languages is cumbersome (too detailed)
Introduction to Computer Programming CSC 1401: Introduction to Programming with Java Lecture 2 Wanda M. Kunkle.
1 Programming & Programming Languages Overview l Machine operations and machine language. l Example of machine language. l Different types of processor.
Lecture 2: Do you speak Java?. From Problem to Program Last Lecture we looked at modeling with objects! Steps to solving a business problem –Investigate.
Introduction to Java.
Writing algorithms using the while-statement. Previously discussed Syntax of while-statement:
Writing algorithms using the for-statement. Programming example 1: find all divisors of a number We have seen a program using a while-statement to solve.
CS0007: Introduction to Computer Programming Setting Up Java.
Programming a computer. What does programming a computer mean ? Programming a computer: Since a computer can only execute machine instructions (encoded.
Editing Java programs with the BlueJ IDE. Working environments to develop (= write) programs There are 2 ways to develop (write) computer programs: 1.Using.
The break and continue statements. Introduction There are 2 special statements that can affect the execution of loop statements (such as a while-statement)
PYTHON: LESSON 1 Catherine and Annie. WHAT IS PYTHON ANYWAY?  Python is a programming language.  But what’s a programming language?  It’s a language.
IB Computer Science II Paul Bui
Shorthand operators.
CCSA 221 Programming in C CHAPTER 2 SOME FUNDAMENTALS 1 ALHANOUF ALAMR.
Introduction to Java Tonga Institute of Higher Education.
The character data type char
CMSC 202 Computer Science II for Majors Object-Oriented Programming.
What is a Computer? An, electrical machine, that can be programmed to accept data (input), process it into useful information (output) and store it away.
The string data type String. String (in general) A string is a sequence of characters enclosed between the double quotes "..." Example: Each character.
FRST JAVA PROGRAM. Getting Started with Java Programming A Simple Java Application Compiling Programs Executing Applications.
Java and C# [this is a bonus – it is not a required lesson] ACO101: Introduction to Computer Science.
Java Basics - Prashant Nagaraddi. Features of Java n Java syntax is similar to C/C++ but there are many differences too n Java is strongly typed like.
1 CSC204 – Programming I Lecture 2 Intro to OOP with Java.
Introduction to C++ Programming Language
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Python From the book “Think Python”
The dangling-else ambiguity. Previously discussed The Java compiler (translator) consider white space characters (i.e., SPACE, TAB and New line) as insignificant.
The basics of the array data structure. Storing information Computer programs (and humans) cannot operate without information. Example: The array data.
Floating point numerical information. Previously discussed Recall that: A byte is a memory cell consisting of 8 switches and can store a binary number.
The scope of local variables. Murphy's Law The famous Murphy's Law says: Anything that can possibly go wrong, does. (Wikipedia page on Murphy's Law:
Object Oriented Programming Lecture 3. Introduction  In discussing Java, some items need to be clarified  The Java programming language  The Java virtual.
Working with arrays (we will use an array of double as example)
Introduction to programming in the Java programming language.
Assignment statements using the same variable in LHS and RHS.
Mixing integer and floating point numbers in an arithmetic operation.
8-2 What is a program? What is a “Window Manager” ? What is a “GUI” ? How do you navigate the Unix directory tree? What is a wildcard? Readings: See CCSO’s.
”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.
Using the while-statement to process data files. General procedure to access a data file General procedure in computer programming to read data from a.
The assignment expressions. The assignment operator in an assignment statement We have seen the assignment statement: Effect: var = expr; Stores the value.
Arithmetic expressions containing Mathematical functions.
CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington.
Introduction to array: why use arrays ?. Motivational example Problem: Write a program that reads in and stores away 5 double numbers After reading in.
Installing Java on a Home machine For Windows Users: Download/Install: Go to downloads html.
Working with floating point expressions. Arithmetic expressions Using the arithmetic operators: and brackets (... ), we can construct arithmetic expression.
Boolean expressions, part 1: Compare operators. Compare operators Compare operators compare 2 numerical values and return a Boolean (logical) value A.
Simple algorithms on an array - compute sum and min.
Lecture1 Instructor: Amal Hussain ALshardy. Introduce students to the basics of writing software programs including variables, types, arrays, control.
The ++ and -- expressions. The ++ and -- operators You guessed it: The ++ and -- are operators that return a value.
Compilers and Interpreters
CS 201 Lecture 1 (b) Using an IDE Tarik Booker CS 201: Introduction to Programming California State University, Los Angeles.
Chapter 3: Mastering Editors Chapter 3 Mastering Editors (Emacs)
Installing Java on a Home machine
Lecture 1b- Introduction
Writing, Compiling and Running a C program
Programming languages
Installing Java on a Home machine
The Boolean (logical) data type boolean
Introduction to Algorithm Design
IB Computer Science II Paul Bui
Review of Previous Lesson
Presentation transcript:

Using the Java programming language compiler

Review of relevant material from previous lectures From previous lectures: A computer can only execute machine instruction codes (binary numbers) Writing algorithms in machine instruction codes is extremely tedious

Review of relevant material from previous lectures (cont.) People have invented a number of English-like languages that is highly suitable for writing algorithms People have also written computer applications that translate algorithm written in a programming language into machine instructions These languages are called (high level) programming languages These applications are called compilers

How to write an algorithm that a computer can execute The hard way: You will hate your professor if he/she make you do this.... (and yet, the pioneers in Computer Science had done this... we must be grateful to them) Write the algorithm (yourself) in machine instruction (binary numbers)

How to write an algorithm that a computer can execute (cont.) The easy way: 1.Write the algorithm (yourself) in a programming language (using an editor like gedit) 2.Translate the program using a compiler into machine instructions (The translated program is stored in a computer file) 3.Let the computer execute the translated program in machine instructions (This translated program is an computer application because it can be run by a computer)

How to write an algorithm that a computer can execute (cont.) Pictorially: (An application is a file that contains machine instructions (which can be executed by a computer))

Using the Java compiler The name of the Java compiler (application) is: javac

Using the Java compiler (cont.) A Java program (= a computer algorithm written in the Java programming language) is first written and stored in a file The name of the file must end with the characters: The ending of a filename is called the file extension and it is commonly used to identify the kind of file..java

Using the Java compiler (cont.) The following command will translate a Java program into machine code: The Java compiler javac will store the translated machine codes into a file name ProgramFileName.class UNIX prompt>> javac ProgramFileName.java

Using the Java compiler (cont.) Example:

Using the Java compiler (cont.) Example Program: (Demo above example) –The Hello.java Prog file: Hello.java What to do: Right click of the link and save in some scratch directory Change current directory to that scratch directory Compile Hello.java with javac Hello.java

The Java machine language The translated machine code produced by the Java compiler javac is called: Java bytecode

The Java machine language Java bytecodes are executed by a Java machine --- a computer that executes machine instructions in Java bytecodes However, no such Java machine has ever been built In other words: There does not exist a physical computer (machine) that can execute Java byte codes

The Java virtual machine Emulators: Emulators are also known as virtual machines (Because they do the same thing as a real machine, but is not a physical machine) Emulators are (special) computer programs that emulate the exact behavior of a machine or entity

The Java virtual machine (cont.) Java virtual machine: (A Java virtual machine is an emulator) A Java virtual machine is a computer program (application) than can execute an algorithm written in Java bytecode

The Java virtual machine (cont.) The name of this computer application is: java

Executing the translated Java program with a Java virtual machine Suppose the program containing the Java bytecode is called: This program can be executed by the Java virtual machine java by executing the following command: ProgramFileName.clas s java ProgramFileName

Executing the translated Java program with a Java virtual machine (cont.) Note: You must omit the extension.class The Java virtual machine java will append the extension.class to its argument

Executing the translated Java program with a Java virtual machine (cont.) Example:

Executing the translated Java program with a Java virtual machine (cont.) Example Program: (Demo above code) –Hello.java Prog file: Hello.java What to do: Right click on the link ans save in some scratch directory Change current directory to that scratch directory Compile Hello.java with: &nsbp; javac Hello.java Then execute the Java bytecode Hello.class with: java Hello