JAVA An overview for C++ programmers

Similar documents
Introduction to Java. Lecture 1 COP 3252 Summer May 16, 2017

Chapter 1 GETTING STARTED. SYS-ED/ Computer Education Techniques, Inc.

Assumptions. History

Objective-C. Stanford CS193p Fall 2013

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

Chapter 1 INTRODUCTION SYS-ED/ COMPUTER EDUCATION TECHNIQUES, INC.

CS321 Languages and Compiler Design I. Winter 2012 Lecture 2

Introduction to Java Programming

D Programming Language

The Java Programming Language

Page 1. Human-computer interaction. Lecture 1b: Design & Implementation. Building user interfaces. Mental & implementation models

Sample Copy. Not for Distribution.

Operating Systems CMPSCI 377, Lec 2 Intro to C/C++ Prashant Shenoy University of Massachusetts Amherst

6. Pointers, Structs, and Arrays. March 14 & 15, 2011

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

September 10,

From C++ to Java. Duke CPS

Selected Java Topics

Crash Course in Java. Why Java? Java notes for C++ programmers. Network Programming in Java is very different than in C/C++

Stanford CS193p. Developing Applications for ios Fall Stanford CS193p. Fall 2013

Agenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java

CS121/IS223. Object Reference Variables. Dr Olly Gotel

Chapter 1 Getting Started

CSE 303: Concepts and Tools for Software Development

Introduction to Java

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

Java Internals. Frank Yellin Tim Lindholm JavaSoft

Kickstart Intro to Java Part I

6. Pointers, Structs, and Arrays. 1. Juli 2011

QUIZ. What is wrong with this code that uses default arguments?

OOSD. Introduction to JAVA. Giuseppe Lipari Scuola Superiore Sant Anna Pisa. September 29, 2010

Java: framework overview and in-the-small features

2 rd class Department of Programming. OOP with Java Programming

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

OOSD. Introduction to JAVA. Giuseppe Lipari Scuola Superiore Sant Anna Pisa. September 12, 2011

SYLLABUS JAVA COURSE DETAILS. DURATION: 60 Hours. With Live Hands-on Sessions J P I N F O T E C H

CS1102: What is a Programming Language?

Binghamton University. CS-211 Fall Object Orientation

377 Student Guide to C++

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given

Introduce C# as Object Oriented programming language. Explain, tokens,

CS 11 java track: lecture 1

CSC207H: Software Design. Java + OOP. CSC207 Winter 2018

Core Java Syllabus. Pre-requisite / Target Audience: C language skills (Good to Have)

Advanced Object-Oriented Programming Introduction to OOP and Java

CLI and CLR. Antonio Cisternino Giuseppe Attardi

These are notes for the third lecture; if statements and loops.

NOOTAN PADIA ASSIST. PROF. MEFGI, RAJKOT.

Structure of this course. C and C++ Past Exam Questions. Text books

Programming. Syntax and Semantics

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

Special Topics: Programming Languages

G Programming Languages - Fall 2012

CS3157: Advanced Programming. Outline

A brief introduction to C programming for Java programmers

COSC 2P95. Procedural Abstraction. Week 3. Brock University. Brock University (Week 3) Procedural Abstraction 1 / 26

Core JAVA Training Syllabus FEE: RS. 8000/-

CPS 506 Comparative Programming Languages. Programming Language

History Introduction to Java Characteristics of Java Data types

CSC207H: Software Design. Java + OOP. CSC207 Winter 2018

CPSC 3740 Programming Languages University of Lethbridge. Data Types

Object-Oriented Software Engineering Practical Software Development using UML and Java. Chapter 2: Review of Object Orientation

QUIZ Friends class Y;

Final-Term Papers Solved MCQS with Reference

G Programming Languages - Fall 2012

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures

CS1004: Intro to CS in Java, Spring 2005

Kakadu and Java. David Taubman, UNSW June 3, 2003

Introduction to Programming (Java) 2/12

Business and Scientific Applications of the Java Programming Language

CS558 Programming Languages

