PZ12CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000 1 PZ12CX- Java Programming Language Design and Implementation.

Slides:



Advertisements
Similar presentations
Programming Languages and Paradigms The C Programming Language.
Advertisements

Portability and Safety Mahdi Milani Fard Dec, 2006 Java.
Lab Information Security Using Java (Review) Lab#0 Omaima Al-Matrafi.
Lab#1 (14/3/1431h) Introduction To java programming cs425
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
Introduction to Java CS 331. Introduction Present the syntax of Java Introduce the Java API Demonstrate how to build –stand-alone Java programs –Java.
PZ04A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ04A - Scalar and composite data Programming Language.
Lecture 1: Overview of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++ Designed.
CMSC 341 Introduction to Java Based on tutorial by Rebecca Hasti at
Programming in Java; Instructor:Moorthy Introduction, Objects, Classes, Libraries1 Programming in Java Introduction.
OOP Languages: Java vs C++
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Programming Languages and Paradigms Object-Oriented Programming.
Java and C++, The Difference An introduction Unit - 00.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Java: Chapter 1 Computer Systems Computer Programming II.
Introduction to Java CSIS 3701: Advanced Object Oriented Programming.
INTRODUCTION TO JAVA CHAPTER 1 1. WHAT IS JAVA ? Java is a programming language and computing platform first released by Sun Microsystems in The.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Programming Languages and Paradigms Object-Oriented Programming (Part II)
1 Computer Systems -- Introduction  Chapter 1 focuses on:  the structure of a Java application  basic program elements  preparing and executing a program.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and Server Side Programming Very rich GUI libraries Portability (machine independence) A.
The Java Programming Language
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Java Programming Presented by Daniel Rosenthal Friday, November 30 th, 2007.
Chap. 1 Classes, Types, and Objects. How Classes Are Declared [ ] class [extends ] [implements,, … ] { // class methods and instance variable definitions.
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.
Introduction to java Prepared By:-Pragnesh Patel Lect. In Computer Dept. NSIT,Jetalpur 1.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
1 Introduction to Java. 2 What is Java? A programming language. A platform –A virtual machine (JVM) definition. –Runtime environments in diverse hardware.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
1 Programming Java Java Basics. 2 Java Program Java Application Program Application Program written in general programming language Applet Program running.
Fall 2015CISC124 - Prof. McLeod1 CISC124 Have you filled out the lab section survey? (As of last night 54 left to fill out the survey.) TA names have been.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Copyright Curt Hill Variables What are they? Why do we need them?
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Developed at Sun Microsystems in 1991 James Gosling, initially named “OAK” Formally announced java in 1995 Object oriented and cant write procedural.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
Java Computer Industry Lab. 1 Programming Java Java Basics Incheon Paik.
 Data Type is a basic classification which identifies different types of data.  Data Types helps in: › Determining the possible values of a variable.
PZ01DX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ01DX - Overview of C and C++ Programming Language.
PZ02CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ02CX - Perl Programming Language Design and Implementation.
Object Oriented Programming Lecture 2: BallWorld.
1 Scalar and composite data Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Scalar and composite data Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Memory Management in Java Mr. Gerb Computer Science 4.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
JAVA MULTIPLE CHOICE QUESTION.
Chapter No. : 1 Introduction to Java.
Yanal Alahmad Java Workshop Yanal Alahmad
Java Primer 1: Types, Classes and Operators
Internet and Java Foundations, Programming and Practice
Programming Language Concepts (CIS 635)
I/O Basics.
An Introduction to Java – Part I
The Building Blocks Classes: Java class library, over 1,800 classes:
Units with – James tedder
Units with – James tedder
Introduction to Data Structure
Java Programming Language
Introducing Java.
Java Basics Data Types in Java.
Presentation transcript:

PZ12CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ12CX- Java Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section Appendix A.5

PZ12CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Java development Java development began in 1991 at Sun Microsystems, where James Gosling led the Green Team in a project to develop a language for use on consumer digital devices. In 1993, the Mosaic Web Browser was released. The Green Team immediately saw the role of their language as a way to enhance Web browsers. Because of slow transmission speeds, Sun saw this new language as a way to incorporate executable behavior in the browser rather than in the web server. A critical development: The Web server would not know what machine the user's browser was executing on. To solve this problem, a Java virtual machine was designed and the applet would be compiled into a series of bytecodes for that virtual machine. By 1995, Java became a de facto standard for web browser applets.

PZ12CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Java overview For the most part, Java is C++ with the excess baggage of C removed. Data are strongly typed, with integers, Booleans, and characters all being separate types. Arrays are separate types, and a string is not simply an array of characters. Method invocation is the only subroutine linkage. Because all objects are part of classes, there is no need for separate function or procedure calls. Struct objects are not needed because the same effect can be achieved via instance variables in class definitions. Pointers are implicit in the language, but there is no pointer data type.

PZ12CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Java example 1 import java.io.*; 2 class DataConvert { 3 public int convert(byte ch) {return ch-'0';}}; 4 class DataStore extends DataConvert { 5 public void initial(int a) 6 {ci=0; size=a;}; 7 void save(int a) 8 {store[ci++]=a;}; 9 int setprint() { ci=0; return size;}; 10 int printval() { return store[ci++];}; 11 int sum() 12 {int arrsum = 0; 13 for(ci=0;ci<size;ci++)arrsum=arrsum+store[ci]; 14 return arrsum;}; 15 private static int maxsize = 9; 16 int size, ci; 17 nt[] store = new int[maxsize];}; Figure A.9 in text

PZ12CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Java example (continued) 18 class sample { 19 public static void main(String argv[ ]) 20 {int sz,j; 21 byte[ ] Line = new byte[10]; 22 DataStore x = new DataStore(); 23 try{ 24 while((sz= System.in.read(Line)) != 0) 25 {int k = x.convert(Line[0]); 26 x.initial(k); 27 for(j=1;j<=k;j++) 28 x.save(x.convert(Line[j])); 29 for(j=x.setprint(); j>0; j--) 30 System.out.print 31 (x.printval()); 32 System.out.print("; SUM="); 33 System.out.println(x.sum());}} 34 catch(Exception e){System.out.println 35 ("File error.");} 36 } // End main 37 } // End class sample

PZ12CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Scalar data Numeric data can be 8-bit, 16-bit, 32-bit or 64-bit signed integer data. There are also 32-bit float and 64-bit double real data that follow IEEE Standard 754. Java also stores data as byte and short, although these are coerced into int to perform any operations on them. Character data are stored using unicode. Unicode is an international standard that creates 16-bit characters. For example, char x = 'a' creates an object x with the unicode value for the character a. Boolean data may be true or false. Unlike C, Boolean is not an int.

PZ12CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Arrays Arrays are dynamic and are allocated as pointers: Declare an empty array: Newvalues Mydata[ ] To allocate the array: Mydata = new Newvalues[100]; -- Call the new function to allocate a 100-element array. To actually allocate each element of the array, you would also need to do, for each i, Mydata[i] = new Newvalues() Both could be accomplished in one step; for example, int[ ] Mydata = new int[100];

PZ12CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Control structures Same as C control structures. class definitions similar to C++ class definitions in defining instance variables and methods for a new class, but like Smalltalk the superclass of a new class is explicitly given: class Newvalues extends Object { public double x; /* instance variable */ public int y; /* instance variable */ Newvalues() {... } /* Constructor for Newvalues */ }

PZ12CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Predefined classes Java uses a large predefined class library. java.io.*$ is the standard input-output library java.awt.* is the standard applet library Java has the same sub-classing structure of C++. A subclass Newclass is a subclass of Olderclass by the class definition class Newclass extends Olderclass {... } newclass inherits all the instance variables of Olderclass, and method invocation to Newclass (as in Newclass.functionX) is passed to Olderclass.functionX if functionX is not a method defined in class Newclass.

PZ12CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Instance variables Variables in a class definition are usually instance variables- they are in every instance of an object of that class. Static attribute - To have a variable that is common across all instances of a given class. For example, a linked list structure would be of class LinkedObject. static FreeListType FreeList; C++ virtual methods are called abstract and are defined similarly to C++ virtual methods: abstract void MethodName(); /* Null body */

PZ12CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Threads Java allows for some level of multiprocessing through threads. Threads are defined by the new Thread(object) command. The synchronized attribute (synchronized void startSort()) on multiple-method definitions prevents more than one of them from executing at a time, and thus avoids deadlock situations.

PZ12CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Threads -2 Created by the new command Executed by the run() method; started with start() Executes until the stop() method or run() completes execution Threads may suspend() and resume() execution. Synchronization:Use monitors with synchronized attribute: public synchronized void methodName(int value) {val= returned_value;}