TCU CoSc 10403 Introduction to Programming (with Java) Java Language Overview.

Slides:



Advertisements
Similar presentations
Designing a Program & the Java Programming Language
Advertisements

Chapter 1: Computer Systems
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Java Programming, 3e Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
1 Kursusform  13 uger med: Undervisning i klassen 1,5-2 timer Opgave ”regning” i databar (løsninger på hjemmeside) En midtvejsopgave der afleveres og.
The Java Programming Language
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
©2004 Brooks/Cole Chapter 1: Getting Started Sections Covered: 1.1Introduction to Programming 1.2Constructing a Java Program 1.3The print() and println()
Aalborg Media Lab 21-Jun-15 Software Design Lecture 1 “ Introduction to Java and OOP”
Outline Java program structure Basic program elements
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Chapter 1 Introduction. © 2004 Pearson Addison-Wesley. All rights reserved1-2 Outline Computer Processing Hardware Components Networks The Java Programming.
Introduction to C Programming
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Java Programs COMP 102 #3.
Chapter 1 Introduction.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
A First Program Using C#
Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R# address: Group Addresses Post message:
Java Programming, 3e Concepts and Techniques Chapter 2 - Part 2 Creating a Java Application and Applet.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley John Lewis, Peter DePasquale, and Joseph Chase Chapter 1: Introduction.
© 2006 Pearson Education Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition.
Chapter 1.4 Programming languages Homework Due: Monday, August 11, 2014.
Java: Chapter 1 Computer Systems Computer Programming II.
Java Language and SW Dev’t
General Programming Introduction to Computing Science and Programming I.
Chapter 2 Overview of C Part I J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National Taipei University.
© 2006 Pearson Education 1 Obj: cont 1.3 and 1.4, to become familiar with identifiers and to understand how programming languages work HW: p.51 #1.8 –
1 Computer Systems -- Introduction  Chapter 1 focuses on:  the structure of a Java application  basic program elements  preparing and executing a program.
The Java Programming Language
Introduction. Objectives An overview of object-oriented concepts. Programming and programming languages An introduction to Java 1-2.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Input, Output, and Processing
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Computer Programming 2 Lab(1) I.Fatimah Alzahrani.
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
Chapter 1 Section 1.1 Introduction to Java Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
Lecture 1 Introduction Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Introduction to programming in the Java programming language.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
1 CSE1340 Class 4. 2 Objectives Write a simple computer program in Java Use Swing components to build the GUI Use proper naming conventions for classes.
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
CSC Programming I Lecture 6 September 4, 2002.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
1 Problem Solving b The purpose of writing a program is to solve a problem b The general steps in problem solving are: Understand the problemUnderstand.
Java Programming, 2E Introductory Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Intro to Programming  Chapter 1 Part 2  Problem Solving.
PROGRAM ESSENTIALS. TOKENS  SMALLEST UNITS OF A PROGRAM LANGUAGE  Special Symbols  Mathematical Operators  Punctuation  Word Symbols  Key Words.
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
Creating a Java Application and Applet
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Java Programs COMP 102 #3.
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Chapter 2 C++ Basics.
© Peter Andreae Java Programs COMP 102 # T1 Peter Andreae Computer Science Victoria University of Wellington.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
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.
Introduction to Computing Science and Programming I
Working with Java.
Chapter 2 Introduction to C++ Programming
CSC201: Computer Programming
Lecture 1 Introduction Richard Gesick.
Chapter 3 Syntax, Errors, and Debugging
1.3 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.
Unit 1: Introduction Lesson 1: PArts of a java program
Chapter 1: Computer Systems
Focus of the Course Object-Oriented Software Development
Instructor: Alexander Stoytchev
Presentation transcript:

TCU CoSc Introduction to Programming (with Java) Java Language Overview

