Download presentation
Presentation is loading. Please wait.
Published byHoward Berry Modified over 9 years ago
1
Java and C++ Transitioning
2
A simple example public class HelloWorldApp { public static void main(String[] args) { //Display the string. System.out.println("Hello World!"); } } #include void main (int argc, char* argv[]) { cout << “Hello World”); } JAVA C++
3
Everything is a class in java public class HelloWorldApp { public static void main(String[] args) { //Display the string. System.out.println("Hello World!"); } } #include void main (int argc, char* argv[]) { cout << “Hello World”); } JAVA C++
4
static declarations public class HelloWorldApp { public static void main(String[] args) { //Display the string. System.out.println("Hello World!"); } } #include void main (int argc, char* argv[]) { cout << “Hello World”); } JAVA C++
5
static Declarations Used in class specifications Also used in other areas (ambiguity) –Must consider context One instance for ALL objects public class A { int x; static int y; void B(){…} static void C(){…} } A1 = new A(); A2 = new A(); A3 = new A(); 3 x values 1 y value Must declare an instance Of A to call B e.g. A1.B(); Use class to call C e.g. A.C(); System.out.println…
6
Different I/O procedures public class HelloWorldApp { public static void main(String[] args) { //Display the string. System.out.println("Hello World!"); } } #include void main (int argc, char* argv[]) { cout << “Hello World”); } JAVA C++
7
Command line parameters public class HelloWorldApp { public static void main(String[] args) { //Display the string. System.out.println("Hello World!"); } } #include void main (int argc, char* argv[]) { cout << “Hello World”); } JAVA C++
8
No include statements in java public class HelloWorldApp { public static void main(String[] args) { //Display the string. System.out.println("Hello World!"); } } #include void main (int argc, char* argv[]) { cout << “Hello World”); } JAVA C++
9
File naming public class HelloWorldApp { public static void main(String[] args) { //Display the string. System.out.println("Hello World!"); } } #include void main (int argc, char* argv[]) { cout << “Hello World”); } JAVA C++ HelloWorldApp.java Must be named: Anything.cpp Named ANYTHING:
10
File Organization JAVA C++ MainFile.java ClassA.javaClassB.java Main routine ClassA ClassB OR MainFile.cpp ClassA.cpp ClassB.java
11
No explicit pointers public class A { int x,y; A(){x=0;y=0;} public void printit(){…} } public class HelloWorldApp { public static void main(String[] args) { A A1, A2; A1 = new A(); A2 = new A(); A1.printit() } JAVA
12
Pointers in c++ class A { int x,y; A(){x=0;y=0;} public void printit(){…} } void main() { A* A1, A2; A1 = new A(); A2 = new A(); A1->printit(); } C++
13
Accessing Libraries C++ –Uses include –Requires compilation and explicit listing of files to be compiled/linked Java –No include/headers –Libraries grouped in packages –List libraries to be used in import –Automatically incorporates files from packages without explicit listing other than import –More notes on packages and import later
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.