Algorithm Programming 1 (using Java) 89-210 Bar-Ilan University 2007-2008 תשס"ח by Moshe Fresko.

Slides:



Advertisements
Similar presentations
A Programmer's Introduction to Java - from a S/370 user (c) IDMS/SQL News
Advertisements

Chapter 16 Java Virtual Machine. To compile a java program in Simple.java, enter javac Simple.java javac outputs Simple.class, a file that contains bytecode.
Introduction To Java Objectives For Today â Introduction To Java â The Java Platform & The (JVM) Java Virtual Machine â Core Java (API) Application Programming.
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 The objectives of this chapter are: To describe the key aspects of Java To describe the Java software development kit (SDK) To explain.
Object Orientated Programming
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.
Introduction to Java Kiyeol Ryu Java Programming Language.
Introduction to Java Programming, 4E
Chapter 16 Java Virtual Machine. To compile a java program in Simple.java, enter javac Simple.java javac outputs Simple.class, a file that contains bytecode.
A Short Introduction to JAVA
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.
L EC. 01: J AVA FUNDAMENTALS Fall Java Programming.
01 Introduction to Java Technology. 2 Contents History of Java What is Java? Java Platforms Java Virtual Machine (JVM) Java Development Kit (JDK) Benefits.
Java PAL.  Contains the development kit and the runtime environment ( aka the Java Virtual Machine )  Download Link:
CMSC 341 Introduction to Java Based on tutorial by Rebecca Hasti at
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Getting Started What is Java? A programming language –Fully buzzword-compliant: A simple, object oriented, distributed, interpreted, robust, secure,
Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps.
BASIC JAVA PROGRAMMING TUTORIAL. History  James Gosling and Sun Microsystems  Oak  Java, May 20, 1995, Sun World  Hot Java –The first Java-enabled.
BA22001 Introduction to Java Instructor: Jingwu He.
Introduction to Java Programming with JBuilder 4
S.W. Ma/CIM/LWL41211/2 Prog. IIA Page 1 HKIVE (Lee Wai Lee Campus) Department of CIM Course : Year 2 Module : Programming IIA Textbook : Introduction.
Java Workshop for Teachers May 6, 2005 A Brief Look at the Java Programming Language.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
©2007 · Georges Merx and Ronald J. NormanSlide 1 Chapter 3 The Structure and Syntax of Java.
Java Bytecode What is a.class file anyway? Dan Fleck George Mason University Fall 2007.
Sadegh Aliakbary Sharif University of Technology Fall 2012.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
POS 406 Java Technology And Beginning Java Code
Introduction to Java Programming with Forte Y. Daniel Liang.
1 Introduction to Java. 2 What is Java? A programming language. A platform –A virtual machine (JVM) definition. –Runtime environments in diverse hardware.
Introduction to Java Programming. Introduction Course Objectives Organization of the Book.
Session 1 Introduction to Java. Objectives Java Simplified / Session 1 / 2 of 32 Explain the history of Java Explain Java in brief List the types of Java.
National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.
CS Software Studio Java Lab 1 Meng-Ting Wang PLLAB, Computer Science Department, National Tsing-Hua University.
Java and its Evolution. Contents Java Introduction Java Features How Java Differs from other OO languages Java and the World Wide Web Java Environment.
23-October-2002cse JavaIntro © 2002 University of Washington1 Intro to Java CSE 413, Autumn 2002 Programming Languages
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Java Programming Transparency No. 1-1 Introduction to Java Programming Cheng-Chia Chen September 2001.
Application Architecture Using Java Hong Li. Introduction Developed by a team led by James Gosling at Sun Microsystem. Originally called Oak, designed.
Duke CPS From C++ to Java l Java history: Oak, toaster-ovens, internet language, panacea l What it is ä O-O language, not a hybrid (cf. C++)
Java Programming: Advanced Topics1 Introduction to Advanced Java Programming Chapter 1.
Java Computer Industry Lab. 1 Programming Java Java Basics Incheon Paik.
RealTimeSystems Lab Jong-Koo, Lim
Introduction to JAVA Programming
Introduction to Java Programming, 4E Y. Daniel Liang.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Fundamental of Java Programming (630002) Unit – 1 Introduction to Java.
Java™ 2 Platform Getting Started.
Java and C II CSE 351 Spring 2017 Instructor: Ruth Anderson
Introduction to Java Programming
Chapter No. : 1 Introduction to Java.
Introduction to Advanced Java Programming
CS216: Program and Data Representation
Introduction Enosis Learning.
Introduction to Java Dept. Business Computing University of Winnipeg
Introduction Enosis Learning.
Advanced Programming Fall 2017.
From C++ to Java Java history: Oak, toaster-ovens, internet language, panacea What it is O-O language, not a hybrid (cf. C++) compiled to byte-code, executed.
Chap 1. Getting Started Objectives
Java and C II CSE 351 Spring 2017 Instructor: Ruth Anderson
Chap 4. Programming Fundamentals
Outcome of the Lecture Upon completion of this lecture you will be able to understand Fundamentals and Characteristics of Java Language Basic Terminology.
Presentation transcript:

Algorithm Programming 1 (using Java) Bar-Ilan University תשס"ח by Moshe Fresko

Course objectives  Learning Professional Programming by Algorithmic Examples  Learning Java  Object Oriented Programming  Design Patterns  Multithreaded Programming  GUI  Run-time Class Information

Course Requirements  Exercises/Projects, 25 % of the grade Programming Exercises One step-by-step Project Time schedules are strict, no late exercises are accepted. They will be handed on via the Department Submitec utility Cheating is punished by Discipline Assembly ( Very strictly )  Exam 75 %

What is Java ?  (Almost) Fully OO Programming Language.  Syntax: Similar to C++, Different in some Semantics and Internals.  Architecture Neutral  World-Wide-Web programming language

History  Early 1990s, Oak, by Sun For embedded systems in Consumer Electronic Devices  1994, Sun decided to adapt Oak to Web  January 1995, renamed as Java, Building Web based applications  May 1995, Sun ’ s first JDK (Java Development Kit) With HotJava capable of running Applets  1998, Sun released Java 2 SDK (J2SDK) By time Bunch of Libraries are added

Object Oriented Reminders  Abstraction  Encapsulation  Inheritance  Abstract classes  Polymorphism By Inheritance By Overloading Interfacing  Constructors and Finalizers

Design Patterns  Design Patterns help you learn from others ’ successes, instead of your failures  Separate things that change, from the things that doesn ’ t change  Elegant and Cheap-to-Maintain  Inheritance can be thought as a DP, and so Composition, etc.  Iterator (Enumeration in Java 1.0 and 1.1)

Resources  Internet Tutorials and Downloads of Java of Java Development Environment  NetBeans ide  Symantec ’ s Cofe  Borland ’ s JBuilder  Books Developing Java Software Russel Winder & Graham Roberts 2 nd Edition, 2000 John Wiley and Sons, Ltd. Java 2 Complete Gemma O ’ Sullivan 1998, Sybex Thinking in Java Bruce Eckel 3 rd Edition (free to download) Design Patterns Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides 1995, Addison Wesley Other Java Books …

JDK, J2SE  J2SE, J2EE and J2ME  JFC : Java Foundation Classes  Java2D : 2D Graphics  JavaBeans : Java object component technology  Servlets : Web Server  JavaHelp : For creating help systems  etc.  javac : Compiler to Byte-Code  java : Loads a byte-code into JVM and executes  javap : Byte-code viewer  javadoc : Creates HTML documentation for the code.  jdb : Java debugger  appletviewer : To view applets from within an HMTL page

Application Example  Programs Applications Applets  Programs are Case Sensitive  Example: HelloWorldApp.java file public class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); }

