Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Algorithm Programming 1 89-210 Bar-Ilan University 2007-2008 תשס"ח by Moshe Fresko."— Presentation transcript:

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

2 Java for C++ programmers

3 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.

4 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.

5 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.

6 C++ vs. Java 21. Constructors are similar to C++. 22. No destructors in Java. Only finalize() method, called during Garbage Collection. 23. Method overloading like in C++. 24. 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)

7 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.

8 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();

9 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++. 44. 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.

10 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

11 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


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

Similar presentations


Ads by Google