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

Similar documents
An overview of Java, Data types and variables

Java Professional Certificate Day 1- Bridge Session

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

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

Programming. Syntax and Semantics

CS 11 java track: lecture 1

Introduction to 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

Java Applets. Last Time. Java Applets. Java Applets. First Java Applet. Java Applets. v We created our first Java application

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

Java Bytecode (binary file)

Program Fundamentals

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

Getting started with Java

CT 229. CT229 Lecture Notes. Labs. Tutorials. Lecture Notes. Programming II CT229. Objectives for CT229. IT Department NUI Galway

Lec 3. Compilers, Debugging, Hello World, and Variables

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

CS335 Graphics and Multimedia

Lecture 1: Overview of Java

COMP6700/2140 JDK Tools

2 rd class Department of Programming. OOP with Java Programming

CHAPTER 1. Introduction to JAVA Programming

Implementing a Web Server on OS/390: Part III Writing Common Gateway Interfaces and Installing Java Virtual Machine

Java language. Part 1. Java fundamentals. Yevhen Berkunskyi, NUoS

Chapter 1 Introduction to Java

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

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

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

CS 177 Recitation. Week 1 Intro to Java

Lesson 01 Introduction

Getting Started with Java. Atul Prakash


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

COT 3530: Data Structures. Giri Narasimhan. ECS 389; Phone: x3748

Software and Programming 1

Object Oriented Programming with JAVA UNIT - I

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School

CS 61C: Great Ideas in Computer Architecture Introduction to C

Introduction Basic elements of Java

Outline. Introduction to Java. What Is Java? History. Java 2 Platform. Java 2 Platform Standard Edition. Introduction Java 2 Platform

Tools : The Java Compiler. The Java Interpreter. The Java Debugger

Objectives. Problem Solving. Introduction. An overview of object-oriented concepts. Programming and programming languages An introduction to Java

1. What is Jav a? simple

Chapter 1: Introduction to Computers and Java

8/23/2014. Chapter Topics. Introduction. Java History. Why Program? Java Applications and Applets. Chapter 1: Introduction to Computers and Java

Programming with Java

Lecture 5 - NDK Integration (JNI)

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

Introduction Welcome! Before you start Course Assessments The course at a glance How to pass M257

CompSci 125 Lecture 02

Introduction to Java

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

Course Outline. Introduction to java

IT151: Introduction to Programming (java)

1 Introduction Java, the beginning Java Virtual Machine A First Program BlueJ Raspberry Pi...

Java Programming Language Mr.Rungrote Phonkam

Introduction To Java. Chapter 1. Origins of the Java Language. Origins of the Java Language. Objects and Methods. Origins of the Java Language

Tutorial 1 CSC 201. Java Programming Concepts عؾادئماظربجمةمبادؿكدامماجلاصا

Kickstart Intro to Java Part I

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

Chapter 1. Introduction to Computers and Java Objects. Background information. » important regardless of programming language. Introduction to Java

CS Week 2. Jim Williams, PhD

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

Computer Components. Software{ User Programs. Operating System. Hardware

Building Java Programs. Introduction to Programming and Simple Java Programs

Programming Language Concepts: Lecture 1

Pace University. Fundamental Concepts of CS121 1

Crash Course Review Only. Please use online Jasmit Singh 2

PROGRAMMING FUNDAMENTALS

An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a

1. Download the JDK 6, from

Software and Programming 1

Java Basic Programming Constructs

Algorithms and Programming I. Lecture#12 Spring 2015

Fundamentals of Programming. By Budditha Hettige

4 Programming Fundamentals. Introduction to Programming 1 1

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 9: Writing Java Applets. Introduction

13 th Windsor Regional Secondary School Computer Programming Competition

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Introduction to Programming Using Java (98-388)

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Advanced Computer Programming

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

3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)

For live Java EE training, please see training courses at

Chapter 1. Introduction

Higher National Diploma in Information Technology First Year, Second Semester Examination 2015

Java Foundations: Unit 3. Parts of a Java Program

Programming Language Basics

Inf1-OOP. Textbooks. Who and What. Organisational issues. Why Java? Course Overview. Hello, World! in Java

: Primitive data types Variables Operators if, if-else do-while, while, for. // // First Java Program. public class Hello {

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

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

At its simplest, a computer is a collection of wires, transistors and electrical components that are connected in a specific way When you send

CS 231 Data Structures and Algorithms, Fall 2016

Introduction to C An overview of the programming language C, syntax, data types and input/output

Course information. Petr Hnětynka 2/2 Zk/Z

