Going from C++ to Java Jayden Navarro.

Slides:



Advertisements
Similar presentations
Java Intro. A First Java Program //The Hello, World! program in Java public class Hello { public static void main(String[] args) { System.out.println("Hello,
Advertisements

CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
General Computer Science for Engineers CISC 106 Lecture 26 Dr. John Cavazos Computer and Information Sciences 04/24/2009.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
CMSC 341 Introduction to Java Based on tutorial by Rebecca Hasti at
Programming in Java; Instructor:Moorthy Introduction, Objects, Classes, Libraries1 Programming in Java Introduction.
“Introduction to Programming With Java”
Introduction to C++ - How C++ Evolved Most popular languages currently: COBOL, Fortran, C, C++, Java (script) C was developed in 1970s at AT&T (Richie)
Georgia Institute of Technology Speed part 3 Barb Ericson Georgia Institute of Technology May 2006.
Welcome to the Lecture Series on “Introduction to Programming With Java”
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Session One Introduction. Personal Introduction Role of programmers Robot Examination HUD & HID Uploading Code.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
2: Everything is an Object You Manipulate Objects Using References Primitives Arrays in Java Scoping You Never Destroy Objects Creating New Data Types:
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.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
Programming Fundamentals 2: Simple/ F II Objectives – –give some simple examples of Java applications and one applet 2. Simple Java.
Mixing integer and floating point numbers in an arithmetic operation.
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
Java for C++ Programmers A Brief Tutorial. Overview Classes and Objects Simple Program Constructors Arrays Strings Inheritance and Interfaces Exceptions.
Overview of Java CSCI 392 Day One. Running C code vs Java code C Source Code C Compiler Object File (machine code) Library Files Linker Executable File.
C++ (intro) Created by Hwansoo Han Edited by Ikjun Yeom.
The assignment expressions. The assignment operator in an assignment statement We have seen the assignment statement: Effect: var = expr; Stores the value.
Java and C++ Transitioning. A simple example public class HelloWorldApp { public static void main(String[] args) { //Display the string. System.out.println("Hello.
CSE 1341 Honors Note Set 2 1. Overview  Java vs. C++  Functions in C++  First Programming Packet  Development Environment 2.
CSc 201 Introduction to Java George Wells Room 007, Hamilton Building
Java FilesOops - Mistake Java lingoSyntax
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
3/5/2002e-business and Information Systems1 Java Java Java Virtual Machine (JVM) Java Application Program Interface (API) HW Kernel API Application Programs.
Java: Variables and Methods By Joshua Li Created for the allAboutJavaClasses wikispace.
Object Oriented Programming Lecture 2: BallWorld.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Reading Parameters CSCI 201 Principles of Software Development Jeffrey Miller, Ph.D.
STRUCTURED PROGRAMMING Complete C++ Program. Content 2  Main Function  Preprocessor directives  User comments  Escape characters  cout statement.
Java Methods and Applications CSIS 3701: Advanced Object Oriented Programming.
Introduction to programming in java
Introduction of Java Fikri Fadlillah, S.T.
C++ Lesson 1.
C++ First Steps.
Intro to ETEC Java.
BRIEF Overview ON THE MAJOR Similarities & Differences
Introduction to C++ Systems Programming.
Compiling and Running a Java Program
Computing Fundamentals
Internet and Java Foundations, Programming and Practice
Objectives Identify the built-in data types in C++
C++ in 90 minutes.
Lecture Note Set 1 Thursday 12-May-05
Intro to Java.
Java Intro III.1 (Fr Feb 23).
Programming Abstractions
An Introduction to Java – Part I, language basics
Pointers & Functions.
BRIEF Overview ON THE MAJOR Similarities & Differences
Java Intro.
Created by Hwansoo Han Edited by Ikjun Yeom
Introduction to Java Brief history of Java Sample Java Program
Multiple Files Revisited
Pointers & Functions.
Chap 1. Getting Started Objectives
F II 2. Simple Java Programs Objectives
An Introduction to STL.
Introduction to java Part I By Shenglan Zhang.
Chapter 2 part #1 C++ Program Structure
Presentation transcript:

Going from C++ to Java Jayden Navarro

Key Differences Harder to do easier things Easier to do harder things Printing to the screen (System.out.println();) Getting user input (BufferedReader or Scanner) Easier to do harder things Creating classes (No header files, prototyping) Compiling and running programs (javac mainfile.java)

Biggest General Differences No header files No namespaces No makefiles No pointers No need to reference other user’s class files (#include sample.h)

Biggest General Differences, cont. Automatic memory management No destructor Everything is contained in a class, including main Filename must be class name

Biggest Syntax Differences cout << “hello\n”; bool string cin >> var; Arrays (covered later) Java: System.out.println(“hello”); boolean String No short equivalent

Virtual Machine vs. Machine Specific Executable .class (bytecode) vs .exe (machine code)

How to Compile No Header files! No make file! Compile the main file and the rest of the files compile .class files are created for every .java file Use the command “javac ‘filename.java’”

How to Run Use the command “java ‘filename’” Don’t use .java at the end of the filename!

How to Create Objects ClassName objectName = new ClassName(Param1, Param2, etc.); CANNOT DO: ClassName objectName(Param1, Param2, etc.);

Arrays Size is permanent, just like in C++! Zero based, just like in C++! Can only use one data type per array, just like in C++! By default, arrays are filled with zeros or null values, in C++ they are undefined

int[] a = new int[5]; int test = a[3]; a[3] = 54; size == 5 Indices: 0 to 4 test == 0;

int[] b = {34, 4, 7}; int num = b[1]; size == 3 Indices: 0 to 2 num == 4

int[] c; c = new int[8]; size == 8 Indices: 0 to 7

Note placement of first brackets! C++: int a[5]; Java: int[] a = new int[5];

ArrayLists instead of Vectors Creating ArrayLists ArrayList<String> IA = new ArrayList<String>(); Inserting data SA.add(“hi”); Accessing data String s = SA.get(INDEX);

ArrayLists<Integer> example Must use ‘Integer’ or ‘Character’, etc. Creating ArrayLists ArrayList<Integer> IA = new ArrayList<Integer>(); Inserting data IA.add(54); Accessing data int num = IA.get(INDEX);

How to get user input import java.io.BufferedReader; import java.io.InputStreamReader; BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); String theString = input.readLine();

Hello World: C++ #include <iostream> using namespace std; int main() { cout << "Hello, world!\n"; }

Hello World: Java public class HelloWorld { public static void main(String[] args) { System.out.println(“Hello World!”); } Note bracket styling differences!

Helpful Links Google it! Wikipedia: Java vs. C++ Java API overview Stack Overflow: Yahoo Answers for Programmers Google it!

Thank You!