The Java programming environment. The Java programming environment. Java: A tiny intro. Java features

Similar documents
Goals. Java - An Introduction. Java is Compiled and Interpreted. Architecture Neutral & Portable. Compiled Languages. Introduction to Java

CS 11 java track: lecture 1

Kickstart Intro to Java Part I

Java Bytecode (binary file)

Learning objectives. The Java Environment. Java timeline (cont d) Java timeline. Understand the basic features of Java

Introduction to Java

Getting started with Java

Programming Language Concepts: Lecture 2

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

Programming. Syntax and Semantics

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

Introduction to Programming Using Java (98-388)

1. Download the JDK 6, from

Introduction to Java

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

Character Stream : It provides a convenient means for handling input and output of characters.

From C++ to Java. Duke CPS

An overview of Java, Data types and variables

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

Course Outline. Introduction to java

CS 231 Data Structures and Algorithms, Fall 2016

Full file at

Answer1. Features of Java

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

Lecture Set 4: More About Methods and More About Operators

Section 2.2 Your First Program in Java: Printing a Line of Text

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

1. Java is a... language. A. moderate typed B. strogly typed C. weakly typed D. none of these. Answer: B

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8

CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY JAVA

Index. Course Outline. Grading Policy. Lab Time Distribution. Important Instructions

Java Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing

History of Java. Java was originally developed by Sun Microsystems star:ng in This language was ini:ally called Oak Renamed Java in 1995

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

STRUCTURING OF PROGRAM

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

Java Language Basics: Introduction To Java, Basic Features, Java Virtual Machine Concepts, Primitive Data Type And Variables, Java Operators,

Introduction to Java

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Program Fundamentals

Java Basic Syntax. Java vs C++ Wojciech Frohmberg / OOP Laboratory. Poznan University of Technology

2 rd class Department of Programming. OOP with Java Programming

Assumptions. History

Atelier Java - J1. Marwan Burelle. EPITA Première Année Cycle Ingénieur.

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

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

1 Shyam sir JAVA Notes

Programming Language Basics

Computer Science is...

Introduction to Java

Lecture 1: Overview of Java

Lecture Set 4: More About Methods and More About Operators

Programming Language Concepts: Lecture 2

data_type variable_name = value; Here value is optional because in java, you can declare the variable first and then later assign the value to it.

CHAPTER 1. Introduction to JAVA Programming

CS/B.TECH/CSE(OLD)/SEM-6/CS-605/2012 OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

Special Topics: Programming Languages

Chapter 1 Introduction to Java

CS321 Languages and Compiler Design I. Winter 2012 Lecture 2

Operators and Expressions

Java Training JAVA. Introduction of Java

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days

GlobalLogic Technical Question Paper

Question. 1 Features of Java.

Chapters 1-4 Summary. Syntax - Java or C? Syntax - Java or C?

Lecture 2, September 4

Java Programming. Manuel Oriol, March 22nd, 2007

Selected Questions from by Nageshwara Rao

G52PGP. Lecture oo3 Java (A real object oriented language)

GO MOCK TEST GO MOCK TEST I

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University COPYRIGHTS 2017 EOM, HYEONSANG ALL RIGHTS RESERVED

A PROGRAM IS A SEQUENCE of instructions that a computer can execute to

Java Professional Certificate Day 1- Bridge Session

Sri Vidya College of Engineering & Technology

Introduction to Programming (Java) 2/12

Computational Applications in Nuclear Astrophysics using Java Java course Lecture 1

Chapter 6 Introduction to Defining Classes

Short Notes of CS201

CompSci 125 Lecture 02

Lecture 5 - NDK Integration (JNI)

CS201 - Introduction to Programming Glossary By

Introduction Basic elements of Java

Object-Oriented Programming

S.E. Sem. III [CMPN] Object Oriented Programming Methodology

CS2141 Software Development using C/C++ C++ Basics

PROGRAMMING FUNDAMENTALS

B2.52-R3: INTRODUCTION TO OBJECT ORIENTATED PROGRAMMING THROUGH JAVA

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

Chapter 2: Basic Elements of Java

CMSC131. Introduction to your Introduction to Java. Why Java?

Java Programming Language Mr.Rungrote Phonkam

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

1. [3 pts] What is your section number, the period your discussion meets, and the name of your discussion leader?

Java Basic Programming Constructs

1.1 Your First Program

Programming Language Concepts: Lecture 1

Transcription:

The Java programming environment Cleaned up version of C++: no header files, macros, pointers and references, unions, structures, operator overloading, virtual base classes, templates, etc. Object-orientation: Classes + Inheritance Distributed: RMI, Servlet, Distributed object programming. Robust: Strong typing + no pointer + garbage collection Secure: Type-safety + access control Architecture neutral: architecture neutral representation Portable Interpreted High performance through Just in time compilation + runtime modification of code Multi-threaded Dynamic The Java programming environment Java programming language specification Syntax of Java programs Defines different constructs and their semantics Java byte code: Intermediate representation for Java programs Java compiler: Transform Java programs into Java byte code Java interpreter: Read programs written in Java byte code and execute them Java virtual machine: Runtime system that provides various services to running programs Java programming environment: Set of libraries that provide services such as GUI, data structures,etc. Java enabled browsers: Browsers that include a JVM + ability to load programs from remote hosts Java features Names and scopes Simple data types: integers, floats, char, strings Control statements: if-then-else, switch, while, for Classes and objects Inheritance Interfaces Exceptions Concurrency Packages Name spaces Reflection Applet model Java: A tiny intro How are Java programs written? How are variables declared? How are expressions specified? How are control structures defined? How to define simple methods? What are classes and objects? What about exceptions? What about concurrency? 1

