Chapter 1: Introduction Java Programming Language How the Java Virtual Machine Works (compiling, etc…) Update by: Dan Fleck Coming up: The Java Programming.

Slides:



Advertisements
Similar presentations
Chapter 1: Computer Systems
Advertisements

Programming Languages
COMP425M Introduction to Programming
Programming with Java. Problem Solving The purpose of writing a program is to solve a problem The general steps in problem solving are: –Understand the.
Dale Roberts Introduction to Java - First Program Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
1 Kursusform  13 uger med: Undervisning i klassen 1,5-2 timer Opgave ”regning” i databar (løsninger på hjemmeside) En midtvejsopgave der afleveres og.
1 Java Basics. 2 Compiling A “compiler” is a program that translates from one language to another Typically from easy-to-read to fast-to-run e.g. from.
The Java Programming Language
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 1 “ Introduction to Java and OOP”
Outline Java program structure Basic program elements
Chapter 1 Introduction. © 2004 Pearson Addison-Wesley. All rights reserved1-2 Outline Computer Processing Hardware Components Networks The Java Programming.
Chapter 1 Introduction.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
Java: Chapter 1 Computer Systems Computer Programming II Aug
Chapter 1 Introduction.
Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R# address: Group Addresses Post message:
HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.
Chapter 1 Programming Languages. Application Development: Top 10 Programming Languages to Keep You Employed 1. Java 2. C# 3. C++ 4. JavaScript 5. Visual.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley John Lewis, Peter DePasquale, and Joseph Chase Chapter 1: Introduction.
© 2006 Pearson Education Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition.
Java: Chapter 1 Computer Systems Computer Programming II.
Java Language and SW Dev’t
© 2006 Pearson Education 1 Obj: cont 1.3 and 1.4, to become familiar with identifiers and to understand how programming languages work HW: p.51 #1.8 –
1 Computer Systems -- Introduction  Chapter 1 focuses on:  the structure of a Java application  basic program elements  preparing and executing a program.
Chapter 1 Introduction 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All rights reserved.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
CSC204 – Programming I Lecture 4 August 28, 2002.
Introduction. Objectives An overview of object-oriented concepts. Programming and programming languages An introduction to Java 1-2.
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
Lecture 1 Introduction Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Chapter 2: Java Fundamentals
Java The Java programming language was created by Sun Microsystems, Inc. It was introduced in 1995 and it's popularity has grown quickly since A programming.
Introduction to Java Java Translation Program Structure
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
Lecture 2 Software Concepts Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
Introduction to Programming and Java. 2 The Central Processing Unit The speed of a CPU is controlled by the system clock which generates an electronic.
1 Problem Solving b The purpose of writing a program is to solve a problem b The general steps in problem solving are: Understand the problemUnderstand.
White Space Spaces, blank lines, and tabs are collectively called white space and are used to separate words and symbols in a program Extra white space.
Intro to Programming  Chapter 1 Part 2  Problem Solving.
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
Java.
Chapter 1 Introduction. 2 Focus of the Course Object-Oriented Software Development problem solving program design, implementation, and testing object-oriented.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
WEEK 2 1 Software Concepts -- Introduction Now we can begin to examine the basic ideas behind writing programs Chapter 2 focuses on: history.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Introduction to Java Programming by Laurie Murphy Revised 09/08/2016.
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
JAVA MULTIPLE CHOICE QUESTION.
Working with Java.
Lecture 1 Introduction Richard Gesick.
GC101 Introduction to computer and program
University of Central Florida COP 3330 Object Oriented Programming
1.3 Problem Solving The purpose of writing a program is to solve a problem The general steps in problem solving are: Understand the problem Dissect the.
Unit 41 – Programing in Java
null, true, and false are also reserved.
Introduction to Java Programming
CS-0401 INTERMEDIATE PROGRAMMING USING JAVA
An overview of Java, Data types and variables
Chapter 1: Computer Systems
Units with – James tedder
Units with – James tedder
Java Software Solutions Foundations of Program Design 9th Edition
Focus of the Course Object-Oriented Software Development
Instructor: Alexander Stoytchev
Chap 2. Identifiers, Keywords, and Types
Presentation transcript:

Chapter 1: Introduction Java Programming Language How the Java Virtual Machine Works (compiling, etc…) Update by: Dan Fleck Coming up: The Java Programming Language

THE JAVA PROGRAMMING LANGUAGE Coming up: Java

Java The Java programming language was created by Sun Microsystems, Inc. It was introduced in 1995 and it's popularity has grown quickly since Java is NOT Javascript… they are different languages… knowing one does NOT mean you know the other! Don’t get that confused Coming up: Java Program Structure

Java Program Structure In the Java programming language: ◦ A program is made up of one or more classes ◦ A class contains one or more methods ◦ A method contains program statements A Java application always contains a method called main main is the first method called when a Java application starts Coming up: Java Program Structure

Java Program Structure public class MyProgram {}{} // comments about the class class header class body Comments can be placed almost anywhere Coming up: Java Program Structure

Java Program Structure public class MyProgram {}{} // comments about the class public static void main (String[] args) {}{} // comments about the method method header method body Coming up:

Time to write HelloWorld in Java Coming up: In Java, what is used to separate blocks?

Coming up: Comments In Java, what is used to separate blocks? A. white space B. Tabs C. curly braces --- { } D. square braces --- [ ]

Comments Comments in a program are called inline documentation They should be included to explain the purpose of the program and describe processing steps They do not affect how a program works Java comments can take three forms: // this comment runs to the end of the line /* this comment runs to the terminating symbol, even across line breaks */ /** this is a javadoc comment */ Coming up: Identifiers

Identifiers Identifiers are the words a programmer uses in a program (variable names, class names, method names…) An identifier can be made up of letters, digits, the underscore character ( _ ), and the dollar sign Identifiers cannot begin with a digit Java is case sensitive - Total, total, and TOTAL are different identifiers By convention, programmers use different case styles for different types of identifiers, such as ◦ title case for class names - Lincoln ◦ upper case for constants - MAXIMUM Coming up: Reserved Words are predefined in the language, and cannot be used as identifiers

Reserved Words are predefined in the language, and cannot be used as identifiers The Java reserved words: abstract assert boolean break byte case catch char class const continue default do double else enum extends false final finally float for goto if implements import instanceof int interface long native new null package private protected public return short static strictfp super switch synchronized this throw throws transient true try void volatile while Coming up: What value prints?

What value prints? public void test() { int myVar = 10; int MYVAR = 20; myVar = 35; System.out.println(“Value is:”+MYVAR); } A. 10 B. 20 C. 35 D. MYVAR Coming up: White Space

White Space Spaces, blank lines, and tabs are called white space White space is used to separate words and symbols in a program Extra white space is ignored in Java A valid Java program can be formatted many ways Programs should be formatted to enhance readability, using consistent indentation See HelloWorld2.javaHelloWorld2.java See HelloWorld3.javaHelloWorld3.java Coming up: Object-Oriented Programming

Object-Oriented Programming Java is an object-oriented programming language As the term implies, an object is a fundamental entity in a Java program Objects can be used effectively to represent real- world entities For instance, an object might represent a particular employee in a company Each employee object handles the processing and data management related to that employee Coming up: Objects

Objects An object has: ◦ state - descriptive characteristics ◦ behaviors - what it can do (or what can be done to it) The state of a bank account includes its account number and its current balance The behaviors associated with a bank account include the ability to make deposits and withdrawals Note that the behavior of an object might change its state Coming up: Classes

Classes An object is defined by a class A class is the blueprint of an object The class uses methods to define the behaviors of the object The class that contains the main method of a Java program represents the entire program A class represents a concept, and an object represents the embodiment of that concept Multiple objects can be created from the same class Coming up:

Lets create the BankAccount class Coming up: Objects and Classes

Objects and Classes Bank Account A class (the concept) John’s Bank Account Balance: $5,257 An object (the realization) Bill’s Bank Account Balance: $1,245,069 Mary’s Bank Account Balance: $16,833 Multiple objects from the same class Coming up: Given Bill Gates’ bank account and Dan Fleck’s bank account, is “withdraw” a valid behavior in both? Instances of a class have the state filled in. In this case, state is the name of the account holder and the balance

