II. Compiling and launching from Command-Line, IDE A simple JAVA program

Similar documents
Java Language. Programs. Computer programs, known as software, are instructions to the computer. You tell a computer what to do through programs.

Chapter 1 Introduction to Computers, Programs, and Java

Chapter 1: Introduction to Computers, Programs, and Java

Introduction to Java. Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.

Lecture 1: Introduction to Java

Chapter 1 Introduction to Java

Chapter 1 Introduction to Computers, Programs, and Java. What is a Computer? A Bit of History

Chapter 1 Introduction to Computers, Programs, and Java

Chapter 1 Introduction to Computers, Programs, and Java

Chapter 1 Introduction to Computers, Programs, and Java

Introduction to Computers, Programs, and Java. CSE 114, Computer Science 1 Stony Brook University

Module 1: Introduction to Computers, Programs, and Java

Introduction to Java Programming CPIT 202. WEWwwbvxnvbxmnhsgfkdjfcn

Networks Programming Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000)

1. Introduction. Java. Fall 2009 Instructor: Dr. Masoud Yaghini

Chapter 1 Introduction to Computers, Programs, and Java

Eclipse Tutorial. For Introduction to Java Programming By Y. Daniel Liang

History Introduction to Java Characteristics of Java Data types

Objectives. Chapter 1 Introduction to Computers, Programs, and Java. What is a Computer?

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

Introduction. Introduction to OOP with Java. Lecture 01: Introduction to OOP with Java - AKF Sep AbuKhleiF -

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

NetBeans Tutorial. For Introduction to Java Programming By Y. Daniel Liang. This tutorial applies to NetBeans 6, 7, or a higher version.

Supplement H.1: JBuilder X Tutorial. For Introduction to Java Programming, 5E By Y. Daniel Liang

CHAPTER 1. Introduction to JAVA Programming

Supplement II.B(1): JBuilder X Tutorial. For Introduction to Java Programming By Y. Daniel Liang

Eng. Mohammed S. Abdualal

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

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

Getting Started with Eclipse/Java

Introduction to JAVA Programming Language

Fundamentals of Programming. By Budditha Hettige

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

Eng. Mohammed Alokshiya

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

Chapter 1 Introduction to Computers, Programs, and Java

Advanced Object-Oriented Programming Introduction to OOP and Java

Getting Started. Chapter 1. Java Programming FROM THE BEGINNING. Chapter 1: Getting Started

IQTIDAR ALI Lecturer IBMS Agriculture University Peshawar

Lecture 1: Overview of Java

This lecture will take you through simple and practical approach while learning Java Programming language.

Introduction to OOP Using Java Pearson Education, Inc. All rights reserved.

Chapter 1 Introduction to Computers, Programs, and Java

B.V. Patel Institute of BMC & IT, UTU 2014

C++ Spring Break Packet 11 The Java Programming Language

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

Lecture 4: Introduction to Java and your Development Environment

Java is a high-level programming language originally developed by Sun Microsystems and released in Java runs on a variety of

Programming with Java

Chapter 1. Introduction

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

Java Programming Language Mr.Rungrote Phonkam

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

Lecture 1: Introduction to Java

CS520 Setting Up the Programming Environment for Windows Suresh Kalathur. For Windows users, download the Java8 SDK as shown below.

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Certified Core Java Developer VS-1036

Notes of the course - Advanced Programming. Barbara Russo

CS335 Graphics and Multimedia

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

Introduction to Java Programming

Before you start with this tutorial, you need to know basic Java programming.

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Introduction to Java. Lecture 1 COP 3252 Summer May 16, 2017

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M

Pace University. Fundamental Concepts of CS121 1

JDB - QUICK GUIDE JDB - INTRODUCTION

Introduction to Programming (Java) 2/12

CSE 421 Course Overview and Introduction to Java

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

Getting Started With Java

Chapter. Focus of the Course. Object-Oriented Software Development. program design, implementation, and testing

JAVA Programming Concepts

Introduction to Java

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

Introduction to Java Applications; Input/Output and Operators

Sun ONE Integrated Development Environment

Eclipse Environment Setup

Full file at

CS11 Java. Fall Lecture 1

Chapter 1 Introduction to Computers, Programs, and Java

CS260 Intro to Java & Android 02.Java Technology

