Hands-on Introduction to JAVA

Slides:



Advertisements
Similar presentations
Introduction to programming in java. Input and output to screen with Java program Structure of Java programs Statements Conditional statements.
Advertisements

Begin Java Pepper. Objectives What is a program? Learn the basics of your programming tool: BlueJ Write a first Java program and see it run Make some.
IT151: Introduction to Programming
Dale Roberts Introduction to Java - First Program Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Chapter 2: Your First Program! Hello World: Let’s Program  All programs must have the extension.java  Our first program will be named: HelloWorld.java.
CPSC150 Fall 2008 Dr. L. Lambert. CPSC150 Overview Syllabus Use Textbook, ask questions, extra thorough, I will post sections covered All information.
How do we make our Welcome.java program do something? The java in our Welcome.java file won’t do anything by itself. We need to tell the computer to execute.
Excerpts from Introduction to Java Programming, 4E Author: Y. Daniel Liang (Copyright by Prentice Hall)
Introduction to Java Programming, 4E
 2003 Prentice Hall, Inc. All rights reserved. Customized by Sana Odeh for the use of this class. 1 Introduction to Computers and Programming in JAVA.
Unit2: Object-oriented programming Getting started with Java Jin Sa.
How do we make our Welcome.java program do something? The java in our Welcome.java file won’t do anything by itself. We need to tell the computer to execute.
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
“Introduction to Programming With Java”
Introducing Java.
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.
Basics Programming Concepts. Basics A computer program is a set of instructions to tell a computer what to do Machine language = circuit level language.
Welcome to the Lecture Series on “Introduction to Programming With Java”
Session One Introduction. Personal Introduction Role of programmers Robot Examination HUD & HID Uploading Code.
FRST JAVA PROGRAM. Getting Started with Java Programming A Simple Java Application Compiling Programs Executing Applications.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and Server Side Programming Very rich GUI libraries Portability (machine independence) A.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
1 CSC204 – Programming I Lecture 2 Intro to OOP with Java.
© 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.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Board Activity Find your seat on the seating chart Login – Remember your login is your first initial your last name and the last three numbers of your.
Programming Concept Chapter I Introduction to Java Programming.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Introduction to Java Programming with Forte Y. Daniel Liang.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
The scope of local variables. Murphy's Law The famous Murphy's Law says: Anything that can possibly go wrong, does. (Wikipedia page on Murphy's Law:
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Introduction to programming in the Java programming language.
8/31: Intro to Java, Languages, and Environments Types of programming languages –machine languages –assembly languages –high-level languages Java environment.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and web applications Very rich GUI libraries Portability (machine independence) A real Object.
Anatomy of a Java Program. AnotherQuote.java 1 /** A basic java program 2 * 3 Nancy Harris, James Madison University 4 V1 6/2010.
Java FilesOops - Mistake Java lingoSyntax
Introduction to Java Programming. 2 Chapter 1 Introduction to Java and Forte F What Is Java? F Getting Started With Java Programming –Create, Compile.
CPRG 215 Introduction to Object-Oriented Programming with Java Module 1-Introduction to Java Topic 1.3 Write Your First Java Program Produced by Harvey.
Lecture1 Instructor: Amal Hussain ALshardy. Introduce students to the basics of writing software programs including variables, types, arrays, control.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Introduction to 1. What is Java ? Sun Microsystems Java is a programming language and computing platform first released by Sun Microsystems in The.
Lesson 2: First Java Programs. 2.1 Why Java? Java is one of the most popular programming languages in the world. Java is a modern object-oriented programming.
Introduction to Java Programming, 4E Y. Daniel Liang.
Introduction to Object Oriented
Introduction to programming in java
Computer Programming Your First Java Program: HelloWorld.java.
Lecture 1b- Introduction
Dept of Computer Science University of Maryland College Park
Object-Oriented Programming Using Java
Chapter 1 Introduction to Computers, Programs, and Java
GC101 Introduction to computer and program
Chapter 3 GC 101 Java Fundamentals.
Introduction to.
Chapter 2, Part I Introduction to C Programming
Java programming lecture one
Intro to Java.
Chapter 1 Introduction to Computers, Programs, and Java
Chapter 10 Programming Fundamentals with JavaScript
Chapter 3 Classes and Objects
Chapter 1 Introduction to Computers, Programs, and Java
Java Intro.
Anatomy of a Java Program
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
Chapter 2: Java Fundamentals
Computer Programming-1 CSC 111
Presentation transcript:

Hands-on Introduction to JAVA First Java Program 2008-2009 1b Michael Fung, CS&E, The Chinese University of HK

The First Java Program Type all carefully and save it to a file named Welcome.java class Welcome { /* The Welcome Program ------------------- Illustrates a simple program displaying a message. */ public static void main (String [ ] args) { System.out.println("Welcome to Java!"); } 2008-2009 1b Michael Fung, CS&E, The Chinese University of HK

The First Java Program Java program source files (.java) contain definition of classes class Welcome { /* The Welcome Program ------------------- Illustrates a simple program displaying a message. */ public static void main (String [ ] args) { System.out.println("Welcome to Java!"); } 2008-2009 1b Michael Fung, CS&E, The Chinese University of HK

The First Java Program Curly braces pair enclose a block of code, class Welcome here class Welcome { /* The Welcome Program ------------------- Illustrates a simple program displaying a message. */ public static void main (String [ ] args) { System.out.println("Welcome to Java!"); } Don’t miss me! 2008-2009 1b Michael Fung, CS&E, The Chinese University of HK

The First Java Program Curly braces pair enclose a block of code, method main( ) here class Welcome { /* The Welcome Program ------------------- Illustrates a simple program displaying a message. */ public static void main (String [ ] args) { System.out.println("Welcome to Java!"); } Don’t miss me! 2008-2009 1b Michael Fung, CS&E, The Chinese University of HK

The First Java Program This is a block of comments, for human, not for computer class Welcome { /* The Welcome Program ------------------- Illustrates a simple program displaying a message. */ public static void main (String [ ] args) { System.out.println("Welcome to Java!"); } It explains to you what happens 2008-2009 1b Michael Fung, CS&E, The Chinese University of HK

The First Java Program /* and */ pair encloses a comment block class Welcome { /* The Welcome Program ------------------- Illustrates a simple program displaying a message. */ public static void main (String [ ] args) { System.out.println("Welcome to Java!"); } Don’t miss me! 2008-2009 1b Michael Fung, CS&E, The Chinese University of HK

The First Java Program This is a method of the class Welcome, named main( ) class Welcome { /* The Welcome Program ------------------- Illustrates a simple program displaying a message. */ public static void main (String [ ] args) { System.out.println("Welcome to Java!"); } 2008-2009 1b Michael Fung, CS&E, The Chinese University of HK

The First Java Program There MUST be a pair of parentheses following ALL method names class Welcome { /* The Welcome Program ------------------- Illustrates a simple program displaying a message. */ public static void main (String [ ] args) { System.out.println("Welcome to Java!"); } Don’t miss me! 2008-2009 1b Michael Fung, CS&E, The Chinese University of HK

Michael Fung, CS&E, The Chinese University of HK The First Java Program Let's leave these first. Let's leave these first. class Welcome { /* The Welcome Program ------------------- Illustrates a simple program displaying a message. */ public static void main (String [ ] args) { System.out.println("Welcome to Java!"); } 2008-2009 1b Michael Fung, CS&E, The Chinese University of HK

The First Java Program Standard properties of the main( ) method class Welcome { /* The Welcome Program ------------------- Illustrates a simple program displaying a message. */ public static void main (String [ ] args) { System.out.println("Welcome to Java!"); } 2008-2009 1b Michael Fung, CS&E, The Chinese University of HK

The First Java Program A statement (instruction) to display a message class Welcome { /* The Welcome Program ------------------- Illustrates a simple program displaying a message. */ public static void main (String [ ] args) { System.out.println("Welcome to Java!"); } 2008-2009 1b Michael Fung, CS&E, The Chinese University of HK

The First Java Program After every statement, there must be a semi-colon! class Welcome { /* The Welcome Program ------------------- Illustrates a simple program displaying a message. */ public static void main (String [ ] args) { System.out.println("Welcome to Java!"); } 2008-2009 1b Michael Fung, CS&E, The Chinese University of HK

Michael Fung, CS&E, The Chinese University of HK The First Java Program How to ask the computer to act according to the instructions in this program? class Welcome { /* The Welcome Program ------------------- Illustrates a simple program displaying a message. */ public static void main (String [ ] args) { System.out.println("Welcome to Java!"); } 2008-2009 1b Michael Fung, CS&E, The Chinese University of HK

Michael Fung, CS&E, The Chinese University of HK The First Java Program Change to the directory containing the file Welcome.java Type javac Welcome.java It generates a new file Welcome.class Type (without .class) java Welcome What’s the result? 2008-2009 1b Michael Fung, CS&E, The Chinese University of HK

Michael Fung, CS&E, The Chinese University of HK The First Java Program Welcome to Java! Welcome main Java Virtual Machine Message sender 2008-2009 1b Michael Fung, CS&E, The Chinese University of HK

What has happened? Java Program [Welcome.java] Compile Java Compiler [javac] Compile Java Byte Code [Welcome.class] native code Translate Java Virtual Machine (JVM) [java] It locates the class method main() from the class Welcome and starts execution from there 2008-2009 1b Michael Fung, CS&E, The Chinese University of HK

Big Program For Simple Task? Yes, it just displays a little message. When writing business letters, we conform to grammar and format. Likewise for programming! For more complicated tasks, such overheads are relatively trivial. 2008-2009 1b Michael Fung, CS&E, The Chinese University of HK

Software Life Cycle Computer programming is not just writing programs after learning a language. requirements specification program design conception design analysis 70% of the software cost is related to software maintenance in the operation phase. Well-designed and constructed software is easier to maintain. coding actual program operation debugging testing 2008-2009 1b Michael Fung, CS&E, The Chinese University of HK

Michael Fung, CS&E, The Chinese University of HK End Note Readings and References Chapter 1 2008-2009 1b Michael Fung, CS&E, The Chinese University of HK