Rina System development with Java Instructors: Rina Zviel-Girshin Interdiciplinary Center Herzlia School of the Computer Science Fall:

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Chapter 1: Computer Systems
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.
Object Oriented Programming in JAVA
The Java Programming Language
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 2013 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Getting Started with Java
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
Introducing Java.
Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R# address: Group Addresses Post message:
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
© 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
System development with Java Lecture 2. Rina Errors A program can have three types of errors: Syntax and semantic errors – called.
INTRODUCTION TO JAVA CHAPTER 1 1. WHAT IS JAVA ? Java is a programming language and computing platform first released by Sun Microsystems in The.
Rina System development with Java Instructors: Rina Zviel-Girshin Interdiciplinary Center Herzlia School of the Computer Science Fall:
1 Computer Systems -- Introduction  Chapter 1 focuses on:  the structure of a Java application  basic program elements  preparing and executing a program.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Copywrite ASC1 System development with Java Instructors: Rina Zviel-Girshin Interdiciplinary Center Herzlia School of the Computer Science Fall:
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.
Java Programming, Second Edition Chapter One Creating Your First Java Program.
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.
Rina System development with Java Instructor: Rina Zviel-Girshin Lecture 2.
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.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
CPS120: Introduction to Computer Science Variables and Constants.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
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.
Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
Copyright 2010 by Pearson Education APCS Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
1 Programming Languages and Java Programming languages Java language The basic program Java syntax.
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.
Chapter No. : 1 Introduction to Java.
Internet and Java Foundations, Programming and Practice
CS180 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
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
Focus of the Course Object-Oriented Software Development
CSE 142, Spring 2012 Building Java Programs Chapter 1
Chap 2. Identifiers, Keywords, and Types
Zorah Fung University of Washington, Winter 2016
JAVA. Java is a high-level programming language originally developed by Sun Microsystems and released in Java runs on a variety of platforms, such.
Presentation transcript:

Rina System development with Java Instructors: Rina Zviel-Girshin Interdiciplinary Center Herzlia School of the Computer Science Fall:

Rina Information Source Course site : Course book: Java Software Solutions /Lewis & Loftus Thinking in Java / Bruce Eckle

Rina Course Methodology Non-Linearity Spiral model Hypermedia CAI – Computer Assisted Instruction Interactive learning Labs and programming Multi-approach: inductive-deductive trails

Rina Programming Languages and Java Programming languages Java language The basic program Java syntax

Rina Programming The process of writing programs called a programming. The process requires: Programming language A translator of the programming language into machine language Programs are written in programming language.

Rina Syntax Syntax describes the grammatical rules of a language. Valid words Valid grammar constructions Valid punctuation Programs must be syntactically correct.

Rina Semantics Semantics gives the meaning of what you write with a language. A programming language must precisely define the meaning of every statement that can be written with it. Programs must be semantically correct.

Rina Example The following sentence is syntactically correct but semantically incorrect. “ Java programs are green and yellow.” –All words are correct words. –Punctuation is correct. –But logically the sentence makes no sense.

Rina Programming languages There are several families of the programming languages: Procedural ( Pascal, C++, Java) Logical ( Prolog) Visual ( Visual Basic) Document (HTML, LATEX)

Rina Programming languages Procedural languages can be divided into:  Machine languages  Low-level (Assembler )  Intermediate-level (C)  High-Level (C++, Java)

Rina Java Java is high-level language. Java is object oriented language. In this course we will use the terms: – OOP, – OOA, – OOD.

Rina OOA and OOD OOA- Object-Oriented Analysis is a way to analyze a problem. OOD- Object-Oriented Design is a way to design a solution. Both see the world as: objects and their relations (behavior, communication).

Rina OOA and OOD (cont) The way to analyze a problem is to define the objects relevant to it and their behavior. The way to solve a problem is to realize the objects relevant and the behavior we need. Both are useful as preliminary stages in OOP- Object Oriented Programming.

Rina OOP Objects are the building blocks of:  the problem  the solution  the input source  the output target  the environment

Rina Objects Objects include both: data (fields, variables, state) processing (behavior, methods, functions) Objects have two kinds of behavior: outer – I/O, messages, relations with others inner – processing (usually computing the messages)

Rina Objects (cont) Relations between objects are implemented using communication (messages). Communication can have many forms. Some forms are very different from the usual idea of a message. Objects acquire structure using their relations. The structure is usually tree-like.

Rina High-level languages Writing programs in machine language is possible but very difficult and time consuming. Programs usually written in a more human readable language - high-level language. Java is high-level language. A program written in any computer language must be translated into a machine language in order to be executed.

Rina Translators Compiler A compiler is a program that translates a source program (usually high level language) into target program (usually machine language program). The resulting program can be executed many times. Interpreter An interpreter is a program that reads, translates and executes the source program statement by statement. The translation is done each time the program runs.

Rina Java Java is a high-level, third generation programming language, like C, Fortran, Smalltalk. Shares much of C's syntax. Designed by a group at Sun MicroSystems. Originally called Oak.

