1 Introduction zNow we can begin to examine the basic ideas behind writing programs zLecture 1 focuses on: ythe structure of a Java application ybasic.

Slides:



Advertisements
Similar presentations
Chapter 1: Computer Systems
Advertisements

Programming Languages
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.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
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.
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.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
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:
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.
Chapter 1.4 Programming languages Homework Due: Monday, August 11, 2014.
Java: Chapter 1 Computer Systems Computer Programming II.
Java Language and SW Dev’t
System development with Java Lecture 2. Rina Errors A program can have three types of errors: Syntax and semantic errors – called.
© 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.
C Derived Languages C is the base upon which many build C++ conventions also influence others *SmallTalk is where most OOP comes Java and Javascript have.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Lecture 1 Introduction Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Chapter 2: Java Fundamentals
Chapter 1: Introduction Java Programming Language How the Java Virtual Machine Works (compiling, etc…) Update by: Dan Fleck Coming up: The Java Programming.
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.
© 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.
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.
ZObject-Oriented Software Development yproblem solving yprogram design and implementation yobject-oriented concepts xobjects xclasses xinterfaces xinheritance.
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.
Chapter 1 Introduction. 2 Focus of the Course Object-Oriented Software Development problem solving program design, implementation, and testing object-oriented.
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.
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
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
Chap 2. Identifiers, Keywords, and Types
Chap 1. Getting Started Objectives
Chap 4. Programming Fundamentals
Instructor: Alexander Stoytchev
Presentation transcript:

1 Introduction zNow we can begin to examine the basic ideas behind writing programs zLecture 1 focuses on: ythe structure of a Java application ybasic program elements ypreparing and executing a program ybasic object-oriented programming concepts yhelpful support for writing software yJava applets

2 Java Program Structure  See Lincoln.javaLincoln.java zA program is made up of one or more classes zA class contains one or more methods zA method contains program statements zA Java application always executes the main method

3 White Space zSpaces, blank lines, and tabs are collectively called white space and are used to separate words and symbols in a program zExtra white space is ignored zA valid Java program can be formatted many different ways  See Lincoln2.java and Lincoln3.javaLincoln2.java Lincoln3.java zPrograms should be formatted to enhance readability, using consistent indentation

4 Comments zComments in a program are also called inline documentation zThey should be included to explain the purpose of the program and describe processing steps zJava comments can take two forms: // comment runs to the end of the line /* comment runs to terminating symbol, even across line breaks */

5 Identifiers zIdentifiers are the words a programmer uses in a program zMost identifiers have no predefined meaning except as specified by the programmer zAn identifier can be made up of letters, digits, the underscore character (_), and the dollar sign zThey cannot begin with a digit  Java is case sensitive, therefore Total and total are different identifiers

6 Reserved Words zSome identifiers, called reserved words, have specific meanings in Java and cannot be used in other ways abstract boolean break byte byvalue case cast catch char class const continue default do double else extends false final finally float for future generic goto if implements import inner instanceof int interface long native new null operator outer package private protected public rest return short static super switch synchronized this throw throws transient true try var void volatile while

7 Literals zA literal is an explicit data value used in a program zInteger literals: zFloating point literals: zString literals: "The result is: " "To thine own self be true."

8 The Java API zThe Java Application Programmer Interface (API) is a collection of classes that can be used as needed  The println and print methods are part of the Java API; they are not part of the Java language itself  Both methods print information to the screen; the difference is that println moves to the next line when done, but print does not  See Countdown.javaCountdown.java

9 String Concatenation and Addition  The + operator serves two purposes zWhen applied to two strings, they are combined into one (string concatenation) zWhen applied to a string and some other value (like a number), that value is converted to a string and they are concatenated zWhen applied to two numeric types, they are added together arithmetically  See Antarctica.java and Sum.javaAntarctica.java Sum.java

10 Java Translation and Execution zThe Java compiler translates Java source code into a special representation called bytecode zJava bytecode is not the machine language for any traditional CPU zAnother software tool, called an interpreter, translates bytecode into machine language and executes it zTherefore the Java compiler is not tied to any particular machine zJava is considered to be architecture-neutral

11 Java Translation and Execution Java source code Machine code Java bytecode Java interpreter Bytecode compiler Java compiler

12 Java Translation and Execution zExecuting the compiler in a command line environment: > javac Lincoln.java  This creates a file called Lincoln.class, which is submitted to the interpreter to be executed: > java Lincoln  The.java extension is used at compile time, but the.class extension is not used with the interpreter zOther environments do this processing in a different way

13 Syntax and Semantics zThe syntax of a language defines how you can put symbols, reserved words, and identifiers together to make a valid program zThe semantics of a language construct is the meaning of the construct; it defines its role in a program zA syntactically correct program does not mean it is logically (semantically) correct zA program will always do what we tell it to do, not what we meant to tell it to do

14 Errors zA program can have three types of errors zThe compiler will find problems with syntax and other basic issues (compile-time errors) yIf compile-time errors exist, an executable version of the program is not created zA problem can occur during program execution, such as trying to divide by zero, which causes a program to terminate abnormally (run-time errors) zA program may run, but produce incorrect results (logical errors)

15 Command Line Arguments  See Name_Tag.javaName_Tag.java  The main method accepts extra information on the command line when a program is executed > java Name_Tag John zEach extra value is called command line argument zIn Java, command line arguments are always read as a list of character strings

16 Software Engineering zWe should always strive to engineer our software to make it reliable and maintainable zAs the complexity of a program increases, its cost to develop and revise grows exponentially cost complexity

17 Software Components zPrograms are easier to construct and modify when they are made up of separate components zA software component can be thought of as any program element that transforms input into output Input Output Component Compute average

18 Software Components zComponents can be combined to make larger components

19 Object-Oriented Programming zJava is object-oriented language zPrograms are made from software components called objects zAn object contains data and methods zAn object is defined by a class zMultiple objects can be created from the same class

20 Object-Oriented Programming zA class represents a concept and an object represents the realization of that concept Car My first car John's car Dad's car Class Objects

21 Object-Oriented Programming zObjects can also be derived from each other using a process called inheritance zObjects, classes, and inheritance will be discussed in greater detail later Vehicle TrainCarAirplane

22 Class Libraries zThe Java API is a class library, a group of classes that support program development zClasses in a class hierarchy are often related by inheritance zThe classes in the Java API is separated into packages  The System class, for example, is in package java.lang zEach package contains a set of classes that relate in some way

23 The Java API Packages zSome packages in the Java API: java.applet java.awt java.beans java.io java.lang java.math java.net java.rmi java.security java.sql java.text java.util

24 Importing Packages zUsing a class from the Java API can be accomplished by using its fully qualified name: java.lang.System.out.println (); zOr, the package can be imported using an import statement, which has two forms: import java.applet.*; import java.util.Random;  The java.lang package is automatically imported into every Java program

25 Java Applets zA Java applet is a Java program that is intended to be sent across a network and executed using a Web browser zA Java application is a stand alone program  Applications have a main method, but applets do not  Applets are derived from the java.applet.Applet class  See Confucius.java and No_Parking.javaConfucius.java No_Parking.java zLinks to applets can be embedded in HTML documents

26 Java Applets Java source code Java bytecode Java compiler Java interpreter Web browser local computer remote computer