C++ vs. Java: Similiarities & Differences Dr. Jeyakesavan Veerasamy Director of CS UTDesign program & CS Teaching Faculty University.

Slides:



Advertisements
Similar presentations
C++ Language Fundamentals. 2 Contents 1. Introduction to C++ 2. Basic syntax rules 3. Declaring and using variables.
Advertisements

IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Portability and Safety Mahdi Milani Fard Dec, 2006 Java.
Date: Subject:Distributed Data Processing Name:Maria Br ü ckner.
Various languages….  Could affect performance  Could affect reliability  Could affect language choice.
Advanced Java Concepts Dr. Jeyakesavan Veerasamy
Pointers Revisited l What is variable address, name, value? l What is a pointer? l How is a pointer declared? l What is address-of (reference) and dereference.
C++ & Java Dick Steflik CS-248. Similarities Syntax - almost identical Object Model - very similar Stream based I/O.
CIS 101: Computer Programming and Problem Solving Lecture 8 Usman Roshan Department of Computer Science NJIT.
Rossella Lau Lecture 8, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 8: Polymorphism & C++ pointer  Inheritance.
Session 1 CS-240 Data Structures Binghamton University Dick Steflik.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
1 ES 314 Advanced Programming Lec 3 Sept 8 Goals: complete discussion of pointers discuss 1-d array examples Selection sorting Insertion sorting 2-d arrays.
1 CSE 303 Lecture 11 Heap memory allocation ( malloc, free ) reading: Programming in C Ch. 11, 17 slides created by Marty Stepp
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles C/C++ Emery Berger and Mark Corner University of Massachusetts.
Guide To UNIX Using Linux Third Edition
Introduction to Java.
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
Programming in Java; Instructor:Moorthy Introduction, Objects, Classes, Libraries1 Programming in Java Introduction.
OOP Languages: Java vs C++
Programming Languages and Paradigms Object-Oriented Programming.
CSCI 224 Introduction to Java Programming. Course Objectives  Learn the Java programming language: Syntax, Idioms Patterns, Styles  Become comfortable.
Java and C++, The Difference An introduction Unit - 00.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 10. Pointers & Dynamic Data Structures.
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.
Implement High-level Program Language on JVM CSCE 531 ZHONGHAO LIU ZHONGHAO LIU XIAO LIN.
Java Introduction Lecture 1. Java Powerful, object-oriented language Free SDK and many resources at
By – Tanvir Alam.  This tutorial offers several things.  You’ll see some neat features of the language.  You’ll learn the right things to google. 
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.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
February 11, 2005 More Pointers Dynamic Memory Allocation.
Introduction and Features of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++
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.
Computer Science and Software Engineering University of Wisconsin - Platteville 2. Pointer Yan Shi CS/SE2630 Lecture Notes.
Game Programming in Java Dr. Jeyakesavan Veerasamy CS faculty, The University of Texas at Dallas Website:
Constructors CMSC 202. Object Creation Objects are created by using the operator new in statements such as… The following expression invokes a special.
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.
CPSC 252 Dynamic Memory Allocation Page 1 Dynamic memory allocation Our first IntVector class has some serious limitations the capacity is fixed at MAX_SIZE.
Object-Oriented Programming in C++
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
C/C++ Basics. Basic Concepts Basic functions of each language: Input, output, math, decision, repetition Types of errors: Syntax errors, logic errors,
1 Lecture07: Memory Model 5/2/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
CMSC 202 Advanced Section Classes and Objects: Object Creation and Constructors.
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++)
Introducing C++ to Java Programmers by Kip Irvine updated 2/27/2003.
Classes, Arrays & Pointers. Compiler & Linker expectations file1.cppfile2.cppfilen.cpp …. file1.ofile2.ofilen.o …. Linker application (executable) Compiler.
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
Dr. Yang, QingXiong (with slides borrowed from Dr. Yuen, Joe) LT:10 Advance Pointer Array, String and Dynamic Memory Allocation CS2311 Computer Programming.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Memory Management in Java Mr. Gerb Computer Science 4.
FASTFAST All rights reserved © MEP Make programming fun again.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Lecture 3 Translation.
Object Oriented Programming in
Object Lifetime and Pointers
Intro to ETEC Java.
BRIEF Overview ON THE MAJOR Similarities & Differences
Generics, Lambdas, Reflections
Dynamic Memory Allocation
Computer Organization & Compilation Process
C/C++ Basics.
BRIEF Overview ON THE MAJOR Similarities & Differences
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.
Dynamic Memory.
Computer Organization & Compilation Process
Classes and Objects Object Creation
CMSC 202 Constructors Version 9/10.
Presentation transcript:

C++ vs. Java: Similiarities & Differences Dr. Jeyakesavan Veerasamy Director of CS UTDesign program & CS Teaching Faculty University of Texas at Dallas, USA

History C (1969)  C++ (1979)  Java (1995) Both support OOP. Most OOP library contents are similar, however Java continues to grow. Syntax is very close – Java has strong influence of C/C++. Easy to learn the other language when you know one of these.

C++ compiler & Linker usage file1.cppfile2.cppfilen.cpp …. file1.ofile2.ofilen.o …. Linker application (executable) Compiler C++ compiler does not care about filenames. This appliction runs directly on top of OS.

Java compiler usage file1.javafile2.javafilen.java …. file1.classfile2.classfilen.class …. Compiler Operating System Java Runtime Environment (JRE)

C++ vs. Java: differences C++Java Write once, compile everywhere  unique executable for each target Write once, run anywhere  same class files will run above all target-specific JREs. No strict relationship between class names and filenames. Typically, a header file and implementation file are used for each class. Strict relationship is enforced, e.g. source code for class PayRoll has to be in PayRoll.java

C++ vs. Java: differences … C++Java I/O statements use cin and cout, e.g. cin >> x; cout << y; I/O input mechanism is bit more complex, since default mechanism reads one byte at a time (System.in). Output is easy, e.g. System.out.println(x); Pointers, References, and pass by value are supported. No array bound checking. Primitive data types always passed by value. Objects are passed by reference. Array bounds are always checked.

C++ vs. Java: differences … C++Java Explicit memory management. Supports destructors. Automatic Garbage Collection. Supports operator overloading. Specifically operator overloading was thrown out.

Types of memory used by executable task Code Stack data (static) heap (dynamic)

Objects Objects can be created as local variables just like any basic data types in C++. C++: ComplexType num1; Java: Nothing equivalent – Objects cannot be in stack.

Objects in Heap C++: ComplexType *num1 = new ComplexType(…); Java: ComplexType num1 = new ComplexType(…);

Arrays Basic data types and classes are treated the same way in C++, unlike Java. C++: ComplexNumber numbers[5]; Java: nothing equivalent.

C++ array version #2 ComplexNumber *numbers; numbers = new ComplexNumber[5]; Java: nothing equivalent for classes, but possible for basic data types: int numbers[]; numbers = new int[5];

C++ array version #3 ComplexNumber **numbers; numbers = new ComplexNumber*[5]; for( index i = 0 ; i < 5 ; i++) numbers[i] = new ComplexNumber(…); Java: ComplexNumber numbers[]; numbers = new ComplexNumber [5]; for( index i = 0 ; i < 5 ; i++) numbers[i] = new ComplexNumber(…);

C++ vs. Java: Analogy Working with C++ is like flying a airpline, while working with Java is like driving a car. What does it mean? Too many controls/options in C++: think before use each one. Careful use can result in efficiency, poor use can result in serious inefficiency Issues like memory leak can crash the application, out-of-bounds array access can cause memory corruption – but it may not show up for long time – causing lot of headache! Java : slow and steady wins the race?

References C++ tutorials: C++ reference: Java tutorial: Java API documentation: