CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 3 Writing Java Applications, Java Development Tools.
Advertisements

Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
Introduction to C Programming CE Lecture 1 Introduction to C.
1 Java Basics. 2 Compiling A “compiler” is a program that translates from one language to another Typically from easy-to-read to fast-to-run e.g. from.
Introduction to Object- Oriented Programming with Java Spring Semester 2003 Paul Krause.
Introduction to Java Programming
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
Outline Java program structure Basic program elements
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
Session 1 CS-240 Data Structures Binghamton University Dick Steflik.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Introduction to Java CS 331. Introduction Present the syntax of Java Introduce the Java API Demonstrate how to build –stand-alone Java programs –Java.
Guide To UNIX Using Linux Third Edition
Introduction to Java Programming Language Junji Zhi University of Toronto 1.
Java CourseWinter 2009/10. Introduction Object oriented, imperative programming language. Developed: Inspired by C++ programming language.
CMSC 341 Introduction to Java Based on tutorial by Rebecca Hasti at
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
Programming in Java; Instructor:Moorthy Introduction, Objects, Classes, Libraries1 Programming in Java Introduction.
CSC3170 Introduction to Database Systems
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
High-Level Programming Languages: C++
An intro to programming. The purpose of writing a program is to solve a problem or take advantage of an opportunity Consists of multiple steps:  Understanding.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
By Noorez Kassam Welcome to JNI. Why use JNI ? 1. You already have significantly large and tricky code written in another language and you would rather.
1 Comp 104: Operating Systems Concepts Java Development and Run-Time Store Organisation.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and Server Side Programming Very rich GUI libraries Portability (machine independence) A.
The Java Programming Language
CSC Java Programming, Fall, 2008 Week 2: Java Data Types, Control Constructs, and their C++ counterparts, September 4.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
POS 406 Java Technology And Beginning Java Code
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
CSE 131 Computer Science 1 Module 1: (basics of Java)
CS591x A very brief introduction to Java. Java Developed by Sun Microsystems was intended a language for embedded applications became a general purpose.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
Java Programming Presented by Daniel Rosenthal Friday, November 30 th, 2007.
Introduction to java Prepared By:-Pragnesh Patel Lect. In Computer Dept. NSIT,Jetalpur 1.
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.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
1 Introduction to Java. 2 What is Java? A programming language. A platform –A virtual machine (JVM) definition. –Runtime environments in diverse hardware.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Object Oriented Software Development 4. C# data types, objects and references.
CSE 1341 Honors Note Set 2 1. Overview  Java vs. C++  Functions in C++  First Programming Packet  Development Environment 2.
By Mr. Muhammad Pervez Akhtar
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Duke CPS From C++ to Java l Java history: Oak, toaster-ovens, internet language, panacea l What it is ä O-O language, not a hybrid (cf. C++)
Classes, Interfaces and Packages
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
An Introduction to Java – Part 1 Erin Hamalainen CS 265 Sec 001 October 20, 2010.
OOP Basics Classes & Methods (c) IDMS/SQL News
C is a high level language (HLL)
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
RealTimeSystems Lab Jong-Koo, Lim
Object Oriented Programming Lecture 2: BallWorld.
Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
CS-140 Dick Steflik Lecture 3. Java C++ Interpreted optimized for the internet Runs on virtual ized machine Derived from C++ Good object model Widely.
JAVA MULTIPLE CHOICE QUESTION.
Intro to ETEC Java.
Internet and Java Foundations, Programming and Practice
C Basics.
Programming Language Concepts (CIS 635)
An Introduction to Java – Part I
Java Programming Language
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Presentation transcript:

CS-341 Dick Steflik Introduction

C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining new types (classes) provides symbolic constants provides inline substitution of functions allows default function arguments allows function name overloading allows operator overloading operators for managing free storage provides a reference type

C++ Usage procedural programming - a better version of C –cleaner handling of arrays as function parameters –stream based I/O model object oriented programming –encourages reuse of already tested code rather than inventing a problem solution over and over –encourages data abstraction –encourages data hiding

The C++ Compiler Translates C++ source code into the machine language for the hardware platform –output of the compiler are object files (.obj) which are partially ready to run –object files must be linked together using the system linker to make an executable file (.exe).exe files are specific for the hardware platform C++ is portable only at the source level

C++ Compilers GNU C++ –Open Source –Multi-platform Windows UNIX (most) LINUX MAC Microsoft Visual C++ –includes everything needed to program the Windows API

