Lecture 17 Modern Programming Trends JVM, C#, .NET

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Introduction to ASP.NET.
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.
1 Lecture 10 Intermediate Representations. 2 front end »produces an intermediate representation (IR) for the program. optimizer »transforms the code in.
Programming Languages and Paradigms
Memory Management Case study (JVM & CLR) KIRAN KUMAR V KIRAN KUMAR V LENIN THUMMALAPALLI LENIN THUMMALAPALLI.
Java Virtual Machine (JVM). Lecture Objectives Learn about the Java Virtual Machine (JVM) Understand the functionalities of the class loader subsystem.
1 1 Lecture 14 Java Virtual Machine Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
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;
CS 4800 By Brandon Andrews.  Specifications  Goals  Applications  Design Steps  Testing.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 33: Code Generation and Linking COMP 144 Programming Language Concepts Spring 2002.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 39: Case Study: C# and.NET COMP 144 Programming Language Concepts Spring 2002 Felix.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 31: Building a Runnable Program COMP 144 Programming Language Concepts Spring 2002.
3/17/2008Prof. Hilfinger CS 164 Lecture 231 Run-time organization Lecture 23.
Java Virtual Machine (JVM). Lecture Objectives Learn about the Java Virtual Machine (JVM) Understand the functionalities of the class loader subsystem.
Principles of Object-Oriented Software Development The language Java.
Java for High Performance Computing Jordi Garcia Almiñana 14 de Octubre de 1998 de la era post-internet.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 32: The Java Virtual Machine COMP 144 Programming Language Concepts Spring 2002.
JVM-1 Introduction to Java Virtual Machine. JVM-2 Outline Java Language, Java Virtual Machine and Java Platform Organization of Java Virtual Machine Garbage.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
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.
Unit 061 Java Virtual Machine (JVM) What is Java Virtual Machine? The Class Loader Subsystem Linking oVerification oPreparation oResolution Class Initialization.
Building An Interpreter After having done all of the analysis, it’s possible to run the program directly rather than compile it … and it may be worth it.
1 Software Testing and Quality Assurance Lecture 31 – SWE 205 Course Objective: Basics of Programming Languages & Software Construction Techniques.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
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.
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
Java Security Updated May Topics Intro to the Java Sandbox Language Level Security Run Time Security Evolution of Security Sandbox Models The Security.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 18: 0xCAFEBABE (Java Byte Codes)
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
JVM And CLR Dan Agar April 16, Outline Java and.NET Design Philosophies Overview of Virtual Machines Technical Look at JVM and CLR Comparison of.
Arpit Jain Mtech1. Outline Introduction Dalvik VM Java VM Examples Comparisons Experimental Evaluation.
1 The Java Virtual Machine Yearly Programming Project.
DAT602 Database Application Development Lecture 5 JAVA Review.
Implement High-level Program Language on JVM CSCE 531 ZHONGHAO LIU ZHONGHAO LIU XIAO LIN.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
1 October 1, October 1, 2015October 1, 2015October 1, 2015 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University Azusa.
Lecture 10 : Introduction to Java Virtual Machine
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko.
1 Comp 104: Operating Systems Concepts Java Development and Run-Time Store Organisation.
1 Introduction to JVM Based on material produced by Bill Venners.
The Java Programming Language
Programming in C#. I. Introduction C# (or C-Sharp) is a programming language. C# is used to write software that runs on the.NET Framework. Although C#
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
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.
Virtual Machines, Interpretation Techniques, and Just-In-Time Compilers Kostis Sagonas
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
JAVA COURSE 1 Computer Engineering Association. Compile your first program Public class Hello{ public class Hello(){ System.out.println(“Hello”); } puclic.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Object Oriented Software Development 4. C# data types, objects and references.
Programming Languages and Paradigms Activation Records in Java.
Today… “Hello World” ritual. Brief History of Java & How Java Works. Introduction to Java class structure. But first, next slide shows Java is No. 1 programming.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
INTRODUCTION CHAPTER #1 Visual Basic.NET. VB.Net General features It is an object oriented language  In the past VB had objects but focus was not placed.
RealTimeSystems Lab Jong-Koo, Lim
Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Chapter No. : 1 Introduction to Java.
Lecture 39: Case Study: C# and .NET
Internet and Java Foundations, Programming and Practice
Introduction Enosis Learning.
2.1. Compilers and Interpreters
CS360 Windows Programming
Introduction Enosis Learning.
CS-0401 INTERMEDIATE PROGRAMMING USING JAVA
CSc 453 Interpreters & Interpretation
Presentation transcript:

Lecture 17 Modern Programming Trends JVM, C#, .NET Programming Language Concepts Lecture 17 Modern Programming Trends JVM, C#, .NET

From Source Code to Executable Code program gcd(input, output); var i, j: integer; begin read(i, j); while i <> j do if i > j then i := i – j; else j := j – i; writeln(i) end. Compilation Compiler translate high-level source program intro an equivalent target program

Phases of Compilation The first three phases are language-dependent The last two are machine-dependent The middle two dependent on neither the language nor the machine

Example program gcd(input, output); var i, j: integer; begin read(i, j); while i <> j do if i > j then i := i – j; else j := j – i; writeln(i) end.

Example Syntax Tree and Symbol Table

Phases of Compilation Intermediate code generation transforms the abstract syntax tree into a less hierarchical representation: a control flow graph

Example Control Flow Graph Basic blocks are maximal-length set of sequential operations Operations on a set of virtual registers Unlimited A new one for each computed value Arc represents interblock control flow

Phases of Compilation Machine-independent code improvement performs a number of transformations: Eliminate redundant loads stores and arithmetic computations Eliminate redundancies across blocks

Phases of Compilation Target Code Generation translates blocks into the instruction set of the target machine, including branches for the arc It still relies in the set of virtual registers

Phases of Compilation Machine-specific code improvement consists of: Register allocation (mapping of virtual register to physical registers and multiplexing) Instruction scheduling

Compilation Passes Why are compilers divided in passes? Sharing the front-end among the compilers of more than one machine Sharing the back-end among the compilers of more than one language Historically, passes help reducing memory usage

Intermediate Forms Front-end and back-end are linked using an abstract representation known as the Intermediate Format (IF) They classified according to their level of machine dependence High-level IFs are usually trees or directed graphs that capture the hierarchy of the program They are useful for machine-independent code improvement, interpretation and other operations

Intermediate Forms Stack-based Language Stack-based language are another type of IFs E.g. JVM, Pascal’s P-code They are simple and compact They resemble post-order tree enumeration Operations Take their operands from an implicit stack Return their result to an implicit stack These languages tend to make language easy to port and the result code is very compact Ideal for network transfer of applets

The Java Virtual Machine Java Architecture Java Programming Language Java Virtual Machine (JVM) Java API We will use the JVM as a case study of an intermediate program representation

The Java Programming Environment

The Java Platform The byte code generated by the Java front-end is an intermediate form Compact and Platform-independent

The Role of the Virtual Machine Local or Remote

Dynamic Class Loading You don't have to know at compile-time all the classes that may ultimately take part in a running Java application. User-defined class loaders enable you to dynamically extend a Java app at run-time As it runs, your app can determine what extra classes it needs and load them Custom loaders can download classes across a network (applets), get them out of some kind of database, or even calculate them on the fly.

The Execution Engine Back-end transformation and execution Simple JVM: byte code interpretation Just-in-time compiler Method byte codes are compiled into machine code the first time they are invoked The machine code is cached for subsequent invocation It requires more memory Adaptive optimization The interpreter monitors the activity of the program, compiling the heavily used part of the program into machine code It is much faster than simple interpretation

The Java Virtual Machine

Shared Data Areas Each JVM has one of each: Method area: byte code and class (static) data storage Heap: object storage

Thread Data Areas Frame in Execution

Stack Frames Stack frames have three parts: Local variables Operand stack Frame data

Stack Frame Local Variables class Example { public static int runClassMethod(int i, long l, float f, double d, Object o, byte b) { return 0; } public int runInstanceMethod(char c, double d, short s, boolean b) {

Stack Frame Operand Stack Adding 2 numbers iload_0 iload_1 Iadd istore_2

Stack Frame Frame Data The stack frame also supports Constant pool resolution Normal method return Exception dispatch

Stack Frame Frame Allocation in a Heap class Example { public static void addAndPrint() { double result = addTwoTypes(1, 88.88); System.out.println(result); } public static double addTwoTypes(int i, double d) { return i + d;

Stack Frame Native Method A simulated stack of the target language (e.g. C) is compared.

The Heap Class instances and array are stores in a single, shared heap Each Java application has its own heap Isolation But a JVM crash will break this isolation JVM heaps always implement garbage collection mechanisms

Heap Object Representation

The Heap Object Representation

The Heap Memory/Speed Tradeoff

Reference The content of this lecture is based on Inside the Java 2 Virtual Machine by Bill Venners Chapter 1 Introduction to Java's Architecture http://www.artima.com/insidejvm/ed2/introarchP.html Chapter 5 The Java Virtual Machine http://www.artima.com/insidejvm/ed2/jvm.html Interactive Illustrations http://www.artima.com/insidejvm/applets/index.html

C# and .NET In 2000, Microsoft releases a new language, C#, heavily influences by Java and C++ Is there anything new from the programming languages point of view? Microsoft is making it the key stone in their new development strategy (.NET) Big bucks… big evil…

Hello World Java C# public class HelloWorld {    public static void main(String[] args) {       System.out.println(“Hello world!");    } } class HelloWorld {    static void Main(string[] args) {       System.Console.WriteLine(“Hello world!");    } }

Framework Class Libraries Common Language Runtime Motivation for C# .NET New development framework that promises to simplify Windows programming COM/DCOM is hard to learn Heavy on component orientation Language independence run-time system Common Language Run-time (CLR) C# programs VB .NET Framework Class Libraries Common Language Runtime Windows

Common Language Runtime It can execute .NET program in an intermediate representation, the Common Language Interface (CLI) CLR is designed to work well in a multi-language environment Java Virtual Machines is rather Java-oriented CLR is supposed to work well with imperative programming languages (e.g., C, Pascal) and statically typed object oriented languages (e.g., C#, Eiffel) Many language have compilers for CLR at different stages of development, including Python, Perl, Scheme, Haskell, Prolog,…

Motivation for C# Rapid application development (RAD) Visual development tools/languages such as Visual Basic and Delphi, are very popular and useful C# is optimized for such development model Platform-independence CLR and CLI Access to platform-native resources A more direct approach than the one taken by Java Native Interface (JNI)

C# Syntax Comparison with Java If/then/else Java C# int i = 0; if (i == 0) {    i = 1; } else {    i = 2; } int i = 0; if (i == 0) {    i = 1; } else {    i = 2; }

C# Syntax Switch C# Java int i = 0; switch (i) { case 0: break;    case 1:       i = 2; break;    default: i = -1;     break; } int i = 0; switch (i) {    case 0:       i = 1; break;    case 1: i = 2; break;    default: i = -1; break; }

C# Syntax While Do/While C# Java int i = 0; while (i++ < 10) { } int i = 0; do { } while (i++ < 10); int i = 0; do { } while (i++ < 10);

C# Syntax foreach Java import java.util.Vector; public static int sum(Vector v) {    int sum = 0;    for (int j = 0; j < v.size(); j++) {         Integer i = (Integer)v.elementAt(j);          sum = sum + i.intValue();    }    return sum; } C# using System.Collections; static int SumList(ArrayList theList) {    int sum = 0;    foreach (int j in theList) {       sum = sum + j;    }    return sum; }

C# Syntax Break/Continue Return Java C# int i = 0; while (i++ < 10) {    if (i < 5) continue;    break; } int i = 0; while (i++ < 10) {    if (i < 5) continue;    break; } public void returnNothing() {    return; } public int returnOne() {    return 1; } public void returnNothing() {    return; } public int returnOne() {    return 1; }

C# Syntax Object instantiation Exclusive access Java C# Something s = new Something(); Something s = new Something(); synchronized(this) {    // do something } lock(this) {    // do something }

C# Syntax try/catch/finally Java try {    throw new SampleException(); } catch (SampleException ex) { } finally { } C# try {    throw new SampleException(); } catch (SampleException ex) { } finally { } try {    throw new SampleException(); } catch {} finally { } catch clause is optional catch argument is optional No throws keyword

C# Syntax Class definition Interface definition Interface implementation Java C# class Foo extends Bar { ... } class Foo extends Bar { ... } interface IFoo extends IBar { ... } interface IFoo : IBar { ... } class Foo implements IFoo, IBaz { ... } class Bar: IFoo, IBaz { }

Other C# Features C# provides Java-style garbage collection C# implements a Java- and Delphi-style value/reference-type system Variables of primitive types also act like objects (unlike Java primitive objects) Java Integer iobj = new Integer(12); System.out.println(iobj.toString()); C# Console.WriteLine(12.ToString());

Other C# Features Enumerations Properties (forced getter and setters) enum description: ulong {    Good,    Bad,    Ugly }; Properties (forced getter and setters) TextBlock tb; if (tb.backgroundColor == Color.green) { // "get" is called for comparison    tb.backgroundColor = Color.red;  // "set" is called } else {    tb.backgroundColor = Color.blue; // "set“ is called }

Other C# Features Get/set public class TextBlock {    // Assume Color is an enum private Color _bgColor; private Color _fgColor;    public Color backgroundColor {   get {          return _bgColor;      }   set { _bgColor = value;   }    //... and so on...  } }

End of Lecture