The Computer System. Hardware = Physical Computer. Software = Computer Programs. People = End Users & Programmers. people

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

Lab # 2. For today s lab:

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

GETTING STARTED. The longest journey begins with a single step. In this chapter, you will learn about: Compiling and Running a Java Program Page 2

Identifiers. Identifiers are the words a programmer uses in a program Some identifiers are already defined. Some are made up by the programmer:

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java

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

Getting Started with Java. Atul Prakash

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

02/03/15. Compile, execute, debugging THE ECLIPSE PLATFORM. Blanks'distribu.on' Ques+ons'with'no'answer' 10" 9" 8" No."of"students"vs."no.

Java Bytecode (binary file)

The NetBeans IDE is a big file --- a minimum of around 30 MB. After you have downloaded the file, simply execute the file to install the software.

Introduction to Java. Nihar Ranjan Roy.

Getting Started (1.8.7) 9/2/2009

Course Outline. Introduction to java

JVM interprets the Java bytecode, controls how it interacts with the operating system and manages memory.

Transcription:

Contents Topic 01 - Java Fundamentals I. Introducing JAVA II. Compiling and launching from Command-Line, IDE A simple JAVA program III. How does JAVA work IV. Review - Programming Style, Documentation, Syntax error / Runtime error / Logic error Supplement - Eclipse Debugger (Written by Mr. KONG, Tsz Chung Benny, BSCS2) I. Introducing JAVA - The White Paper for Java was announced in May 1996 James Gosling, Henry McGilton - Sun engineers http://www.oracle.com/technetw ork/java/javase/overview/javahist ory-index-198355.html - Java is designed to achieve: Simple Object oriented Distributed Multithreaded Dynamic Architecture neutral, Portable Java is partially modeled on C++, but simplified and improved. Java was designed from the start to be object-oriented. Java is designed to make distributed computing easy with networking capability. Writing network programs is like sending and receiving data to and from a file. Multithread programming is smoothly integrated. Designed to adapt to an evolving environment. Libraries can freely add new methods and instance variables without effecting clients. Straightforward to find out runtime type information. With a Java Virtual Machine (JVM), one program can run on any platform without being recompiled. High performance Robust Secure High performance of interpreted bytecodes, efficient translation of bytecodes to machine code. Java compiler, modified program constructs, runtime exception-handling Security mechanisms to protect against harm caused by stray programs. - The Java platform is available as different packages: http://www.oracle.com/technetw ork/java/langenv-140151.html JRE (Java Runtime Environment) For consumers to run Java programs. JDK (Java Development Kit) For programmers to write Java programs. Includes JRE plus tools for developing, debugging, and monitoring Java applications. Last modified: 4-Sep-2018 1/8

- Once installed, the Java Virtual Machine (Java VM) is launched in the computer. - During runtime, the Java VM interprets Java byte code and translates into OS calls. Java programs (*.class, storing Java byte code) JAVA Virtual Machine OS (Windows, Linux etc..) Hardware (Intel, AMD, etc..) - Java Versions: Version 1.0 (1995) Version 1.1 (1996) Version 1.2 (1998) Version 1.3 (2000) Version 1.4 (2002) Version 1.5 (2004) a. k. a. Java 5 Version 1.6 (2006) a. k. a. Java 6 Version 1.7 (2011) a. k. a. Java 7.. Version?? (2018) see http://openjdk.java.net/projects/jdk/ Java 8 Launch http://www.oracle.com/events/us/en/ja va8/index.html Java 9 stable release - scheduled to come in 2017 http://openjdk.java.net/projects/jdk9/ - Editions for different development purposes: Java Standard Edition (J2SE) J2SE can be used to develop client-side standalone applications or applets. Java Enterprise Edition (J2EE) Server-side applications such as Java servlets, Java ServerPages, and Java ServerFaces. Java Micro Edition (J2ME) Applications for mobile devices such as cell phones. Last modified: 4-Sep-2018 2/8