(heavily based on last year s notes (Andrew Moore) with thanks to Alastair R. Beresford. 1. Types Variables Expressions & Statements 2/23

Name, Scope, and Binding. Outline [1]

Object-Oriented Software Engineering. Chapter 2: Review of Object Orientation

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++

Forth Meets Smalltalk. A Presentation to SVFIG October 23, 2010 by Douglas B. Hoffman

C++: Const Function Overloading Constructors and Destructors Enumerations Assertions

GDB Tutorial. A Walkthrough with Examples. CMSC Spring Last modified March 22, GDB Tutorial

Variables and Java vs C++

CS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley.

Java Programming. Zheng-Liang Lu. Java 301 Summer Department of Computer Science & Information Engineering National Taiwan University

CSE P 501 Compilers. Java Implementation JVMs, JITs &c Hal Perkins Winter /11/ Hal Perkins & UW CSE V-1

Software Development & Education Center. Java Platform, Standard Edition 7 (JSE 7)

VARIABLES AND TYPES CITS1001

CS558 Programming Languages Winter 2018 Lecture 4a. Andrew Tolmach Portland State University

Derived and abstract data types. TDT4205 Lecture 15

Civil Engineering Computation

Outline. Object Oriented Programming. Course goals. Staff. Course resources. Assignments. Course organization Introduction Java overview Autumn 2003

The issues. Programming in C++ Common storage modes. Static storage in C++ Session 8 Memory Management

CHAPTER 1. Introduction to JAVA Programming

Pointers in C/C++ 1 Memory Addresses 2

Chapter 10 :: Data Abstraction and Object Orientation

Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types. Record Types. Pointer and Reference Types

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

AP Computer Science A: Java Programming

Short Notes of CS201

Praktische Softwaretechnologie

Programming in C and C++

CISC 124: Introduction To Computing Science II

Transcription:

JAVA An overview for C++ programmers Wagner Truppel wagner@cs.ucr.edu edu March 1st, 2004 The early history James Gosling, Sun Microsystems Not the usual start for a prog.. language Consumer electronics, 1991 Mosaic and the Internet, 1994 The revolution: applets,, 1995 Since then, many improvements and additions have been made to the language http://java.sun.com/features/1998/05/birthday.html Java for C++ programmers 2 Why is Java so appealing? Platform independent Safe Easy to learn Powerful, well-documented, and easy-to-use libraries to perform many complicated tasks During this presentation, we ll look into each of these qualities, and more Comparison to C++ Hands-on activities Java for C++ programmers 3 1

Platform independence Sun s s motto for Java: write once, run anywhere It s s a great idea, but how s s it done? what are the drawbacks? Java for C++ programmers 4 Platform independence Java for C++ programmers 5 Platform independence Wait so does it mean that Java is an interpreted language? Yes, source is compiled into bytecodes. Aren t t interpreted languages inherently slower than compiled ones? Yes. Why you should not care so much, though: Java trades speed for platform independence safety (more on this later) Java compilers are pretty darn good anyway Still, if you re really worried about speed, you may always use the so-called just-in-time (JIT)) compilers. Java for C++ programmers 6 2

