Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection.

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Introduction to ASP.NET.
Advertisements

George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Road Map Introduction to object oriented programming. Classes
C# Amy Broom Hossam Ragaban Randal Rollings Fall 2003.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
Lecture 9 Concepts of Programming Languages
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.
Peter Juszczyk CS 492/493 - ISGS. // Is this C# or Java? class TestApp { static void Main() { int counter = 0; counter++; } } The answer is C# - In C#
CMSC 341 Introduction to Java Based on tutorial by Rebecca Hasti at
Platforms and tools for Web Services and Mobile Applications Introduction to C# Bent Thomsen Aalborg University 3rd and 4th of June 2004.
Java versus C# An introduction to C# and Visual Studio.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
3.1 Documentation & Java Language Elements Purpose of documentation Assist the programmer with developing the program Assist other programers who.
Programming Languages and Paradigms Object-Oriented Programming.
Java and C++, The Difference An introduction Unit - 00.
Overview of Previous Lesson(s) Over View  OOP  A class is a data type that you define to suit customized application requirements.  A class can be.
CIS 068 JAVA vs. C++ Main Differences. CIS 068 JAVA vs C++ Java is (an interpreted) write once, run anywhere language. –The biggest potential stumbling.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Object Oriented Programming: Java Edition By: Samuel Robinson.
By Noorez Kassam Welcome to JNI. Why use JNI ? 1. You already have significantly large and tricky code written in another language and you would rather.
Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko.
Introduction to Java University of Sunderland CSE301 Harry R. Erwin, PhD.
CS212: Object Oriented Analysis and Design Lecture 6: Friends, Constructor and destructors.
Introduction to C# C# is - elegant, type-safe, object oriented language enabling to build applications that run on the.NET framework - types of applications.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
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.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
JAVA BASICS Prepared by The Smartpath Information Systems
C# Versus Java Author: Eaddy, Marc Source: Software Tools for the Professional Programmer. Dr. Dobb's Journal. Feb2001, Vol. 26 Issue 2, p74 Hong Lu CS699A.
1 C# A brief overview by Jack Senechal and Bryan Powell.
Hoang Anh Viet Hà Nội University of Technology Chapter 1. Introduction to C# Programming.
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
C# EMILEE KING. HISTORY OF C# In the late 1990’s Microsoft recognized the need to be able to develop applications that can run on multiple operating system.
Introduction to Java Java Translation Program Structure
Introduction to Java COM379 (Part-Time) University of Sunderland Harry R Erwin, PhD.
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
C# Classes and Inheritance CNS 3260 C#.NET Software Development.
Copyright Curt Hill Variables What are they? Why do we need them?
Java Basics Opening Discussion zWhat did we talk about last class? zWhat are the basic constructs in the programming languages you are familiar.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
 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.
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++)
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Introduction to C# By: Abir Ghattas Michel Barakat.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Object Oriented Programming Session # 03.  Abstraction: Process of forming of general and relevant information from a complex scenarios.  Encapsulation:
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
Introduction to C# Anders Hejlsberg Distinguished Engineer Developer Division Microsoft Corporation.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
Basic Syntax อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 2.
Object Oriented Programming Lecture 2: BallWorld.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Methods, classes, and Objects Dr. Jim Burns. Question  Which of the following access modifiers is the default modifier?  public  private  protected.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
CIS 068 JAVA vs. C++ Main Differences CIS 068.
Basic Introduction to C#
JAVA MULTIPLE CHOICE QUESTION.
Internet and Java Foundations, Programming and Practice
CS230 Tutorial Week 3.
Lecture 9 Concepts of Programming Languages
Interface.
Java Programming Language
Pointers C#, pointers can only be declared to hold the memory addresses of value types int i = 5; int *p; p = &i; *p = 10; // changes the value of i to.
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Chap 2. Identifiers, Keywords, and Types
Lecture 9 Concepts of Programming Languages
Presentation transcript:

Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection coupled with the elimination of pointers Powerful reflection capabilities No header files, all code is written inline Classes all descended from ‘object’ and must be allocated on the heap with ‘new’ keyword Thread support (similar to Java)

