1 Java Programming Basics SE-1011 Dr. Mark L. Hornick.

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.
LESSON 3 - Identifiers JAVA PROGRAMMING. Identifiers All the Java components —classes, variables, and methods— need names. In Java these names are called.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
The Java Programming Language
Getting Started with Java
Outline Java program structure Basic program elements
Chapter 1 Introduction. © 2004 Pearson Addison-Wesley. All rights reserved1-2 Outline Computer Processing Hardware Components Networks The Java Programming.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
Copyright 2013 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Copyright 2008 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading: self-check: #1-14.
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
Java: Chapter 1 Computer Systems Computer Programming II Aug
Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R# address: Group Addresses Post message:
University of Limerick1 Work with API’s. University of Limerick2 Learning OO programming u Learning a programming language can be broadly split into two.
Java 程序设计 Java Programming Fall, Contents for Today Java Program Structure  How to Compile a Java Program  How to Run a Java Program Environment.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
© 2006 Pearson Education Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition.
Java: Chapter 1 Computer Systems Computer Programming II.
Java Language and SW Dev’t
The Use of Foreign Language Teaching Techniques in the Computer Science Laboratory to Support Oral Presentation and Group Work.
CE-2810 Dr. Mark L. Hornick 1 GNU GCC Assembler and C/C++ compiler.
1 Computer Systems -- Introduction  Chapter 1 focuses on:  the structure of a Java application  basic program elements  preparing and executing a program.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
CSC204 – Programming I Lecture 4 August 28, 2002.
Introduction. Objectives An overview of object-oriented concepts. Programming and programming languages An introduction to Java 1-2.
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
C Derived Languages C is the base upon which many build C++ conventions also influence others *SmallTalk is where most OOP comes Java and Javascript have.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Chapter 2: Java Fundamentals
Page: 1 การโปรแกรมเชิงวัตถุด้วยภาษา JAVA บุรินทร์ รุจจนพันธุ์.. ปรับปรุง 15 มิถุนายน 2552 Keyword & Data Type มหาวิทยาลัยเนชั่น.
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.
SE-1010 Dr. Mark L. Hornick 1 Variables & Datatypes.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
SE-1010 Dr. Mark L. Hornick 1 Java Programming Basics.
CS-1030 Dr. Mark L. Hornick 1 Java Review Interactive.
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Introduction to Java Programming by Laurie Murphy Revised 09/08/2016.
Copyright 2010 by Pearson Education APCS Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
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.
C++ Lesson 1.
Asst.Prof.Dr. Tayfun ÖZGÜR
Working with Java.
Chapter 4 Assignment Statement
Lecture 2: Data Types, Variables, Operators, and Expressions
CSE 190D, Winter 2013 Building Java Programs Chapter 1
Variables and Arithmetic Operators in JavaScript
University of Central Florida COP 3330 Object Oriented Programming
Chapter 3 Assignment Statement
null, true, and false are also reserved.
Introduction to Java Programming
CS-0401 INTERMEDIATE PROGRAMMING USING JAVA
An overview of Java, Data types and variables
Instructor: Alexander Stoytchev
Chapter 1: Computer Systems
Units with – James tedder
JavaScript Reserved Words
Instructor: Alexander Stoytchev
Focus of the Course Object-Oriented Software Development
CSE 142, Spring 2012 Building Java Programs Chapter 1
Instructor: Alexander Stoytchev
Zorah Fung University of Washington, Spring 2015
Chap 2. Identifiers, Keywords, and Types
CSE 142, Winter 2014 Building Java Programs Chapter 1
Agenda Types and identifiers Practice Assignment Keywords in Java
Zorah Fung University of Washington, Winter 2016
Presentation transcript:

1 Java Programming Basics SE-1011 Dr. Mark L. Hornick

Computer of the future? 2SE-1011 Dr. Mark L. Hornick

Algorithms are implemented in Java methods A method is a named collection of Java instructions that implement an algorithm The method for actually computing the number of days between two dates might be named computeDays The method names - or method identifiers - are made up by you (…but you have to follow some rules…) 3SE-1011 Dr. Mark L. Hornick

Good and bad method identifiers computeDays printResult getStartDate days getIt method1 PRINTit x109 SE-1011 Dr. Mark L. Hornick 4 Good method names are meaningful use verbs that imply an action use camel-case format Bad method names are Vague or meaningless don’t use verbs use an unconventional format

Java is also case-sensitive… This means that the following method identifiers are considered separate and distinct: getStartDate getStartdate SE-1011 Dr. Mark L. Hornick 5 Avoid creating identifiers that differ only in capitalization

SE Focus Dr. Mark L. Hornick 6 Java’s reserved words cannot be used as identifiers abstract default if private this boolean do implements protected throw break double import public throws byte else instanceof return transient case extends int short try catch final interface static void char finally long strictfp volatile class float native super while const for new switch continue goto package synchronized Don’t create identifiers that differ from reserved words only in capitalization (e.g. Continue)

