Jumping from C++ to Java

nutmegactSoftware and s/w Development

Nov 10, 2012 (4 years and 9 months ago)

226 views

Jumping from C++ to
Java

By Shawn Lupoli

Why Java?


Simple answer


GUI


There are two types of GUI that Java can
create


SWING


Computer program GUI


APPLET


GUI embedded into HTML


SWING GUI

APPLET GUI

http://janim.net/java
-
games/invader/space
-
invaders.html

Getting Started


You will need the Java Environment or JDK


Java Development Kit


http://java.sun.com/


(main webpage)


Look for Popular Downloads


Find J2SE 5.0 and click


Download JDK 5.0 and NetBeans


NetBeans


Visual Studio for Java


IDE for Java programs


Not my favorite


Do not use it


COULD USE NOTEPAD and the DOS SHELL
to edit and compile your projects

Things that are the same

(or close)


The main()


Still starts there


Displaying text


System.out.println(“….


instead of cout <<


Loops


If/Else structure


Menus/Cases

Things that are the same

(or close)


Functions


Templates


Advanced data structures


Brand new


called Generics


Things that are the DIFFERENT


Accepting input from the keyboard


File I/O


No structs


Linked Lists are PRE
-
CREATED


No pointers


NAME OF FILE MUST BE SAME AS THE CLASS’s
name


All are included in the class, source, main, etc…


Creating your first program


After you have downloaded and installed JDK


Notice the name of the file is the same as the
class


CASE COUNTS!!




Compiling and Running your first
program


NetBeans or some IDE has buttons to take
care of this.


Without an IDE, it is still possible.


At the DOS prompt


javac hello.java


should then compile, will tell you if any errors to fix


THIS ALSO COULD BE A PROBLEM IF YOU GET “'javac' is
not recognized as an internal or external command,
operable program or batch file.” Check your paths for Java.


java hello


will bring up running program (if no errors)

Websites


Warning before you explore


new 1.5.2 version is out


some websites (including mine) are slighty
outdated


most functions are the same


but some differences


if you see a warning in compiling stating “deprecated”,
means an older version, find a newer one