Introduction to Java Tavaris J. Thomas Ph.D. BNAI ZION SCIENTISTS DIVISION JOB ORIENTATION & TERMINOLOGY CLASSES Fall 2012.

Slides:



Advertisements
Similar presentations
Introduction to Programming G51PRG University of Nottingham Revision 1
Advertisements

CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Lab Information Security Using Java (Review) Lab#0 Omaima Al-Matrafi.
Object Oriented Programming in JAVA
Lab#1 (14/3/1431h) Introduction To java programming cs425
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
Object Orientated Programming
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.
Shlomo Hershkop1 Introduction to java Class 1 Fall 2003 Shlomo Hershkop.
Introduction to Java Kiyeol Ryu Java Programming Language.
Introduction to Java Programming Language Junji Zhi University of Toronto 1.
L EC. 01: J AVA FUNDAMENTALS Fall Java Programming.
01 Introduction to Java Technology. 2 Contents History of Java What is Java? Java Platforms Java Virtual Machine (JVM) Java Development Kit (JDK) Benefits.
CMSC 341 Introduction to Java Based on tutorial by Rebecca Hasti at
BASIC JAVA PROGRAMMING TUTORIAL. History  James Gosling and Sun Microsystems  Oak  Java, May 20, 1995, Sun World  Hot Java –The first Java-enabled.
S.W. Ma/CIM/LWL41211/2 Prog. IIA Page 1 HKIVE (Lee Wai Lee Campus) Department of CIM Course : Year 2 Module : Programming IIA Textbook : Introduction.
Lecturer PEN PHIROM Tel : Web site: Lecturer PEN PHIROM Tel :
Sadegh Aliakbary Sharif University of Technology Spring 2011.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
CMSC 202 Computer Science II for Majors Object-Oriented Programming.
Java Introduction Lecture 1. Java Powerful, object-oriented language Free SDK and many resources at
Introduction to Java CSIS 3701: Advanced Object Oriented Programming.
INTRODUCTION TO JAVA CHAPTER 1 1. WHAT IS JAVA ? Java is a programming language and computing platform first released by Sun Microsystems in The.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
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
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Basic Java Syntax CSE301 University of Sunderland Harry R Erwin, PhD.
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
Chapter 1: Introduction to Programs, and Java 1. Objectives To review programs (§ ). To understand the relationship between Java and the World Wide.
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
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.
Spring 09- ICE0124 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 2.
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.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.
1 Programming Java Java Basics. 2 Java Program Java Application Program Application Program written in general programming language Applet Program running.
Fall 2015CISC124 - Prof. McLeod1 CISC124 Have you filled out the lab section survey? (As of last night 54 left to fill out the survey.) TA names have been.
Applied Computing Technology Laboratory QuickStart Java Learning to Program in Java Dr. Tom Way October 21, 2005.
JAVA Programming “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Today… “Hello World” ritual. Brief History of Java & How Java Works. Introduction to Java class structure. But first, next slide shows Java is No. 1 programming.
introductory lecture on java programming
Java Computer Industry Lab. 1 Programming Java Java Basics Incheon Paik.
ITP 109 Week 2 Trina Gregory Introduction to Java.
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.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
Introduction to JAVA Programming
Object Oriented Programming Lecture 2: BallWorld.
Introduction to Java Programming, 4E Y. Daniel Liang.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
CMSC 202 Computer Science II for Majors Fall 2010 Introduction Version 9/101.
Introduction CMSC 202 Fall Instructors Mr. Ryan Bergeron – Lecture Section 01 Tues/Thu 1:00 – 2:15 am, Sondheim 111 – Lecture Section 04 Tues/Thu.
Object Oriented Programming in
GC101 Introduction to computer and program
Chapter 1 Introduction to Computers, Programs, and Java
Chapter No. : 1 Introduction to Java.
Internet and Java Foundations, Programming and Practice
Data types and variables
Introduction to Programming in Java
Advanced Programming Fall 2017.
Units with – James tedder
Units with – James tedder
(Computer fundamental Lab)
Computer Programming-1 CSC 111
Review of Java Fundamentals
Outcome of the Lecture Upon completion of this lecture you will be able to understand Fundamentals and Characteristics of Java Language Basic Terminology.
Presentation transcript:

Introduction to Java Tavaris J. Thomas Ph.D. BNAI ZION SCIENTISTS DIVISION JOB ORIENTATION & TERMINOLOGY CLASSES Fall 2012

Contact Info Tavaris J. Thomas – – Google Group –

Any Programming Experience?

Class Logistics Lectures will run every Tues 6:00pm – 9:00pm The Cooper Union Microlab 602 Approx 4+ programming assignments. Class Lectures will be available on the class group page or on the class webpage Textbook: – Core Java,Volume 1 – Fundamentals (8 th edition) – Cay S. Horstmann and Gary Cornel – ISBN:

Course Topics Introduction to Java Fundamentals Objects and Classes Inheritance Interfaces and Inner Classes Deploying Applications Debugging and Exceptions Multithreading

Week 1 Introduction What is Java? Installing the Java SDK and Eclipse IDE Language Fundamentals

History of Java Began as a Sun Microsystems project called “Green” James Gosling Intended to be used on a variety of architectures All code is translated to the same “Virtual Machine” code, and specific interpreters are written for the VM Chose to make it object-oriented like C++ instead of like Pascal First commercial application: applets (1995)