Consider another simple HelloWorld program import javax.swing.*; import java.awt.*; /* Another HelloWorld program in Java */ public class HelloWorld extends JApplet { JLabel helloLabel = new JLabel ("How ya doing?"); public void init() { setLayout(new FlowLayout()); add (helloLabel); helloLabel.setForeground (Color.RED); }

Syntax & Semantics Note that the preceding program contained a variety of different symbols:,*/();.” These are delimiters (punctuation marks) in the language and must appear in particular places. Similarly, note that there are words such as (“class”, “public”, “extends”, “import”, “Applet”) - these are reserved words in the language and must not be misspelled or written in the wrong context.

Syntax & Semantics The syntax of a language defines how you can put symbols, reserved words, and identifiers together to make a valid program. During compilation, all syntax rules are checked. If a program is not syntactically correct, the compiler gives error messages and won’t produce the bytecode. Syntax errors must be eliminated before the bytecodes are produced that allows us to try to ‘execute’ the program. The semantics of a language construct is the meaning of the construct; it defines its role in a program A syntactically correct program does not mean it is logically (semantically) correct. A program will always do what it is told to do - not what the programmer meant to tell it to do.

Errors A program may have three different types of errors. 1.Compile-time errors - errors with syntax (if compile-time errors exist, an executable version of the program is not created. 2.Run-time errors – program compiles – starts to excute and then crashes (terminates abnormally) (Example: divide by zero). 3.Logical errors – program compiles and executes.The program runs with no errors but produces incorrect results.

Problem Solving Debugging : finding and fixing errors in code System.out.println prints to the console window use System.out.println statements to see where you are in the program’s execution or to display the value of variables: –System.out.println( “a” ); –System.out.println( “x = ” + x ); These will display in the Console window at the bottom of the IDE: 6 System.out.println information appears in the Console window.

Coding Style White Space –Spaces, blank lines, and tabs are collectively called white space and are used to separate words and symbols in a program –Extra white space is ignored –A valid Java program can be formatted many different ways –Programs should be formatted to enhance readability, using consistent indentation –Poor examples: *** Choose some style (mine, the Author’s) and stick with it!!!

Better Style White space consists of blanks, tabs, and newline characters. –White space is used to separate the words and symbols used in Java programs. –A programmer can use white space to emphasize parts of the program and to make the program easier to read. Except when it’s used to separate words, the computer ignores white space. /********************************************************************/ /* Program Name: Lab 1*/ /**/ /* Student Name: J.Q. Public*/ /* Semester: Spring, 2004*/ /* Class & Section: CoSc */ /* Instructor: Dr. James Comer */ /* */ /* Program Overview*/ /* This program displays a string of text in the center*/ /* of the applet window. The text is drawn in blue in*/ /* bold, 16 point Helvetica*/ /* */ /* Input: */ /* There is no input to this program.*/ /**/ /* Output:*/ /* The string of text that is hard coded in the program.*/ /* */ /* Program Limitations:*/ /* The text is centered only if the window is 200 x 200.*/ /**/ /* Significant Program Variables:*/ /* None*/ /**/ /********************************************************************/ import java.awt.*; import javax.swing.*; Import java.applet.; public class MyApplet extends JApplet { public void init() { repaint(); } public void paint(Graphics g) { g.setFont(new Font("Helvetica", Font.BOLD, 16)); g.setColor(Color.blue); g.drawString("Texas Christian University", 5, 100); }

Documentation All programs are to be documented using the Documentation Guidelines and the Documentation Standard provided on the class website. Failure to do so will result in several lost points on your graded lab assignment. Comments should include a detailed “preamble” set of comments (see the standard) and inline documentation (to explain the purpose of the program and to describe processing steps). These are to be positioned within the executable statements of your program. Java comments (which are ignored by the compiler) can take two forms: // comment runs to the end of the line and /* The purpose of this program is …………….. ………………………………………………… ………………………………………………..*/

Documentation Standard /***************************************************************************************************/ /* Program Name: Lab# 3 */ /* */ /* Student Name: John Q. Programmer */ /* Semester: Fall, 1999 */ /* Class & Section: CoSc */ /* Instructor: Dr. Hallie Pena */ /* Due Date: September 23, 1999 */ /* */ /* Program Overview: */ /* This applet uses a text field to accept user input representing a Fahrenheit temperature. */ /* When the user presses the, the temperature is converted to Celsius. the */ /* result is displayed in a label and, in addition, in a text area that serves as an ongoing */ /* log of all conversions that have been performed. The user can continue to perform */ /* terperature conversions until the applet is terminated. */ /* */ /* Input: */ /* Input data must be the integer Fahrenheit value that is to be converted to Celsius. */ /* */ /* Output: */ /* The corresponding Celsius value for the given input data. Past conversions are displayed */ /* in a scrollable text area at the bottom of the display window. */ /* */ /* Program Limitations: */ /* (1) only integer Fahrenheit values may be input for conversion. */ /* (2) care should be taken when inputing values to be converted as the previous input value */ /* remains in the input textfield until erased. */ /* */ /* Significant Program Variables: */ /* title - holds the title that is displayed at the top of the display window. */ /* question - holds the string that is displayed as the user prompt. */ /*... */ /* */ /* References: */ /* (1) this program originally appeared in: "Java Software */ /* Solutions", John Lewis and William Loftus, Addison-Wesley, */ /* 1998, pp */ /***************************************************************************************************/

Terminology for the parts of a Java program consists of classes consist of members (instances of the class) fieldsmethods are variablesobjectsvoidtyped classestypes declared with consist of are constructors parameters fields statements inner classes special typed methods are fields invocation assignment repetition selection exception are program A java