How are Java programs written? Define a class HelloWorld and store it into a file: HelloWorld.java: class HelloWorld { public static void main (String[] args) { System.out.println( Hello, World ); Compile HelloWorld.java Javac HelloWorld.java Output: HelloWorld.class Run Java HelloWorld Output: Hello, World How are variables declared? Fibonacci: class Fibonacci { public static void main(string[] arg) { int lo = 1; int hi = 1; System.out.println(lo); while (hi < 50) { System.out.println(hi); hi = lo + hi; lo = hi lo; How to define expressions? Arithmetic: +, -, *,/, %, = 8 + 3 * 2 /4 Use standard precedence and associativity rules Predicates: ==,!=, >, <, >=, <= public static void main (String[] argv) { boolean b; b = (2 + 2 == 4); System.out.println(b); How are simple methods defined? Every method is defined inside a Java class definition public class Movie { public static int movierating(int s, int a, int d) { return s+a+d; public static void main (String argv[]) { int script = 6; acting = 9; directing = 8; displayrating(script, acting, directing); public static void displayrating(int s, int a, int d) { System.out.print( The rating of this movie is ); System.out.println(Movie.movieRating(s, a, d); 2

How are control structures specified? Typical flow of control statements: if-then-else, while, switch, dowhile, and blocks class ImprovedFibo { static final int MAX_INDEX = 10; public static void main (String[] args) { int lo = 1; int hi = 1; for (int I = 2; I < MAX_INDEX; I++) { if (I %2 = 0) mark = * ; else mark = ; System.out.println(I+ : + hi + mark); hi = lo + hi; lo = hi lo; What are classes and objects? Classes: templates for constructing instances Fields Instance variables Static variables Methods Instance Static class Point { public double x, y; Point lowerleft = new Point(); Point upperright = new Point(); Point middlepoint = new Point(); lowerleft.x = 0.0; lowerleft = 0.0; upperright.x = 1280.0; upperright.y = 1024.0 middlepoint.x = 640.0; middlepoint.y = 512.0 How are instance methods defined? Instance methods take an implicit parameter: instance on which method is invoked public class Movie { public int script, acting, directing; public int rating() { return script + acting + directing; public static void main (String argv[]) { Movie m = new Movie(); m.script = 6; m.acting = 9; m.directing = 8; System.out.print( The rating of this movie is ); System.out.println(m.rating()); How to extend classes? Inheritance: mechanism for extending behavior of classes; leads to construction of hierarchy of classes (More detail in class) What happens when class C extends class D: Inherits instance variables Inherits static variables Inherits instance methods Inherits static methods C can: Add new instance variables Add new methods (static and dynamic) Modify methods (only implementation) Cannot delete anything 3

How to extend classes? public class Attraction { public int minutes; public Attraction() {minutes = 75; public getminutes() {return minutes; public setminutes(int d) {minutes = d; public class Movie extends Attraction { public int script, acting, directing; public int Movie() {script = 5; acting = 5; directing = 5; public int Movie(int s, a, d) { script = s; acting = a; directing = d; public int Rating() {return script + acting + directing; public class Symphony extends Attraction { public int playing, music, conducting; public int symphony() {playing = music = conducting = 5; public int symphony(int p, m, c) { playing = p; music = m; conducting = c; public int rating() {return playing + music + conducting; What are abstract classes? Abstract class: Merely a place holder for class definitions; cannot be used to create instances.; public abstract class Attraction { public int minutes; public Attraction() {minutes = 75; public getminutes() {return minutes; public setminutes(int d) {minutes = d; Following is an error: Attraction x; x = new Attraction(); Following is not an error: public class Movie extends Attraction { public class Symphony extends Attraction { Attraction x; x = new Movie (); x = new Symphony(); Packages Object Attraction Auxiliaries Demonstration Movie extends extends Symphony How do organize above classes into a single unit? Put them in file? However, only one public class/file (whose name is same as that of file) Solution: Place several files (compilation units) into a package Packages cont d. units of organizing related Classes, Interfaces, Sub packages Why? Reduce name clashing Limit visibility of names Java programs typically organized in terms of packages and subpackages Each package may then be divided into several packages, subpackages, and classes Each class can then be stored in a separate file Each source file starts with something like: package mypackage Code in source file is now part of mypackage 4

Packages cont d. public abstract class Attraction { public class Movie extends class Attraction { import java.io.*; import java.util.*; public class Auxiliaries { Where to store packages? How does Java find packages? Export and Import Access control 5