This semester... All programs submitted must be able to run on the Sun Blade workstations in Classroom 2 of the POD. –This can be insured by using the GNU gpp Compiler you may develop on the Sun Blade Workstations, on LINUX (gpp comes with all standard LINUX installs) or on CYGWIN/XEMACS (a emulated UNIX environment that runs on Windows, a CD will be made available or you may download and install from the internet.) Those of you that have Windows machines, I encoutage to install CYGWIN/EMACS Those of you with Windows machines that are more daring I encourage you to make the leap to LINUX You may also telnet into BINGSUNS and use GPP directly in that environment

Java C++ Interpreted optimized for the internet Derived from C++ Good object model Widely accepted as the internet programming language 4-5 years old Compiled optimized for workstation usage derived from C Poorer object model Widely accepted as workstation program- ming language years old

The Java Compiler Translates Java source code into java bytecodes –java bytecodes are the machine language for the Java Virtual Machine the JVM is a hypothetical machine that written mostly in Java but a little bit in C++ and is compiled specifically for various platforms (Windows, Sun, HP, LINUX) Bytecodes are portable between platforms

Java Application Development Java Source File javac Java Class File JVM classpath base classes Compile into bytecodes Run the program

The C++ Compiler Translates C++ source code into the machine language for the hardware platform –output of the compiler are object files (.obj) which are partially ready to run –object files must be linked together using the system linker to make an executable file (.exe).exe files are specific for the hardware platform C++ is portable only at the source level

C++ application development C++ Source File compiler C++ Include Files Object File Linker System Object Files.EXE File

Java import statements imports indicate which parts of which java packages an application will need at run time –also allows the compiler to run to completion and not indicate that the class isn’t part of the file being compiles Remember the compiler only works with the file being compiled

C++ include statements indicate to the compiler preprocessor which files (source) to include in the file to be compiled. Included files are actually copied into the source file and replace the #include statement as part of precompilation. #include “myclass.h” #include #include “fully qualified file name ”

Java application is defined as a class that is instantiated when the program is run main() is the name of the function to be run initially constructor is used initialize the class

C++ application classes are/can be used by a C++ application; but the application is not itself an instantiated class (like Java) main() is the name of the function where the executable file starts execution C++ classes do not have main() functions C++ objects are initialized via class constructors, C++ applications are initialized in the main() function.

Java - HelloWorld public class HelloWorld { public static void main(String args[]) { System.out.println(“Hellow World”); }

C++ - HelloWorld #include int main() { cout << “Hello World” << “\n”; }

Data Types

Primitive Types Integer types –char : 8 bit –short : 16 bit –nit : 32 bit –long : 64 bit Real Types –float - 32 bit real numbers –double - 64 bit real numbers

Constants In C++ constants are similar to variables but are never allowed to be the target of an assignment (explicit or implicit) In C++ constants are defined as: –const int abc = 100 ; const char plus = ‘+’;

Strings C++ has no native built-in String type Strings are implemented as null terminated arrays of characters, last character of the string is a null character (‘\0’\) char [3] abc = “me” –array abc consists of “m”, “e”, null abc = “me” (shortcut for defining and initializing a string) string functions are in

Boolean (false/true) C++ has no boolean type like Java – the value 0 represents false – any other value represents true the statement “if (50) cout <<“t”; – will always print “t” as 50 is not 0 so the predicate is true the statement “if (5-5) cout<<“t”; else cout << “f” ; –will always print “f” as (5-5) is 0 (i.e. False)

Derived Types These operators create new types from the basic types –*pointer to –*constconstant pointer –&reference to (addressing operator) –[ ]vector of –()function returning

Null statements the simplest statement is the null statement ; useful if the syntax requires a statement for instance to introduce a time delay into a program: –for (int j = 0 ; j < 100 ; j++) {;}

Function Parameters pass by value (default): upon invoking the function the function creates a local copy of the parameter and copies the value to the copy. int foo (int a, int b) { … } int x = 5 ; int y = 7; int b = foo(a, b); x=5 y=7 foo a = 5 b = 5 This gives the effect of x and y being input only as the function can’t change them.

Function Parameters pass by reference: passes a reference to the parameter to the function, the function works with the reference. The function can both read from and write to the argument. Internal to the function the name in the definition is used as an alias for the argument use the & operator to indicate “pass by reference int foo(int &a, int & b) {….} int x=5 ; int y = 7; int t = foo(x,y);

Arrays Array definition is the same: ex. int myarray[5]; when used with a function the syntax is different, to pass an array to a function you no longer need to pass a pointer to the array, just pass the array name. int sum(int cnt, int [ ] m){ int t = 0; for (int i=0 ; i<cnt ; i++) t = t + m[i]; return t } int x = sum(5,myarray);

Array passing always pass by reference (default method)