Java and C# - Some Commonalities Single inheritance Interfaces No global functions or constants, everything belongs to a class Arrays and strings with built-in bounds checking The "." operator is always used (no more ->, :: operators) ‘null’ and ‘boolean’/’bool’ are keywords All values must be initialized before use Only Boolean expressions are allowed in ‘if’ statements Try Block can have a finally clause

Both C# and Java compile initially to an intermediate language: C# to Microsoft Intermediate Language (MSIL), and Java to Java bytecode In each case the intermediate language can be run by interpretation, or just-in-time compilation, on an appropriate 'virtual machine' In C#, however, more support is given for the further compilation of the intermediate language code into native code

Some C# features More primitive data types than Java More extension to value types Supports safer enumeration types Support for ‘struct’ – light weight objects Operator overloading 'delegates' - type-safe method pointers used to implement event-handling Three types of arrays: –Single dimensional –Multi-dimensional rectangular –Multi-dimensional jagged

Restricted use of pointers The 'switch' statements has been changed to disallow 'fall-through' behavior Support for class 'properties'

C# Hello World using System;// System namespace public class HelloWorld { public static void Main()// the Main function starts // with capital M { Console.WriteLine("Hello World!”); }

C# Hello World Case sensitive Everything has to be inside a class Name of the class and the name of the file in which it is saved don’t need to match You are free to choose any extension for the file, but it is usual to use the extension '.cs' Supports both single line and multiple line comments

Variable Types (1): Reference Types and Value Types C# is a type-safe language Variables can hold either value types or reference types, or they can be pointers Where a variable ‘v’ contains a value type, it directly contains an object with some value Where a variable ‘v’ contains a reference type, what it directly contains is something which refers to an object

Built-in Types C# Type Signed?Bytes Occupied Possible Values sbyteYes1-128 to 127 shortYes to intYes to longYes to byteNo10 to 255 ushortNo20 to uintNo40 to ulongNo80 to

Built-in Types C# Type Signed?Bytes Occupied Possible Values floatYes4Approximately ±1.5 x to ±3.4 x with 7 significant figures doubleYes8Approximately ±5.0 x to ±1.7 x with 15 or 16 significant figures decimalYes12Approximately ±1.0 x to ±7.9 x with 28 or 29 significant figures charN/A2Any Unicode character (16 bit) boolN/A1 / 2true or false

Structs Structs are significantly different than C++ In C++ a struct is exactly like a class, except that the default inheritance and default access are public rather than private In C# structs are very different from classes Structs in C# are designed to encapsulate lightweight objects They are value types (not reference types), so they're passed by value They are sealed, which means they cannot be derived from or have any base class other than ‘System.Value’Type, which is derived from Object Structs cannot declare a default (parameterless) constructor Structs are more efficient than classes

Properties Formalize the concept of getter/setter methods In C# the relationship between a get and set method is inherent, while in Java or C++ it has to be maintained

Properties Java/C++ Example public int getSize() { return size; } public void setSize (int value) { size = value; } foo.setSize (getSize () + 1);

Properties C# Example public int Size { get {return size; } set {size = value; } } foo.size = foo.size + 1;

Reference Types The two pre-defined reference types are object and string ‘object’ is the ultimate base class of all other types New reference types can be defined using 'class', 'interface', and 'delegate' declarations Reference types actually hold the value of a memory address occupied by the object they reference Aliasing object x = new object(); x.myValue = 10; object y = x; y.myValue = 20; after this statement both ‘x.myValue’ and ‘y.myValue’ equal 20

Reference Types No aliasing in strings – these are immutable –The properties of these objects can't change themselves –So in order to change what a string variable references, a new string object must be created string s1 = "hello"; string s2 = s1; s1 = “world”; //s1 points to a new string // s2 keeps pointing to the old string