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

Slides:



Advertisements
Similar presentations
Web Application Development Slides Credit Umair Javed LUMS.
Advertisements

Portability and Safety Mahdi Milani Fard Dec, 2006 Java.
Lab#1 (14/3/1431h) Introduction To java programming cs425
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
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++
Session 1 CS-240 Data Structures Binghamton University Dick Steflik.
Lecture 9 Concepts of Programming Languages
Java Data Types  Everything is an Object  Except Primitive Data Types  For efficiency  Platform independent  Portable  “slow”  Objects are often.
Abstract Data Types and Encapsulation Concepts
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#
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
OOP Languages: Java vs C++
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
Programming Languages and Paradigms Object-Oriented Programming.
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
Java and C++, The Difference An introduction Unit - 00.
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.
Comparing C++ and Java. As a C++ programmer, you already have the basic idea of object-oriented programming, and the syntax of Java no doubt looks familiar.
Introduction to Java University of Sunderland CSE301 Harry R. Erwin, PhD.
University of Houston-Clear Lake Proprietary© 1997 Evolution of Programming Languages Basic cycle of improvement –Experience software difficulties –Theory.
CS212: Object Oriented Analysis and Design Lecture 6: Friends, Constructor and destructors.
Basic Java Syntax CSE301 University of Sunderland Harry R Erwin, PhD.
Programming Languages and Paradigms Object-Oriented Programming.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
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 SystemVerilog Enhancement Requests Daniel Schostak Principal Engineer February 26 th 2010.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
Introduction to Java COM379 (Part-Time) University of Sunderland Harry R Erwin, PhD.
C# Classes and Inheritance CNS 3260 C#.NET Software Development.
Types in programming languages1 What are types, and why do we need them?
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
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.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
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.
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Inheritance Initialization & Destruction of Derived Objects Protected Members Non-public Inheritance Virtual Function Implementation Virtual Destructors.
JAVA INTRODUCTION. What is Java? 1. Java is a Pure Object – Oriented language 2. Java is developing by existing languages like C and C++. How Java Differs.
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++)
Introduction to C# By: Abir Ghattas Michel Barakat.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Chapter 1 C++ Basics Review (Section 1.4). Classes Defines the organization of a data user-defined type. Members can be  Data  Functions/Methods Information.
1 Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Reference Types CSE301 University of Sunderland Harry R Erwin, PhD.
C++ General Characteristics: - Mixed typing system - Constructors and destructors - Elaborate access controls to class entities.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection.
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.
CIS 068 JAVA vs. C++ Main Differences CIS 068.
JAVA MULTIPLE CHOICE QUESTION.
BRIEF Overview ON THE MAJOR Similarities & Differences
Chapter 1. Understanding Java
Andy Wang Object Oriented Programming in C++ COP 3330
Lecture 9 Concepts of Programming Languages
null, true, and false are also reserved.
Java Programming Language
Introduction to Java Programming
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.
Chap 2. Identifiers, Keywords, and Types
Lecture 10 Concepts of Programming Languages
Lecture 9 Concepts of Programming Languages
Presentation transcript:

Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko

Java for C++ programmers

C++ vs. Java 1. Java with Interpreter is Slower then compiled C++ 2. Both kind of Comments like C++ // one line comment /* block comment */ 3. No global methods or data, Everything is in class. Instead one can use Static Methods / Static Member 4. No structs, enumerators, or unions. Only classes. 5. All definitions are in class. No method declaration. 6. No class pre-declaration, only definition. 7. No scope resolution operator :: only.

C++ vs. Java 8. Similar to #include in C++, there is import in Java Not the same meaning. import is like namespace. 9. Standard Primitive Data Types boolean, char, byte, short, int, long, float, double. 10. char is 16-bit Unicode 11. Type checking is much tighter in Java. 12. Static quoted strings are automatically converted into String object. 13. Arrays look similar, but have different structure and behavior from C++. Arrays are treated as objects.

C++ vs. Java 14. Objects are created with new. Triangle trg = new Triangle(3,4,5) ; 15. Only primitive types are created on Stack. 16. No forward declarations are needed. 17. Java has no preprocessor. 18. Packages in place of Namespaces. 19. Default Initialization. Object Handles initialized to null, primitive class initialized 0 or equivalent. 20. No pointers in the sense of C++. New creates a reference (or handle). No pointer arithmetic.

C++ vs. Java 21. Constructors are similar to C No destructors in Java. Only finalize() method, called during Garbage Collection. 23. Method overloading like in C Does not support default arguments. 25. No ‘ goto ’, There is ‘ break label ’ and ‘ continue label ’ 26. Singly rooted hierarchy, everything derives from “ Object ”. 27. No parameterized types (no templates)

C++ vs. Java 28. With GC memory leaks are much harder 29. Java has built-in Multi-Threading support 30. Mutual exclusion at object level. 31. Access Specifiers for each member (public, private, protected) 32. Everything in a Package is Friendly 33. Nested classes. Inner class knows the outer class (keeps a handle). 34. No inline keyword. Compiler optimization can do it.

C++ vs. Java 35. Inheritance with “ extends ” keyword. 36. Only to one-level up parent calls with “ super ” keyword. 37. Inheritance doesn ’ t change protection level. Only ‘ public ’ inheritance 38. “ interface ” keyword for abstract base class. “ implements ” keyword for implementing it. 39. No “ virtual ” keyword, since all non-static methods are dynamically binded. “ final ” keyword for efficiency. 40. No Multiple Class Inheritance. But, many interfaces can be implemented. 41. Run-time type identification X.getClass().getName();

C++ vs. Java 42. All Downcast with run-time check. So there is no bad casts like in C++. derived d = (derived) base ; Exceptions are derived from Throwable. “ finally ” keyword for cleanup after exception. 43. Exception Specifications are superior to C No operator overloading. 45. No const. For compile time constant value use “ static final ”. 46. No by value only by reference. 47. Java static variables are started in the first binding of the class.

C++ vs. Java 48. For security issues Application and Applets differ. 49. Native method calls. (Only applications, not applets) 50. Built-in support for comment documentation. 51. Standard libraries for certain tasks. Networking Database connection Multithreading Distributed Objects (RMI and CORBA) Compression Commerce 52. Java 1.1 includes Java Beans standard for component development

Garbage Collection  No on stack memory management, only from Heap.  Different GC Schemes 1) Reference Counting – Problem: Self-referential Groups 2) Chain Search 3) Stop-and-Copy – Two Heaps needed (or chunking) – Copying (If there are little or no garbage) – Lot ’ s of memory transfer 4) Mark-and-Sweep 5) Adaptive Generational Stop-and-Copy Mark-and-Sweep