A Comparative Learning of C++, Java and PHP (PDF Download ...

June 14, 2016 | Author: Anonymous | Category: PHP, Java
Share Embed


Short Description

This book provides parallel comparison with learning highlights of C++, Java and PHP. The Salient Features of this Book ...

Description

i

i “cppjavaphp” — 2014/8/24 — 14:17 — page 1 — #1

Comparative study of C++, Java and PHP

CHANDRAKANT N

i

i

i

i “cppjavaphp” — 2014/8/24 — 14:17 — page 2 — #2

ABOUT AUTHOR • Dr.Chandrakant N Dr.Chandrakant Naikodi is presently working as a Senior Software Engineer in MNC, Bangalore, India. He has successfully accomplished Diploma, BE, ME and PhD degrees in Computer Science and Engineering. He has published many research papers in referred International Journals and Conferences. He is the author of two other technical books namely “C:Test Your Aptitude” and “1000 Questions and Answers in C++” published by Tata Mc-Graw Hill. His area of interest includes Computer Networks, MANETs, WSN, Programming Languages etc.

PREFACE • Nowadays programmers are encouraged or gets opportunity to learn more than one Object Oriented Languages which include C++, JAVA and PHP, in such cases this book gives an wonderful learning capability in short time by comparing all the features of Languages. We used C++11, Java6/7 and PHP5.4/5.5 for compiling C++, JAVA and PHP programs respectively. This book concentrates on comparing Basic Language features, Frequently Asked Questions, and Aptitude Questions with syntaxes and examples wherever required. The author will appreciate the suggestions or feedback from the readers and users of this book, kindly communicate via email addresses chandrakant.naikodi@{yahoo.in,gmail.com,facebook.com}.

i

i

i

i “cppjavaphp” — 2014/8/24 — 14:17 — page 3 — #3

ACKNOWLEDGEMENTS My deep gratitude and thanks to my wife Mrs. Vidyadhare Chandrakant and my daughter Vaishnavi N for their immense patience, prayers and support. My sincere thanks to my father Mr. Dharmanna N and mother Mrs. Shanthabhai Dharmanna for their blessings and support. I thank my brothers Mr. Shankar N, Mr. Surykant N, father-in-law Mr. Venkatesh J, mother-in-law Mrs. Kalavathi V, my brother-in-law Mr. Nataraj and Mr. Raghavendra. I am greatly thankful to my well wishers and teachers, especially late Sri. B C Bhavikatti, Sri. M S Stavermat, Sri. M B Naikodi, Dr. Badrinath GS who supported and encouraged me greatly in all steps. This book could not be completed without the support of my family and friends and the help of several individuals who extended their valuable support in the preparation and compilation of this book.

i

i

i

i “cppjavaphp” — 2014/8/24 — 14:17 — page 4 — #4

I dedicate this book to my lovely daughter Vaishnavi

i

i

i

i “cppjavaphp” — 2014/8/24 — 14:17 — page i — #5

Contents 1

Introduction 1.1 Overview Comparison of C++, JAVA and PHP 1.2 Language Architecture . . . . . . . . . . . . . . 1.3 Program Structure in C++, JAVA and PHP . . 1.4 Sample Program in C++, JAVA and PHP . . . .

. . . .

1 1 4 5 6

2

Data Types 2.1 Basic Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2 Data Type Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

7 7 8

3

Operators and Expressions 3.1 Arithmetic Operators . . . . . . . . . . . 3.2 Logical Operators . . . . . . . . . . . . . 3.3 Bitwise Operators . . . . . . . . . . . . 3.4 Relational/Comparison Operators . . . . 3.5 Assignment Operators . . . . . . . . . . 3.6 Precedence of Operators . . . . . . . . . 3.7 Evaluation of Logical Operations (Same for C++/JAVA/PHP) . . . . . . . . 3.8 Evaluation of Bitwise/Binary Operations (Same for C++/JAVA/PHP) . . . . . . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . . . .

11 11 11 12 12 12 13

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

15

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

15

. . . .

. . . .

17 17 20 22 26

5

Arrays 5.1 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

29 29

6

Strings 6.1 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

35 35

4

Control Flow Statements 4.1 Decision Making Statements 4.2 Looping Statements . . . . . 4.3 Branching Statements . . . . 4.4 Exception Handling . . . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

. . . . . .

. . . .

i

i

i

i

i “cppjavaphp” — 2014/8/24 — 14:17 — page ii — #6

ii 7

Functions 7.1 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

39 39

8

Classes 8.1 Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

45 45

9

Objects 9.1 Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

47 47

10 Inheritance 10.1 Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

51 51

11 Constructors and Destructors 11.1 Constructors and Destructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

55 55

12 Packages(Namespaces) 12.1 Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

59 59

13 Exceptions 13.1 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

63 63

14 Files 14.1 Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

67 67

15 Data Base Connection 15.1 Data Base Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

71 71

16 Memory Management 16.1 Memory Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

73 73

17 FAQs 77 17.1 C++ FAQs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 17.2 Java FAQs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 17.3 PHP FAQs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 18 Aptitude Questions 18.1 C++ Aptitude . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.2 Java Aptitude . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3 PHP Aptitude . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

i

159 159 167 294

i

View more...

Comments

Copyright © 2017 DATENPDF Inc.