Given Bill Gates’ bank account and Dan Fleck’s bank account, is “withdraw” a valid behavior in both? A. Yes B. No Coming up: If I give you a “Computer” and a “Dell Inspiron Laptop” which would be the class and which would be the object? If the answer is Yes, then all the behvaiors between Bill Gates’ account and Dan Fleck’s account are the same… what then is different? (Text Answer)

If I give you a “Computer” and a “Dell Inspiron Laptop” which would be the class and which would be the object? A. Dell is Class, Computer is Object B. Both are Classes C. Both are Objects D. Dell is Object, Computer is Class Coming up: Inheritance

Inheritance One class can be used to derive another via inheritance Classes can be organized into hierarchies Bank Account Account Charge Account Savings Account Checking Account Coming up: Creating an object and calling a method

Creating an object and calling a method To construct an object of class, use the “new” keyword Rectangle myRect = new Rectangle(); ◦ This is similar to declaring a primitive variable, but you must call “new classname” Call a method on myRect: ◦ width = myRect.getWidth(); Coming up: How do you know what methods you can call? Object name Method name

How do you know what methods you can call? Lets look at the Java API! Coming up: How Java compiling works

HOW JAVA COMPILING WORKS Coming up: Program Development

Program Development The mechanics of developing a program include several activities ◦ writing the program in a specific programming language (such as Java) ◦ translating the program into a form that the computer can execute ◦ investigating and fixing various types of errors that can occur Software tools can be used to help with all parts of this process Coming up: Language Levels

Language Levels There are four programming language levels: ◦ machine language ◦ assembly language ◦ high-level language ◦ fourth-generation language Each type of CPU has its own specific machine language The other levels were created to make it easier for a human being to read and write programs Coming up: Programming Languages

Programming Languages Each type of CPU executes only a particular machine language A program must be translated into machine language before it can be executed A compiler is a software tool which translates source code into a specific target language Often, that target language is the machine language for a particular CPU type The Java approach is somewhat different Coming up: Programming Languages

Programming Languages Star Trek Coming up: Programming Languages

Programming Languages C/C++ (traditional) Coming up: Programming Languages Compiler C Program Machine Code

Programming Languages C/C++ (traditional) Coming up: Java Translation Windows Architecture Compiler Windows Architecture Compiler Windows Machine Code Windows Machine Code MAC Architecture Compiler MAC Architecture Compiler Unix Architecture Compiler Unix Architecture Compiler MAC Machine Code MAC Machine Code Unix Machine Code Unix Machine Code C Program

Java Translation Java source code Machine code Java bytecode Bytecode interpreter Bytecode compiler Java compiler Coming up: Programming Languages

Programming Languages Coming up: Java Translation Windows Machine Code Windows Machine Code Java Compiler MAC Machine Code MAC Machine Code Unix Machine Code Unix Machine Code Java Program Windows Java Interpreter MAC Java Interpreter Unix Java Interpreter Java bytecode

Java Translation The Java compiler translates Java source code into a special representation called bytecode Java bytecode is not the machine language for any traditional CPU Another software tool, called an interpreter, translates bytecode into machine language and executes it Therefore the Java compiler is not tied to any particular machine Java is considered to be architecture-neutral Coming up: Java Bytecode

Java Bytecode Using Bytecode allows Java to be considered “write once, run anywhere”. The only code that must be specific for the platform is the Java Virtual Machine (JVM). This is why for different computers you need to download the appropriate JVM, but then any compiled Java code will run there. Coming up: How TO USE THE Java compiler

So, if I have to eventually get to machine code either way using an architecture specific compiler (for C) or a specific VM (for Java), what is the benefit of Java’s bytecode -> Interpreter-> Machine code architecture?

HOW TO USE THE JAVA COMPILER Coming up: How to compile

How to compile Install the Java Development Kit (JDK). This includes the java compiler (javac) and the JRE (Java Runtime Environement) Compiling: javac >.java java HelloWorld.java Running: java > java HelloWorld Coming up: Where to get Java

Where to get Java Click on J2SE (Java 2 Standard Edition) Download: JDK 6 Update XX With Netbeans 6.1. At the time of this slide, XX=7 (We will be using the Netbeans Integrated Development Environment (IDE) in class End of presentation