C# and Java. C# and Java are both modern object-oriented languages

Similar documents
CPSC 3740 Programming Languages University of Lethbridge. Data Types

Array. Prepared By - Rifat Shahriyar

Introduce C# as Object Oriented programming language. Explain, tokens,

Introduction to Programming Using Java (98-388)

C# Fundamentals. Hans-Wolfgang Loidl School of Mathematical and Computer Sciences, Heriot-Watt University, Edinburgh

C# Types. Industrial Programming. Value Types. Signed and Unsigned. Lecture 3: C# Fundamentals

Industrial Programming

Java Primer 1: Types, Classes and Operators

PIC 20A Number, Autoboxing, and Unboxing

CS 430 Spring Mike Lam, Professor. Data Types and Type Checking

Chapter 2: Using Data

Declarations and Access Control SCJP tips

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309

C++11 and Compiler Update

Input And Output of C++

Introduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language

Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class.

Introduction to C++ with content from

Motivation was to facilitate development of systems software, especially OS development.

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Lesson 06 Arrays. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

CONTENTS: Array Usage Multi-Dimensional Arrays Reference Types. COMP-202 Unit 6: Arrays

The Object Model Overview. Contents. Section Title

Chapter 1 Getting Started

Operators and Expressions

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #44. Multidimensional Array and pointers

C20a: Selected Interfaces in Java API

Modern Programming Languages. Lecture Java Programming Language. An Introduction

Data Types, Variables and Arrays. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

A brief introduction to C programming for Java programmers

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given

Chapter 1 INTRODUCTION SYS-ED/ COMPUTER EDUCATION TECHNIQUES, INC.

Kakadu and Java. David Taubman, UNSW June 3, 2003

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result.

A Short Summary of Javali

Extending SystemVerilog Data Types to Nets

Type Checking and Type Equality

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

COMP 2355 Introduction to Systems Programming

Getting started with Java

Assumptions. History

CSC Java Programming, Fall Java Data Types and Control Constructs

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language

The Lorax Programming Language

COS 140: Foundations of Computer Science

CPS 506 Comparative Programming Languages. Programming Language

C++ (Non for C Programmer) (BT307) 40 Hours

Microsoft Visual C# Step by Step. John Sharp

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

CS260 Intro to Java & Android 03.Java Language Basics

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

CS Programming In C

JavaScript. Training Offer for JavaScript Introduction JavaScript. JavaScript Objects

This tutorial has been prepared for the beginners to help them understand basics of c# Programming.

Today. o main function. o cout object. o Allocate space for data to be used in the program. o The data can be changed

22c:111 Programming Language Concepts. Fall Types I

Zheng-Liang Lu Java Programming 45 / 79

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

10. Abstract Data Types

Client-Side Web Technologies. JavaScript Part I

Rules and syntax for inheritance. The boring stuff

Prerequisites: The student should have programming experience in a high-level language. ITCourseware, LLC Page 1. Object-Oriented Programming in C#

Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.

Extending SystemVerilog Data Types to Nets

Inheritance. Transitivity