Application Example  javac HelloWorldApp.java Compiles and creates ByteCode in file “ HelloWorldApp.class ”  java HelloWorldApp Looks for the file “ HelloWorldApp.class ” and for the class “ HelloWorldApp ” in it, and starts to run the static “ main ” function.

Applet Example // HelloWorld.java file import java.applet.*; import java.awt.*; public class HelloWorld extends Applet { public void paint(Graphics g) { g.drawString("Hello world!", 50, 25); } // Hello.html file A Simple Program Here is the output of my program:

JVM  Source Code  Java Compiler (javac) -> ByteCode  Java Interpreter (java) - Java VM

JVM  java -classpath … ; … ; … for providing paths of class libraries, and.jar files .jar files are a set of class files compressed into a single file Class Execution Engine Adapter Interface Adapter OS JNI

Java Bytecode  Like C++  Assembly, Java  ByteCode  We need to check ByteCode For Performance and Memory Usage Tuning Size and Execution Speed Debugging

Java Bytecode - Example class Employee { private String name ; private int idNumber ; public Employee(String strName, int num) { name = strName ; idNumber = num ; storeData(strName,num) ; } public String employeeName() { return name ; } public int employeeNumber() { return idNumber ; } private void storeData(String s, int num) { //... } javac Employee.javacreates Employee.class javap – c Employeeto print to string the byte-code in visual form

Java Bytecode - Example Compiled from "Employee.java" class Employee extends java.lang.Object{ public Employee(java.lang.String,int); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object." ":()V 4: aload_0 5: aload_1 6: putfield #2; //Field name:Ljava/lang/String; 9: aload_0 10: iload_2 11: putfield #3; //Field idNumber:I 14: aload_0 15: aload_1 16: iload_2 17: invokespecial #4; //MethodstoreData:(Ljava/lang/String;I)V 20: return public java.lang.String employeeName(); Code: 0: aload_0 1: getfield #2; //Field name:Ljava/lang/String; 4: areturn public int employeeNumber(); Code: 0: aload_0 1: getfield #3; //Field idNumber:I 4: ireturn }

Java Bytecode - opcodes  opcodes a... : opcode is manipulating type object ref. i … : opcode is manipulation type integer b … : byte, c... : char, d … : double, etc.

Java Bytecode - JVM  JVM Stack-based machine Each thread has a JVM stack which stores Frames A frame is created each time a method is invoked Each Frame has  Operand Stack  An array of Local variables  A reference to Runtime constant pool of the class of the current method

Java Bytecode – JVM diagram

Java Bytecode  Local variables 0 th : this (for constructors or instant methods) Then parameters Then local variables  Operand stack LIFO stack, to pop and push values Used to receive return values  Example public string employeeName() { return name ; } public java.lang.String employeeName(); Code: 0: aload_0 1: getfield #2; //Field name:Ljava/lang/String; 4: areturn  aload_0 : pushes this pointer into stack  getfield #2 : this popped+2 added and get reference (for name) from runtime constant pool of the class. This is loaded to the stack  areturn : returns the top value of the stack (name). It is popped from operand stack and pushed to the operand stack of calling method  The real machine code is : 2A B B0

Java Bytecode public Employee(String strName, int num) { name = strName ; idNumber = num ; storeData(strName,num) ; } public Employee(java.lang.String,int); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object." ":()V 4: aload_0 5: aload_1 6: putfield #2; //Field name:Ljava/lang/String; 9: aload_0 10: iload_2 11: putfield #3; //Field idNumber:I 14: aload_0 15: aload_1 16: iload_2 17: invokespecial #4; //Method storeData:(Ljava/lang/String;I)V 20: return

String and StringBuffer  In package java.lang  StringBuffer is modifiable version of String class  String has length substring extraction Finding and matching String comparison Uppercase and lowercase conversion Leading and trailing whitespace elimination Conversion to/from char arrays Conversion from primitive types to String Appending strings Inserting strings