Unit2: Object-oriented programming Getting started with Java Jin Sa.

Slides:



Advertisements
Similar presentations
L1-2:CSC ©Dr. Basheer M. Nasef Lecture #1 By Dr. Basheer M. Nasef.
Advertisements

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.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
Introduction To Computers and Programming Lecture 2: Your first program Professor: Evan Korth New York University.
Excerpts from Introduction to Java Programming, 4E Author: Y. Daniel Liang (Copyright by Prentice Hall)
Introduction to Java Programming, 4E
Introduction to Java ISYS 350. A Brief History Sun Microsystems released this language in 1996 – Versions: 1.0 – 1.6 Java Development Kit, JDK – Standard.
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
The switch statement: an N-way selection statement.
Introduction to the JDK Java for Computational Finance
BASIC JAVA PROGRAMMING TUTORIAL. History  James Gosling and Sun Microsystems  Oak  Java, May 20, 1995, Sun World  Hot Java –The first Java-enabled.
Introduction to Java Programming with JBuilder 4
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.
From BlueJ to NetBeans SWC 2.semester.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA ‏ Packages.
LESSON 2 CREATING A JAVA APPLICATION JAVA PROGRAMMING Compiled By: Edwin O. Okech [Tutor, Amoud University]
Fundamentals of Java.  Explain the structure of a Java class  List and explain steps to write a Java program  Identify the benefits of NetBeans IDE.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Programming Languages Machine.
1.  At the end of this slide, student can:  Explore tools, features, properties and interface of the Textpad.  Creating a new project.  Open and run.
Session One Introduction. Personal Introduction Role of programmers Robot Examination HUD & HID Uploading Code.
10/10/2015Assoc. Prof. Stoyan Bonev1 COS240 O-O Languages AUBG, COS dept Lecture 10b Title: Running Programs & IDEs (Java) Reference: COS240 Syllabus.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
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
Programming Concept Chapter I Introduction to Java Programming.
Introduction to Java Programming with Forte Y. Daniel Liang.
Clement Allen, PhD Florida A&M University SUMMER 2006.
An Introduction to Software Development Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Introduction to Java Programming. Introduction Course Objectives Organization of the Book.
Java programming Package. A package is a group of similar types of classes, interfaces and sub-packages. Package can be categorized in two form, built-
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
DrJava A lightweight pedagogic environment for Java Eric Allen, Robert Cartwright, and Brian Stoler Rice University
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 3.
Application Architecture Using Java Hong Li. Introduction Developed by a team led by James Gosling at Sun Microsystem. Originally called Oak, designed.
Lecture 02. Java Virtual Machine(JVM) –set of computer software programs and data structures that use a virtual machine model for the execution of other.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
Introduction to Java Programming. 2 Chapter 1 Introduction to Java and Forte F What Is Java? F Getting Started With Java Programming –Create, Compile.
Introduction to array: why use arrays ?. Motivational example Problem: Write a program that reads in and stores away 5 double numbers After reading in.
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.
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
ITP 109 Week 2 Trina Gregory Introduction to Java.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to Computers,
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.
Introduction to Object Oriented
Working with Java.
Object-Oriented Programming Using Java
Object-Orientated Analysis, Design and Programming
Running Programs & IDEs Reference: COS240 Syllabus
Software Development Packages
Java Basics Packages.
Data types, Expressions and assignment, Input from User
Chapter 1 Introduction to Computers, Programs, and Java
Introduction to Java.
Hands-on Introduction to JAVA
Chapter 1 Introduction to Computers, Programs, and Java
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
Building a program (Java libraries) - an example
Classes 5/5 May 14, 2019 ICS102: Classes 5/5.
Presentation transcript:

Unit2: Object-oriented programming Getting started with Java Jin Sa

Objectives of this unit To understand relevant terminologies To know the basic syntax of a Java program and methods To be able to write, compile and run simple Java programs To know how to group classes into packages To know how to use the Scanner class To know how to create, compile and run Java programs using NetBeans

Terminologies Java 2 Platform, Standard Edition (J2SE) Java 2 Platform, Enterprise Edition (J2EE) Java Development Toolkit (JDK), set of tools such as compiler (javac), documentation generator (javadoc) and debugger Java API: predefined classes and interfaces for developing java programs. Integrated development environment (IDE): integrate tools such as compiler and debugger to provide facilities for programmers to develop software, e.g. NetBeans incorporates the development tools of the JDK into one convenient GUI-based program.

A Simple Java program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args){ System.out.println(“Welcome to Java!"); }

Develop and run the Java program without IDE Name of the file must be the same as the name of the class with.java, – e.g. Welcome.java – Convention: class name starts with capital letter To compile – javac Welcome.java – Generates a class file called Welcome.class To run – java Welcome

Develop and run Java programs using IDE (NetBeans) incorporates the Java compiler, the Java interpreter and other tools together with file and project management for developing and executing Java programs. Student activity 2.1. in section C.3. Following NetBeans tutorial on how to create and run a java program using NetBeans Student activity 2.2 in section C.3, create the Welcome program using NetBeans

Some basic language features Referenece: Sun’s tutorial on Java (Language basics tsandbolts/index.html tsandbolts/index.html Package Scanner Loop Switch Array Method

Package and import Everything in java is part of a class. Packages are used to group classes Package can contain other packages Java expects a one-to-one mapping of the package name and the file system directory structure Every class in Java belongs to a package, to put a class in a package, include this line as the first line – package packagename; – If not, the class is in a default unnamed package

Welcome class in the startjava package package startjava; //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println(“Welcome to Java!"); }

Use classes from other packages Use the fully qualified name of the class. E.g. the fully qualified name for the Scanner class is – java.util.Scanner. Or use the “ import ” statement. For example, to import the Scanner class from the java.util package, you use – import java.util.Scanner; You can also import all the classes in a package, e.g. – import java.util.*; The import statement tells the compiler where to locate the classes.

Input using Scanner package startjava; import java.util.Scanner; //This program prints Welcome to Java!+the name public class Welcome { public static void main(String[] args) { String name=""; Scanner scan = new Scanner(System.in); System.out.println("Enter your name:"); name=scan.nextLine(); System.out.println("Welcome to Java! "+name); }

Loop and switch in Java Read unit 2 “Example 1: Calculating total – using loop” in section D.3 Complete Student Activity 2.3 Read unit 2 Example 2: Option menu – using switch in section D.4 Complete Student Activity 2.4

Array in Java Read unit 2 “Example 3: An Example with an array” in section D.5 Complete Student Activity 2.5

An example of using methods public class Welcome1 { public static void main(String[] args) { prompt(); String name=getName(); System.out.println(name); } public static void prompt(){ System.out.println(“Enter your name”); } public static String getName(){ Scanner in=new Scanner(System.in); String nm=in.nextLine(); return nm; }

Using methods Read unit 2 “Example 4: An example with a method” in section D.6 Complete Student Activity 2.6

Summary In this unit, we have introduced some well known terminology related to programming in Java explained how to use NetBeans demonstrated how to write simple Java programs using NetBeans introduced the concept of package illustrated how to use the Scanner class for input covered some basic program concepts including array, loop, conditional statement and methods.