Rina Java advantages Platform independent “Write once, run anywhere”. Improve robustness, remove unsafe language loopholes. According to Sun: “ Java is simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, high-performance, multithread, and dynamic language.”

Rina Java disadvantages The main Java disadvantage: Efficiency concerns. Looking to the future: VM performance will improve.

Rina Java environments Java has many environments. The number grows as Java evolves. Among them are: Text applications Beans Applets GUI Applications Packages

Rina Two main environments The two main environments:  Web Browser  Operating System

Rina Web Browser In the browser environment the browser acts as an intermediate between the program and the operating system. The JVM resides inside the browser. The program can be simpler. The program has to work in graphical mode. The program is called “Applet” (a small application).

Rina Operating System In the operating system environment the program is called “application”. Application has a more rigid structure. Application can be textual or graphical. Application is less secure.

Rina Learning Java The specific challenge is twofold:  Learning the language technical aspect: the large set of new features class libraries classes methods which are provided as part of the language.  Learning to maximize the benefits of the object- oriented paradigm.

Rina Starting to Program The basic idea of the course is to start programming as soon as possible. At first you will have to take a lot of things on trust. Promise: we will return to the details later.

Rina Java programs All Java programs have three parts: Auxiliary prescriptions A class – an envelope around the other components Code per se – Optionally – other components which include the instructions themselves Instructions to be executed

Rina Writing a Java Program Use an editor to type the program code. Save the code file. Compile the file with Java language compiler. Fix the bugs! Run the program.

Rina A basic Java Program // Prints “How are you?” to the screen class My { public static void main (String[] args) { System.out.println(“How are you?”); }

Rina A basic Java Program // Prints “How are you?” to the screen class My { public static void main (String[] args) { System.out.println(“How are you?”); }

Rina Java program structure A Java program is made up of one or more classes. Classes have names. The ‘My’ program consists of one class named ‘My’.

Rina Class structure A Java class contains one or more methods. Methods have names too. The program (the class) has to have a main method. The method is called (surprisingly) – main.