II. Compiling and Launching from Command-Line, IDE, A Simple JAVA Program With JDK installed, you can compile and run Java programs in this way: 1. Create the source file: Welcome.java 2. At the command prompt, set path to JDK and then compile to give Welcome.class 3. Run it: Explanation of the program: In JAVA, everything is inside a class, including the main() method By convention, class names start with an uppercase letter. File name (Welcome.java) must match class name (class Welcome) The static modifier is added to tell that: we can run main without creating an object first. String[] args is the argument for running the program. (See next slide.) (Learn in Lab01_Q1) In JAVA, we have System.out.print, which is just like cout << in C++ System.out.println: newline is added after the output. Last modified: 4-Sep-2018 3/8

Arguments can be supplied to main() as an array of strings: Example: Run-time exception: The program code expects 2 arguments. But the only one is given. - Integrated Development Environments (IDE): NetBeans Eclipse Last modified: 4-Sep-2018 4/8

III. How does JAVA work Compiling and Running Programs Source files (.java) are compiled into.class files by the javac compiler. A.class file does not contain code that is native to the computer; It contains bytecodes in machine language of Java Virtual Machine (Java VM). The JRE runs.class with an instance of the Java Virtual Machine. Welcome.java Welcome.class Welcome program How are JAVA Programs Architecture neutral, Portable? The role of Java VM Java VM is available on many different operating systems. Once you install JRE or JDK, Java VM is ready in your computer. Welcome.java The same.class file is capable of running on Microsoft Windows, the Solaris, Linux, or Mac OS. Last modified: 4-Sep-2018 5/8

IV. Review - Programming Style, Documentation, Syntax error / Runtime error / Logic error Programming Style and Documentation Appropriate Comments Naming Conventions Choose meaningful and descriptive names. Proper Indentation and Spacing Lines Tabs, tidy spacing Use blank line to separate segments of the code. Block Styles public class Day { private int year; private int month; private int day; public Day(int y, int m, int d) { this.year = y; this.month = m; this.day = d; public String tostring() { return day + "-" + month + "-" + year; Poor! Hard to read! Please add line breaks before methods Next-line style (OK) public class Test { public static void main(string[] args) { System.out.println("Block Styles"); public class Test { public static void main(string[] args) { System.out.println("Block Styles"); End-of-line style (OK) Three types of programming errors Syntax Errors Detected by the compiler public class ShowSyntaxErrors { public static main(string[] args) { System.out.println("Welcome to Java); Runtime Errors Causes the program to abort public class ShowRuntimeErrors { public static void main(string[] args) { System.out.println(1 / 0); Logic Errors Produces incorrect result public class ShowLogicErrors { public static void main(string[] args) { System.out.print("Five plus six is "); System.out.println("5"+"6"); Last modified: 4-Sep-2018 6/8

[Supplement] Eclipse Debugger (Originally written by Mr. KONG Tsz Chung Benny, BSCS2) Debugging allows you to run a program interactively. It is extremely helpful for learning Java language by watching how the variables changes, reacts to changes or source code, etc. Eclipse IDE provides such feature for JAVA, it is highly recommended for you to use it if you want to get a better understanding of what s going on during the execution of your program. Step 1. In your source code window, there is a gap between Package Explorer and Your source code. Right click the gap and select Toggle Breakpoint in the line you wish to start debugging (or double click the gap) Step 2. Once you have added a Breakpoint, press this little bug - you can find it at the tool bar. The program will start to run until the breakpoint is reached. Then it will pause and then you can trace the execution freely starting from that point (See step 4.) Step 3. New windows will pop up inside Eclipse. However, the window which contains the Variable tab is the most important: It tells you the value of each variable when the program continues to execute. Step 4. The following list will tell you how to trace the execution: Keys Description F5 Execute the current line and then move on to the next line which will run next. If the current line (Step Into) contains a method call, then the debugger will step into into the calling method. F6 (Step Over) F7 F8 Execute the current line and then move on to the next line which will run next. It does not "step into", i.e., even if the current line contains method calls, they will be executed as one step. Finish the execution of the current method and return to the caller of this method. Resume the execution of the program until it reaches next breakpoint (if any) As you continue running the program, you will often find there is a line highlighted in yellow in the variable tab. This indicates that the variable has been modified just now. Last modified: 4-Sep-2018 7/8

Added by Helena (Jan 15, 2015): Q: "I have fixed the bug, but the output is still wrong. Why?" Answer: You may need to clean the project first (Project menu => clean) There may be another bug. Use the debugger! Last modified: 4-Sep-2018 8/8