Dale Roberts Introduction to Java - First Program Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.

Slides:



Advertisements
Similar presentations
Chapter 1: Computer Systems
Advertisements

Programming with Java. Problem Solving The purpose of writing a program is to solve a problem The general steps in problem solving are: –Understand the.
IT151: Introduction to Programming
Lecture 2 Introduction to C Programming
University of Palestine software engineering department Introduction to data structures Introduction to java application instructor: Tasneem Darwish.
 2005 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Introduction to C Programming
Chapter 1 Introduction to JAVA. Why Learn JAVA? Java is one of the fastest growing programming language in the world. Java is one of the fastest growing.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Chapter 2 Introduction to Java Applications.
Your First Java Program: HelloWorld.java
INSTRUCTOR: SHIH-SHINH HUANG Windows Programming Using Java Chapter2: Introduction to Java Applications 1.
Chapter 2 - Introduction to Java Applications
Introduction To Computers and Programming Lecture 2: Your first program Professor: Evan Korth New York University.
The Java Programming Language
CMT Programming Software Applications
Java Intro. A First Java Program //The Hello, World! program in Java public class Hello { public static void main(String[] args) { System.out.println("Hello,
Outline Java program structure Basic program elements
01 Introduction1June Introduction CE : Fundamental Programming Techniques.
 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.
Chapter 2 - Introduction to Java Applications
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Java Applications & Program Design
Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R# address: Group Addresses Post message:
 2005 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
 2005 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
1 2 2 Introduction to Java Applications Introduction Java application programming –Display messages –Obtain information from the user –Arithmetic.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Android How to Program, 2/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Java Language and SW Dev’t
Dale Roberts Introduction to Java - Access Specifiers Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
The Java Programming Language
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Java Programming, Second Edition Chapter One Creating Your First Java Program.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 2 - Introduction to Java Applications Outline 2.1Introduction 2.2A Simple Program: Printing a.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
1 COMP 241: Object-Oriented Programming with Java Fall 2004 Lecture 1 September 27, 2004 Serdar Taşıran.
Java The Java programming language was created by Sun Microsystems, Inc. It was introduced in 1995 and it's popularity has grown quickly since A programming.
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
Anatomy of a Java Program. AnotherQuote.java 1 /** A basic java program 2 * 3 Nancy Harris, James Madison University 4 V1 6/2010.
Java™ How to Program, 10/e Late Objects Version © Copyright by Pearson Education, Inc. All Rights Reserved.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Dale Roberts Introduction to Java - Input, Program Control and Instantiation Dale Roberts, Lecturer Computer Science, IUPUI
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
Computer Programming Your First Java Program: HelloWorld.java.
Introduction to Java Applications
Working with Java.
Chapter 3 GC 101 Java Fundamentals.
Chapter 2, Part I Introduction to C Programming
Chapter 2 Introduction to Java Applications
Chapter 2 Introduction to Java Applications
Fundamentals of Java Programs, Input/Output, Variables, and Arithmetic
Chapter 2 - Introduction to Java Applications
Chapter 1: Computer Systems
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
Introduction to Java Applications
Computer Programming-1 CSC 111
Instructor: Alexander Stoytchev
Presentation transcript:

Dale Roberts Introduction to Java - First Program Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School of Science, IUPUI

Dale Roberts 1-2 Java Program Structure In the Java programming language: A program is made up of one or more classes A class contains one or more methods A method contains program statements Program statements can reference local or instance variables. There is no concept of global variable. These terms will be explored in detail throughout the course A Java application always contains a method called main

Dale Roberts © 2004 Pearson Addison-Wesley. All rights reserved1-3 Java Program Structure public class MyProgram {}{} // comments about the class class header class body Comments can be placed almost anywhere

Dale Roberts © 2004 Pearson Addison-Wesley. All rights reserved1-4 Java Program Structure public class MyProgram {}{} // comments about the class public static void main (String[] args) {}{} // comments about the method method header method body

Dale Roberts © 2004 Pearson Addison-Wesley. All rights reserved1-5Comments Comments in a program are called inline documentation They should be included to explain the purpose of the program and describe processing steps They do not affect how a program works Java comments can take three forms: // this comment runs to the end of the line /* this comment runs to the terminating symbol, even across line breaks */ /** this is a javadoc comment */

Dale Roberts © 2004 Pearson Addison-Wesley. All rights reserved1-6Identifiers Identifiers are the words a programmer uses in a program An identifier can be made up of letters, digits, the underscore character ( _ ), and the dollar sign Identifiers cannot begin with a digit Java is case sensitive - Total, total, and TOTAL are different identifiers By convention, programmers use different case styles for different types of identifiers, such as title case for class names - Lincoln upper case for constants - MAXIMUM

Dale Roberts 7 First Program in Java: Printing a Line of Text Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays a line of text Illustrates several important Java language features

Dale Roberts Outline Welcome1.java 8

Dale Roberts 9 First Program in Java: Printing a Line of Text (Cont.) Comments start with: // Comments ignored during program execution Document and describe code Provides code readability Traditional comments: /*... */ /* This is a traditional comment. It can be split over many lines */ Another line of comments Note: line numbers not part of program, added for reference 1 // Fig. 2.1: Welcome1.java 2 // Text-printing program.

Dale Roberts 10 First Program in Java: Printing a Line of Text (Cont.) Saving files File name must be class name with.java extension Welcome1.java Left brace { Begins body of every class Right brace ends declarations (line 13) 4 public class Welcome1 5 {

Dale Roberts 11 First Program in Java: Printing a Line of Text (Cont.) Part of every Java application Applications begin executing at main Parentheses indicate main is a method (Ch. 3 and 6) Java applications contain one or more methods Exactly one method must be called main Methods can perform tasks and return information void means main returns no information For now, mimic main 's first line Left brace begins body of method declaration Ended by right brace } (line 11) 7 public static void main( String args[] ) 8 {

Dale Roberts First Program in Java: Printing a Line of Text (Cont.) Instructs computer to perform an action Prints string of characters String – series of characters inside double quotes White-spaces in strings are not ignored by compiler System.out Standard output object Print to command window (i.e., MS-DOS prompt) Method System.out.println Displays line of text This line known as a statement Statements must end with semicolon ; 9 System.out.println( "Welcome to Java Programming!" );

Dale Roberts 13 First Program in Java: Printing a Line of Text (Cont.) Ends method declaration Ends class declaration Can add comments to keep track of ending braces 11 } // end method main 13 } // end class Welcome1

Dale Roberts 14 First Program in Java: Printing a Line of Text (Cont.) Compiling a program Open a command prompt window, go to directory where program is stored Type javac Welcome1.java If no syntax errors, Welcome1.class created Has bytecodes that represent application Bytecodes passed to JVM

Dale Roberts 15 First Program in Java: Printing a Line of Text (Cont.) Executing a program Type java Welcome1 Launches JVM JVM loads.class file for class Welcome1.class extension omitted from command JVM calls method main

Dale Roberts Executing Welcome1 in a Microsoft Windows XP Command Prompt window. 16 You type this command to execute the application The program outputs Welcome to Java Programming!

Dale Roberts 17 Displaying Text with printf System.out.printf Feature added in Java SE 5.0 Displays formatted data Format string Fixed text Format specifier – placeholder for a value Format specifier %s – placeholder for a string 9 System.out.printf( "%s\n%s\n", 10 "Welcome to", "Java Programming!" );

Dale Roberts Acknowledgements Pearson Education, Lewis and Loftus. Deitel, Java How to Program /language.impl.overview.pdf /language.impl.overview.pdf