Computer Components. Software{ User Programs. Operating System. Hardware

Transcription:

Goals Understand the basics of Java. Introduction to Java Write simple Java Programs. 1 2 Java - An Introduction Java is Compiled and Interpreted Java - The programming language from Sun Microsystems Programmer Hardware and Operating System Java -Allows anyone to publish a web page with Java code in it Java - CPU Independent language Source Code Byte Code Text Editor Compiler Interpreter.java file.class file Notepad, emacs,vi javac java appletviewer netscape 3 4 Compiled Languages Architecture Neutral & Portable Programmer Source Code Object Executable Code Code Text Editor Compiler linker.c file.o file a.out file Notepad, emacs,vi gcc Java Compiler - Java source code (file with extension.java) to bytecode (file with extension.class) Bytecode - an intermediate form, closer to machine representation A interpreter (virtual machine) on any target platform interprets the bytecode. 5 6

Architecture Neutral & Portable Porting the java system to any new platform involves writing an interpreter. The interpreter will figure out what the equivalent machine dependent code to run Java Integrates Power of Compiled Languages and Flexibility of Interpreted Languages 7 8 Rich Class Environment Applets v/s Applications Core Classes language Utilities Input/ Output Low-Level Networking Abstract Graphical User Interface Internet Classes TCP/ IP Networking WWW and HTML Distributed Programs Different ways to run a Java executable are: Application- A stand-alone program that can be invoked from command line. A program that has a main method Applet- A program embedded in a web page, to be run when the page is browsed. A program that contains no main method 9 10 Applets v/s Applications Java Development Kit Application Executed by the Java interpreter Applets- Java enabled web browser javac - The Java Compiler java - The Java Interpreter jdb- The Java Debugger appletviewer -Tool to run the applets javap - to print the Java bytecodes javaprof - Java profiler javadoc - documentation generator javah - creates C header files 11 12

Hello World Program Processing // HelloWorld.java: Hello World program class HelloWorld public static void main(string args[]) System.out.println( Hello World ); 13 Compilation # javac HelloWorld.java results in HelloWorld.class Execution # java HelloWorld Hello World 14 Closer Look at - Hello World Simple Java Applet The class has one method main() public static void main(string args[]) System.out.println( Hello World ); Command line input arguments are passed in the String array args[] e.g java HelloWorld John Jane args[0] John args[1] Jane // HelloWorld Applet import java.applet.applet; public class HelloWorld extends Applet public void paint(graphics g) g.drawstring ( Hello World!,25, 25); 15 16 Calling an Applet Execution of Applets <HTML> <TITLE>HELLO WORLD APPLET</TITLE> <HEAD>THE HELLO WORLD APPLET</HEAD> <APPLET CODE=HelloWorld.class width=500 height=500> </APPLET> </HTML> 1 2 3 4 5 Accessing from Microsoft.COM APPLET Development hello.java AT SUN.COM Hello Java hello.class AT SUN S WEB SERVER <app= Hello > Create Applet tag in HTML document The Internet The browser creates a new window and a new thread and then runs the code Hello 17 18

Variables Local Variables are declared within the block of code Variable has a type preceding the name Initial value is set by initialization expressions. type variablename = initialvalue; e.g. int lo = 1; Basic Data Types Types boolean either true of false char 16 bit Unicode 1.1 byte 8-bit integer (signed) short 16-bit integer (signed) int 32-bit integer (signed) long 64-bit integer (singed) float 32-bit floating point (IEEE 754-1985) double 64-bit floating point (IEEE 754-1985) String (class for manipulating strings) Java uses Unicode to represent characters internally 19 20 Declaring Variables - example Constants class SquaredNumbers public static void main(string args[]) int lo = 1; int squared = 0; while (squared <= 25) Constants are similar to variables except that they hold a fixed value. Constants are declared with the reserved word final. final int MAX_LENGTH = 420; By convention upper case letters are used for defining constants. 21 22 Declaring Constants - example Comments class SquaredNumbers public static void main(string args[]) final int MAX_NUMBER = 25; int lo = 1; int squared = 0; while (squared <= MAX_NUMBER) English text scattered through the code are comments JAVA supports 3 types of comments /* * / - Usually used from multi-line comments // - Used for single line comments /* * * / - Documentation comments 23 24

Javadoc Control Flow Effort to make Java self-documenting Control Flow Statements in JAVA while loop True OOP style, encapsulate documentation within code :) Comments beginning with /* * and ending with * / can be extracted and turned into html documentation for loop do-while loop if-else statement switch statement JAVA does not support a goto statement 25 26 while loop for loop while (squared <= MAX) for (int i = 1; i < MAX; i++) System.out.println(i); // prints 1 2 3 4 5 27 28 do-while loop if-else loop do while (squared <= MAX) if ( i < 10) System.out.println( i is less than 10 ); else System.out.println( i is greater than or equal to 10 ); 29 30

switch statement switch (c) case a : System.out.println ( The character is a ); break; case b ; System.out.println ( The character is b ); break; default; System.out.println ( The character is not a or b ); break; C HelloWorld - Revision # include < stdio.h> Int main() printf("hello World\ n"); 31 32 C Variables - Revision C Constant - Revision # include <stdio.h> int main() int i, squared; i = 0; squared = 0; while (squared < = 25) squared = i* i; printf("squared = %d\n",squared); i+ + ; # include <stdio.h> # define MAX_NUMBER 25 int main() int i, squared; i = 0; squared = 0; while (squared < = MAX_NUMBER) squared = i* i; printf("squared = %d\n",squared); i+ + ; 33 34