Algorithms range from trivially simple to incredibly complex An extremely simple program may consist of a single algorithm that just prints something to the screen Realistic programs typically implement multiple algorithms of varying complexity 7SE-1011 Dr. Mark L. Hornick

If an algorithm is complex, it is usually broken into multiple methods Normally, each method handles a single task this keeps things organized and simpler Sub-tasks are delegated to subordinate methods Structuring a program into tasks and sub-tasks is a skill you’ll develop as you gain experience creating Java programs 8SE-1011 Dr. Mark L. Hornick

Related methods are grouped together in named classes Normally, the methods with a class share information, but hide information from other classes This keeps information from being changed or corrupted accidentally However, there are ways for methods of one class to send or receive information from methods of another class 9SE-1011 Dr. Mark L. Hornick

Good and bad class names DayCalculator Lab2Program TVController days Calculate Class1 x109 SE-1011 Dr. Mark L. Hornick 10 Good class names are meaningful use nouns that imply the purpose Start with an uppercase letter Bad class names are Vague or meaningless don’t use nouns use an unconventional format

Every Java program must have a class that contains a primary method, named main This name main (not a verb) exists for historical reasons, and cannot be changed The class containing the main method can be named anything (that makes sense), like DayCalculator The class containing the main method, regardless of it’s actual name, is referred to as the main class 11SE-1011 Dr. Mark L. Hornick

How a Java program gets executed 12 DayCalculator SE-1011 Dr. Mark L. Hornick

13 Summary: The basic Java Program To create a runnable program, we must first define a main class that represents our program We can give the main class any reasonable name, like “MyMainClass” When we “run” the program, the Java Virtual Machine (VM) accesses the main class we defined Then the VM sends a message to our program’s main class that tells it to run. The “run” message is sent by the VM as a call to a method named main that our program’s main class must have defined. SE-1011 Dr. Mark L. Hornick

14 A Java program is composed of one or more classes One of the classes in the program must be the main class That is, it must have a method called main() The main class itself can have any (valid) name All of the Java instructions for a class and a class’s methods must reside in a file having the same name as the class DayCalculator.java must be the name of the file containing all the Java instructions for a class named DayCalculator. SE-1011 Dr. Mark L. Hornick

15 Java Edit-Compile-Run Cycle Step One: Create a program with an editor. This is where you type in the Java instructions, using a text editor (or something like Eclipse), and save the program to a file. The name of the class has to match the name of the file containing the class and have the.java file extension. This is called a source file. SE-1011 Dr. Mark L. Hornick

16 Java Edit-Compile-Run Cycle Step 2: Compile the source file. The process of compiling the source file creates a bytecode file, which is not human-readable. The name of the compiler-generated bytecode file will have the suffix.class while its prefix is the same as the source file’s. DayCalculator.java is compiled, creating DayCalculator.class, the bytecode (or class) file SE-1011 Dr. Mark L. Hornick

17 Java Edit-Compile-Run Cycle Source file vs. its bytecode file: SE-1011 Dr. Mark L. Hornick

18 Java Edit-Compile-Run Cycle Step 3: Execute the bytecode file. The java interpreter (VM) will go through the bytecode file and execute the instructions in it. If an error occurs while running the program, the interpreter will catch it and stop its execution. The VM starts execution at the bytecode instructions that correspond to the Java statement public static void main() SE-1011 Dr. Mark L. Hornick

19 Java Edit-Compile-Run Cycle The result after the interpreter executes the instructions in the bytecode file. SE-1011 Dr. Mark L. Hornick

20 Besides Java instructions, programs also contain comments which state the purpose of the program, explain the meaning of code, and provide other descriptions to help others to understand your code. Comments are not compiled or executed Comments are just text you make up Comments augment the program by providing more understandable, human-friendly information that help readers of your program understand what you have written. SE-1011 Dr. Mark L. Hornick

21 A program template to use as the starting point for all Java applications SE-1011 Dr. Mark L. Hornick

22 In Java, classes are further grouped into logical packages Packages provide a further means of organizing related classes You create package names yourself Package names start with lowercase Classes in the same package reside in the same file folder, where the folder is the package name SE-1011 Dr. Mark L. Hornick

23 Quiz 1 tomorrow at start of Lab Learning outcomes since the start of the course: Define the term program. Define the term algorithm. Why do we use pseudocode? Why do we use flowcharts? How does a Java pseudocode variable differ from a variable you use in Math? List some possible pseudocode variables. Given psuedocode, draw the corresponding flowchart. Given a flowchart, write the corresponding pseudocode. What two types of control-flow does a diamond represent in a flowchart? SE-1011 Dr. Mark L. Hornick