Safe and easy to learn The first thing to note here is that these are relative terms In this talk, we ll compare Java and C++ The general consensus is that Java is easier to learn and use than C++, but I ll I let you be the judge of that. Is Java safer than C++? Java for C++ programmers 7 Safer than C++? What do we mean by safe anyway? Less prone to programmer mistakes Java achieves better safety than C++ by providing sandboxes (won t t talk much about them here) checking every array access for out-of-bounds errors eliminating direct access to pointer operations automatically reclaiming any (heap) memory space not in use (automatic( garbage collection) having a less fragile approach to multiple inheritance making every function virtual providing, generally speaking, a simpler syntax than C++ Java for C++ programmers 8 No pointers? Some people claim that Java has no pointers Not true! All objects are accessed through references, which are automatically de-referenced pointers However, the pointer nature of these references is hidden from the programmer. Why? Reduced number of pointer-related errors Java for C++ programmers 9 3

Automatic garbage collection Objects are always allocated in the heap,, using new,, as in Foo f = new Foo(); f itself is always allocated in the stack the object referenced by f is allocated in the heap recall that memory allocation in C++ is not so simple Java keeps track of how many valid references exist for each object when an object has no more references to it, the memory space it occupies in the heap gets reclaimed No, it doesn t t mean that you may be sloppy Automatic garbage collection has pros and cons Pro: prevents many common memory allocation bugs Con: has a negative impact on your program s s efficiency Java for C++ programmers 10 No multiple inheritance? C++ inheritance forces the inheritance of both data and behavior (code) That s s a very fragile approach in order to inherit some behavior your class may have to gain some data as well, even if it s s not really needed Java solves that problem and at the same time eliminates the need for multiple inheritance by defining something called an interface Interfaces only define the expected behavior of a set of functions, like a contract no data and no implementation A class may implement as many interfaces as needed Of course, regular inheritance between classes is still allowed, but a class may inherit from only one other class - no multiple class inheritance in Java Java for C++ programmers 11 Functions are always virtual All (non-static) functions in Java follow a late- binding process Which function code is actually executed depends on the actual run-time type of the object on which the function is being called, not on the object s s declared type at compile time In C++, unless one declares a function to be virtual, the code to be executed is decided at compile time Thus, in Java, all (non-static) functions are virtual Late-binding is a little slower but prevents common hard-to-find bugs Java for C++ programmers 12 4

Other differences between Java & C++ (Almost) everything is an object Only primitive types (boolean( boolean, char, int, long, float, double) are not objects Function arguments are always passed by value Objects are not copied only their references are Neat solution to name collisions (package( packages) No separation between header and implementation No operator overloading No structs No generics (templates( templates) ) and no enums (constant enumerations) until Java 2, 1.5 Java for C++ programmers 13 A few other nice things about Java Inherently multi-threaded Threads are supported at the language level and are also objects Much nicer compiler and run-time error messages than C++ Exception handling is idiomatic every Sun- written library uses it and does so consistently Powerful and easy-to-use libraries for data structures, multi-threading, networking, I/O, graphics, GUI Java for C++ programmers 14 Other cool stuff Javadoc Auto-documenting your code Your comments are nicely formatted into a set of HTML pages C++ has something similar: Doxygen Swing Dynamically pluggable look-and-feel (plaf( plaf) Powerful, easy-to-use GUI toolkit Java for C++ programmers 15 5

Examples, please! Java for C++ programmers 16 Hot from the Sun Current release version: Java 2, 1.4.2 Java 2, version 1.5 beta is out Support for generics (templates( templates) Autoboxing Enhanced for loop Enumerated types Static import C-style formatted input/output Variable arguments and more http://java.sun.com/developer/technicalarticles technicalarticles/releases/j2se15/ Java for C++ programmers 17 References online The creators of Java http://www.java.sun.com/ The Java Developer Connection is a must. In particular, their Tech Tips free mailing list is awesome http://developer.java.sun.com/ A cool site to keep in touch with Java news http://www.ibiblio ibiblio.org/.org/javafaq/index.shtml This site's free subscription mailing lists are excellent http://www.javaworld javaworld.com/ Java for C++ programmers 18 6

References books I (basics) The Java Tutorial: A Short Course on the Basics Thinking in Java (http://www.( http://www.mindview.net/books/tij/.net/books/tij/) The JFC Swing Tutorial Java in a Nutshell Java Cookbook The Elements of Java Style Java for C++ programmers 19 References books II (intermediate) Practical Java Programming Language Guide Effective Java Programming Language Guide Java Pitfalls: Time-Saving Solutions and Workarounds to Improve Programs Design Patterns Java Workbook GoF s Design Patterns (C++) Java for C++ programmers 20 Questions? I d d like to thank all of you for coming (and staying!) Titus Winters and Dan Berger,, for organizing these talks and for inviting me to give this one Java for C++ programmers 21 7