Rina Main The main method has a standard syntax: public static void main(String args[]) {… // your code } There can be only one main per file. The main method contains the code to be executed when the program runs.

Rina Method structure A method contains one or more statements. The main method of My program has a single statement: System.out.println(“How are you?”);

Rina Stages of Writing and Executing Assumptions: Using only the basic JDK software Assuming the JDK was installed properly In the WIN/DOS environment Class name is My File name is My.java Directory (folder) name is c:\java

Rina Stages of Writing and Executing 1.Open a text editor that can produce a plain text file (such as Notepad). 2.Create a source code file with the extension on the file name being.java. The file has to have the same name as the outer class. 3.Start a the DOS command environment by opening MSDOS prompt (using the Start->Programs->MSDOS Prompt series of choices).

Rina Stages of Writing and Executing 4.Change directory to the directory containing the source file. 5.Compile the file, using the prompt command: javac My.java 6.The result is My.class in the same folder. 7.Run using the prompt command: java My

Rina Applets The program has to import two packages: applet.Applet awt The program (the class) has to extend the Applet class, using the following syntax: public class My extends Applet { // your code }

Rina Basic applet code The final code looks like this: import java.awt.*; import java.applet.*; public class My extends Applet { // your code }

Rina Stages of Writing and Executing Applet can’t be run directly. Applet has to be run in Browser and by the Browser. Web browser executes web pages. Web page should call the applet code.

Rina Call to applet The call to applet consist of: –the command APPLET –the name of the applet class –the dimensions of the panel in which the applet will run

Rina Example Assuming the name of the applet class is HelloWorld.class the call to applet looks like this: <APPLET CODE = "HelloWorld.class" WIDTH = 150 HEIGHT= 50>

Rina HTML The call to applet has to be in HTML file. The file can look as follows: Java applet test page <APPLET CODE="HelloWorld.class" WIDTH=150 HEIGHT=50>

Rina Execution Assuming the file is called HelloWorld.html 1.The stages common to all, described above. 2.Open the file HelloWorld.html in the Browser.

Rina Java Compiler The Java compiler is called javac. Java programs are compiled to byte code.

Rina Byte code The Java compiler translates Java program into a special representation called byte code. Java byte code is a machine code for Java virtual Machine(JVM). VM is a platform-specific tool to interpret the byte code and to translate it to commands for certain processor and OS. The use of the byte code makes Java platform independent.

Rina Compile-interpret-execute cycle

Rina Compile-interpret-execute cycle

Rina Errors A program can have three types of errors: Syntax and semantic errors – called compile- time errors Run-time errors – occur during program execution Logical errors

Rina Errors Compile-time errors occur during program compilation and an executable version of the program is not created. Run-time errors occur during program execution and cause abnormal program termination. Logical errors occur during program execution and produce incorrect results.

Rina Java Syntax To write without syntax mistakes you have to know Java syntax. Syntax Syntax - the study of the patterns of formation of sentences and phrases from words and of the rules for the formation of grammatical sentences in a language.

Rina Java Syntax Case-sensitive Semi-colon (;) is line terminator Curly braces ({,}) used for block structure Several keywords

Rina Comments There are two kinds of comments: /* text */ A traditional comment: all the text from the ASCII characters /* to the ASCII characters */ is ignored. // text An end-of-line comment: all the text from the ASCII characters // to the end of the line is ignored.

Rina Comments Comments do not nest. /* and */ have no special meaning in comments that begin with //. // has no special meaning in comments that begin with /* or /**. As a result, the text: /* this comment /* // /** ends here: */ is a single complete comment.

Rina Identifiers An identifier is: an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter. An identifier cannot have the same spelling (Unicode character sequence) as: a keyword, boolean literal, the null literal

Rina Unicode Letters and digits may be drawn from the entire Unicode character set (The character set that uses 16 bit per character). Identifier can be written in most writing scripts in use in the world today, including: Hebrew, Chinese, Japanese, Korean Practically all languages

Rina Identifiers examples Uppercase and lowercase are different. All the following are different identifiers: MYmyMymYmy1 Examples of identifiers are: Stringsi3 isLetterOrDigit מונה MAX_VALUE

Rina Keywords The following are reserved words called keywords and cannot be used as identifiers: 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

Rina True, False, Null While true and false might appear to be keywords, they are technically Boolean literals. Similarly, while null might appear to be a keyword, it is technically the null literal.

Rina Literals A literal is a source code representation of a value of: a primitive type, the String type, the null type Kinds of Literals: IntegerLiteralFloatingPointLiteral BooleanLiteralCharacterLiteral StringLiteralNullLiteral

Rina Integer Literals An integer literal may be expressed in: decimal (base 10), hexadecimal (base 16), octal (base 8)

Rina Hexadecimal numeral A hexadecimal numeral consists of the leading characters 0x or 0X followed by one or more hexadecimal digits. It can represent a positive, zero, or negative integer. Hexadecimal digits with values 10 through 15 are represented by the letters a through f or A through F, respectively. HexDigit is one of: a b c d e f A B C D E F

Rina Octal numeral An octal numeral consists of a digit 0 followed by one or more of the digits 0 through 7. It can represent a positive, zero, or negative integer. Octal numerals always consist of two or more digits.

Rina Example Examples of int literals: xDadaCafe1996 0x00FF00FF the same number in decimal octal hexadecimal: x xF

Rina Zero 0 is always considered to be a decimal numeral. The numerals 0, 00, and 0x0 all represent exactly the same integer value – zero value.

Rina Floating-Point Literals A floating-point literal has the following parts: a whole-number part, a decimal point (represented by an ASCII period character), a fractional part, an exponent (is indicated by a letter e or E followed by an optionally signed integer), and a type suffix. At least one digit, in either the whole number or the fraction part, and either a decimal point, an exponent, or a float type suffix are required. All other parts are optional.

Rina Floating-Point Literals A floating-point literal is of type float if it is suffixed with an ASCII letter F or f; otherwise its type is double and it can optionally be suffixed with an ASCII letter D or d. Examples of float literals: 1e1f 2.f.3f0f3.14f e+23f

Rina Boolean Literals The boolean type has two values, represented by the literals true and false A boolean literal is always of type boolean. BooleanLiteral is one of: true false

Rina Character Literals A character literal is expressed as a character or an escape sequence, enclosed in single quotes. A character literal is always of type char. Examples of char literals: 'a‘ '%‘'\t‘'\\‘'\u03a9‘ '\uFFFF‘'\177'

Rina String Literals A string literal consists of zero or more characters enclosed in double quotes. A string literal is always of type String. Examples of string literals: ""// the empty string "This is a string"// a string containing 16 characters "This is a " + // actually a string-valued constant expression, "two-line string" //formed from two string literals

Rina Escape Sequences for Character and String Literals Escape Sequence: \ b/* \u0008: backspace BS */ \ t/* \u0009: horizontal tab HT */ \ n/* \u000a: linefeed LF */ \ f/* \u000c: form feed FF */ \ r/* \u000d: carriage return CR */ \ "/* \u0022: double quote " */ \ '/* \u0027: single quote ' */ \ \/* \u005c: backslash \ */

Rina The Null Literal The null type has one value, the null reference, represented by the literal null, which is formed from ASCII characters. A null literal is always of the null type.

Rina Separators The following nine ASCII characters are the separators (punctuators): () {} [] ;,.

Rina Operators The following 37 tokens are the operators, formed from ASCII characters: = ><!~?: == =!=&&|| */&| ^% >>>>+=-= *=/=&=|=^=%=

Rina Programming style Java is a free-format language. There are no syntax rules about how the program has to be arranged on a page. You can write entire program in one line. But as a matter of good programming style, you should lay out your program on the page in a way that will make its structure as clear as possible.

Rina Programming style Some advises: Put one statement per line. Use indentation to indicate statements that are contained inside control structures. Write comments. Give your variables names that make sense.

Rina Style Example Bad: public class Stam { public static void main(String args[]){ System.out.println("Hello!“);}} Better: // style example – outputs “Hello!” public class Hello { public static void main(String args[]) { System.out.println("Hello!"); }

Rina Any Questions?

Rina Any Questions?