(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days

Data Types. (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011

CS2351 Data Structures. Lecture 7: A Brief Review of Pointers in C

.Net Technologies. Components of.net Framework

by Pearson Education, Inc. All Rights Reserved.

Lab # 02. Basic Elements of C++ _ Part1

Chapter 2: Using Data

Motivation was to facilitate development of systems software, especially OS development.

OCA Java SE 7 Programmer I Certification Guide By Mela Gupta. Arrays

Chapter 6 part 1. Data Types. (updated based on 11th edition) ISBN

Introduction to C# Applications

COS 140: Foundations of Computer Science

An Introduction to C++

Another IS-A Relationship

First of all, it is a variable, just like other variables you studied

Synchronization SPL/2010 SPL/20 1

Chapter 6. Data Types

Creating Classes and Objects

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Answer1. Features of Java

Lecture Overview. [Scott, chapter 7] [Sebesta, chapter 6]

PROGRAMMING FUNDAMENTALS

Java: advanced object-oriented features

Short Notes of CS201

Language Reference Manual simplicity

Introduction To C#.NET

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

Inheritance (cont.) Inheritance. Hierarchy of Classes. Inheritance (cont.)

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

Transcription:

C# and Java C# and Java are both modern object-oriented languages C# came after Java and so it is more advanced in some ways C# has more functional characteristics (e.g., anonymous functions, closure, etc.) than Java In this brief introduction we will cover some small syntactic differences In chapter 9 of the textbook we will cover major features of C# that may be appear in Java

Unified Type System (C#) C# possesses a unified type system. This means it does not have primitive types as you know about in Java (e.g., int, character, etc.) Although syntactically some types may appear to be primitive (e.g., int) in C# they are true objects and inherit the Object type. If you were to use typeof() on an int enough times, you would get to Object.

Unified Type System (Java) Java does not have a unified type system in the sense that it possesses true primitives that are not objects Primitive types do not inherit Object's methods. Primitives in Java do, however, have wrapper classes that do inherit from Object. Example: new Integer(5);

Unsigned Types C# supports unsigned types. That is, any type that would ordinarily involve a sign bit will have an unsigned equivalent This basically trades the ability to represent negative numbers for a positive range that is twice as large. For example, considering an 8 bit byte, the signed range is -128 to 127 and the unsigned range is 0 to 255 Java does not support unsigned types

High Precision Floating Point (C#) C# supports a built-in primitive type called decimal that can represent high precision values. The decimal type is 128 bits in size. It can represent values in the range 10 28 to -10 28 It cannot represent decimals of arbitrary length

High Precision Floating Point (Java) Java has no primitive type like decimal to handle increased decimal precision, but possesses a built in class called BigDecimal that can handle this situation. (There is a BigInteger too.) BigDecimal allows for decimal values of any length and numeric value. Since values are saved like strings, numeric processing is very slow.

Type Lifting In C#, declaring a variable with a question mark after the type allows that variable to be assigned the null value. Variables declared this way gain a boolean field called HasValue. Java primitives lack this ability, but can be assigned null when instantiated in their wrapper classes. This is somewhat similar to the option type in F#

Type Lifting Example

Parameter Passing (C#) By default, C# passes things by value, but methods can be configured to allow pass by reference. This is done using the ref keyword.

Parameter Passing (Java) Java is a strictly pass by value language and does not support pass by reference behavior. It is possible to pass around a reference to an object and change the object in that way. In this case it is the reference (address of the object) that is passed by value rather than the object itself.

Method Overriding (C#) In C#, it is necessary to explicitly state which methods can be overridden within their source files. Any attempt to override a method not declared virtual in its source file will cause a syntax error. The overriding function must also be declared with the override keyword.

Method Overriding Example (C#)

Method Overriding (Java) In Java, every method is implicitly virtual and can be overridden at any time.

Multidimensional Arrays C# supports two different kinds of syntax for multidimensional arrays: Rectangular Arrays: int[,] x = new int[m,n]; This kind of array minimizes the number of pointers that must be followed and is more efficient. Jagged Arrays: int[][] x = new int[m][n]; Basically an array of arrays. Involves a pointer for each row in the array. This is the only type of multidimensional array Java supports.

Tuples, Pointers, and Structs C# supports both tuples and pointers while Java does not. However, since C# also supports structs, there is little reason to use tuples. Pointers are considered something of a security risk in C# Any code using them must be declared with the unsafe keyword. Structs function exactly as they do in C.

Enumerations The syntax for enumerated types is virtually identical between the two languages. The underlying structure is different though. In C#, enumerations are implemented with structs. An integer value is paired with a label. This makes comparisons in switch statements extremely efficient. Java makes the enumeration a class, which (considering classes are Java's answer to structs) is the same general idea, but is somewhat less efficient.

Enumeration Example (C#)

And More There are obviously more differences than the ones listed here. This is intended to be a quick introduction to some important differences that might otherwise be troublesome.