Java’s Evolution Java 1.0 First release Java 1.1 Inner classes Java (no additions) Java 1.4 Assertions Java 5.0 [“1.5”] Generic classes, for each loops, variable arguments, autoboxing, metadata, enums, static import Java 6 Performance improvements, library enhancements update 37 Java 7 More security and library enhancements – update 9 Java 8 TDA September 2013

Versions of Java Java SE – Standard Edition Java ME – Micro Edition – embedded devices or resource constrained devices – set top boxes, blu-ray players, mobile devices Java EE – Enterprise Edition – For server side processing

Uses of Java “Write Once, Run Anywhere” – Stand alone applications – Applets (java code embedded into webpages run via we browser) – Servlets (server side Java code that interact with clients typically using HTTP) Android development

Programming Languages Interpreted languages – Perl – Python – PHP Compiled languages – BASIC – C/C++ – Fortran – Java (to bytecode)

JVM Approach Architecture neutral – Only need an implementation of JVM for the native machine – Same Java code will run on all platforms Portable – The results on x86 = results on ARM = results on PPC – Caveat: don’t always fully utilize architecture capabilities Object oriented – Everything is a class Doesn’t this all mean Java is slow? – On average: slower than compiled languages – But, using just-in-time (JIT) compiler Java is fast!

Grabbing Java and Eclipse 1.Go to wnloads/index.html wnloads/index.html 2.Download Java SE 6 Update 37 JDK (includes the JRE) 3.Install the JDK 4.Install the JRE 5.Download Eclipse from: java-developers/heliossr2 6.Continue with installing Eclipse IDE

Hello World Example Simplest possible program: prints one line Will re-visit this program later public class HiWorld { public static void main(String[] args) { System.out.println(“Hello World“); }

Another Example Uses an array of three strings and a loop public class Greetings { public static void main(String[] args) { String[] greeting = new String[3]; greeting[0] = "Welcome to BNAI ZION"; greeting[1] = “Introduction to Java"; greeting[2] = “Spring 2012 "; for(String thisline : greeting) System.out.println(thisline); }

“Hello World” In-depth public class HiWorld { public static void main(String[] args) { // this is a comment. /* so is this, but the following is a statement: */ System.out.println(“Hello World“); } Java is case sensitive public is an access modifier Controls level of access other part of program have to this code Everything in Java is a class – used to create building blocks System.out is an object, calling its println method with parameter “Hello World”

Class Class is a container for the program logic that defines the behavior of an application Building blocks with which all Java applications and applets are built. Everything in a Java program must be inside a class. Following the keyword class is the name of the class. Names must begin with a letter, and after that, they can have any combination of letters and digits.

Simple Template with Javadoc /** * This is a simple template, documented Your Name */ public class ClassName{ public static void main(String[] args){ program statements; }

The 8 Primitive Data Types in Java

Variables For any meaningful program you need to modify data Variables are used to store values Operators operate on one or two variables – Forming expressions Declare a variable called Name of type type: – type Name; – Example: String name; int a, b; Assigning Name a value val: – type Name=val; – Example: String name=“Don Knuth”; int a=3; float k=3.3;

Integer Types Range depends on size of each type: – long (8 bytes) -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 – int (4 bytes) -2,147,483,648 to 2,147,483,647 – short (2 bytes) -32,768 to 32,767 – byte (1 byte) -128 to 127 All integer types are signed (the unsigned keyword does not exist in Java) All integer types are the same size regardless of the device’s architecture

Representing Floating Point Used for positive and negative numbers with fractional parts – Range and precision both depend on type – float (4 bytes) ± *1038 – double (8 bytes) ± *10308 Float stores up to 7 fractional digits Double stores 15 decimal digits – In general, doubles should be used instead of Float – If speed or memory are constrained, floats may be necessary

Representing Characters Unlike C, where char is almost always a single byte, a Java char can hold a multi-byte Unicode character Every char is 16 bits (2 bytes), and stores either a complete character of Unicode U+0000 to U+FFFF or half of a U to U+10FFFF character In most cases, String variable should be used to avoid having to worry about character types and lengths. – String pi = "\u03C0”; //π

Boolean Types Can only indicate two values, true or false Unlike C/C++, integer 0 and 1 are not equivalent to false and true Avoid easy-to-create bugs. For example: if((x=1)) { statement; } //this would not compile in Java Must use true and false when assigning boolean variables No implicit conversion is possible between boolean and other data types

Strings Java does NOT have a built-in string type Standard library contains class called String Every quoted string is an instance of this class Java strings are sequence of Unicode characters – Example: “Java\u2122” consists of: J,a,v,a,™ – Example: String e = “”; //an empty string – String planet = “Earth”; More later with String API

Enumerated Types Sometimes variable should only hold a value from specific (restricted) set Example: Shirt size allowed to be small, medium, large – You can, of course do: – int SMALL=1; – int MEDIUM=2; – int LARGE=3; – int shirtSize=one-of-the-above; But nothing prevents one from setting shirtSize=-1; – Solution: enum’s: – Enum Size {SMALL, MEDIUM, LARGE}; Size shirtSize=Size.one-of-the-above;