0% found this document useful (0 votes)
43 views

Introduction To Programming Languages

This document provides information about an introduction to programming languages course. It includes the lecturer's contact details, module assessment components, required textbooks, additional references, class rules, software to be used, module synopsis and learning outcomes, and topics to be covered such as basic concepts, Java elements, objects and classes, methods, control structures, arrays, and two-dimensional arrays.

Uploaded by

Kelven Ooi
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Introduction To Programming Languages

This document provides information about an introduction to programming languages course. It includes the lecturer's contact details, module assessment components, required textbooks, additional references, class rules, software to be used, module synopsis and learning outcomes, and topics to be covered such as basic concepts, Java elements, objects and classes, methods, control structures, arrays, and two-dimensional arrays.

Uploaded by

Kelven Ooi
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 49

Introduction to Programming Languages

Lecturer name: Puan Rosmah Ismail

Email : [email protected]

Office: Staff Room, SEGi ACE


Consultation Hour: Wednesday, 2-5pm
(By appointment)
Module Assessment
 COURSE EVALUATION

 Component 1: Online Test (10%)


 Component 2: Lab exercises (10%)
70%
 Component 3: Quiz (15%)
 Component 4: Assignment (15%)
 Component 5: Mid-term exam (20%)
 Component 6: Final exam (30%)
 To pass
 must attempt both elements
 must achieve at least 80% of attendance.
 Pass mark is 50%
Intro. to Programming Languages
Books: ( reference)

Joyce Farrell, Java Programming Eighth


Edition, 2016, Cencage Learning

Malik D.S., JAVA Programming:


From Problem Analysis to Program
Design, 5th Edition, Course
Technology, 2012.
Intro. to Programming Languages
Books: (Additional reference)
Intro. to Programming Languages

Additional references:
Java How to Program, Eight Edition, Paul Deitel, Harvey
Deitel, Pearson.
Intro. to Programming Languages
Class rules
 Attend class on time

 No talking or surfing during lectures

 Treat your assignments seriously, no second


chance to re-do your assignments
 Submit your assignments on time

 No eating in class

 Ensure good housekeeping of the class before


you leave
Intro. to Programming Languages
Class rules
 Plagiarism is a serious offence
 Rule 1: You must indicate on your submission any assistance you
received.
 Rule 2: You must not share solution sets or actual program code
with other students.
 Rule 3: You must not look at solution sets or program code from
other years.
 Rule 4: You must be prepared to explain any solution sets or
program code you submit.
 Cheating during exam or assignments is a
serious offence
Software to be used in the course
Netbeans IDE 8.0 or above
Module Synopsis
 Introductory course to Java programming with
an emphasis on the program design,
development and application implementation.

 Provides the students with the appropriate


foundation to the development of programming
skills to a level of competence sufficient to
allow them to contribute major programming
projects or for further study.
Module Learning Outcomes
The student will be able :
 Prepare algorithmic solutions to moderately complex
programming problems.
 Use programming tools to implement solutions.
 Explain code conventions, language idioms and
professional programming practice.
 Demonstrate the intelligent use of some of the more
commonly used standard library functions to reduce
programming effort.
 Demonstrate an understanding of the modular
programming process.
 Demonstrate an understanding of fundamental object-
orientated solutions
Intro. to Programming Languages
Topics:
 Basic concepts programming
 The language of computers

 Processing a Java program

 Programming with the Problem Analysis-Coding-


Execution cycles
 Programming Methodologies

 Basic Elements of Java


 Basic of a Java Program

 Data Types

 Arithmetic Operators and Operator Precedence

 Input and Output


Intro. to Programming Languages
Topics:
 Introduction to Objects and Classes
 Objects
 Using Predefined Classes and Methods
 Methods
 Control Structures I: Selection
 Relational Operators
 Logical Operators and Logical Expressions
 Selection: if and if…else
 Switch Structures
 Comparing Strings
Intro. to Programming Languages
Topics:
 Control Structures II: Repetition
 Why is Repetition needed?
 while Looping Structure
 for Looping Structure
 do…while Looping Structure
 Break and continue Statements
 Arrays
 Why Do We Need Arrays?
 Using Arrays
 Arrays of Objects
 Two-Dimensional Arrays
Revision
Given length 5 cm and width 6 cm, calculate and
display the area of a rectangle.

1. Design the algorithm using :


 Flowchart
 Pseudocode

2. Based on the algorithm above, write a Java program


Revision
1. Design an algorithm and write a program to
read two integers and display the total of the
integers.
Revision
Write a pseudocode for the following problem:

1.Display “Hello” for 3 times.


Computer Programming

 Programming can be defined as the


development of a solution to an identified
problem, and the setting up of a related series
of instructions which will produce the desired
results.
Creating Your First Java Classes
Objectives
 Learn about programming
 Be introduced to object-oriented programming concepts
 Learn about Java
 Analyze a Java application that uses console output
 Add comments to a Java class
 Save, compile, run, and modify a Java application
 Create a Java application using GUI output
 Correct errors and find help
Learning About Programming
 Program
 Set of written instructions that tells computer what to do
 Machine language
 Most basic circuitry-level language
 Low-level programming language
 High-level programming language
 Allows you to use vocabulary of reasonable terms
 Syntax
 Rules of language
 Program statements
 Similar to English sentences
 Carry out tasks of program
Learning About Programming
(cont'd)
 Compiler or interpreter
 Translates language statements into machine code

 Syntax error
 Misuse of language

 Misspelled programming language word

 Debugging
 Freeing program of all errors

 Logic errors
 Also called semantic errors

 Incorrect order or procedure


Learning About Java
 Java
 Developed by Sun Microsystems

 Object-oriented language

 General-purpose

 Advantages
 Security features

 Architecturally neutral

 Can be run on wide variety of computers

 Does not execute instructions on computer directly

 Runs on hypothetical computer known as Java virtual


machine (JVM)
Learning About Java (cont‘d)
 Source code
 Programming statements
written in high-level
programming language
 Bytecode
 Statements saved in file

 Java compiler converts


source code into binary
program
 Java interpreter
 Checks bytecode and
communicates with operating
system
 Executes bytecode
instructions line by line
within Java virtual machine
23 Last Updated:February 7, 2021
Compilation Process

Graphic courtesy of Eric Roberts with some changes


Java Program Types
 Applets
 Programs embedded in Web page

 Java applications
 Called Java stand-alone programs

 Console applications

 Support character output

 Windowed applications

 Menus

 Toolbars

 Dialog boxes
Analyzing a Java Application That Uses Console
Output

 Even simplest Java application


 Involves fair amount of confusing syntax

 Print “First Java application” on screen


Understanding the Statement That Prints the
Output
 Literal string
 Will appear in output exactly as entered

 Written between double quotation marks

 Arguments
 Pieces of information passed to method

 Method
 Requires information to perform its task
Understanding the First Class
 Everything used within Java program must be
part of a class
 Define Java class using any name or identifier
 Requirements for identifiers
 Must begin with:
 Letter of English alphabet
 Or non-English letter (such as α or π)

 Cannot begin with digit


Understanding the First Class
(cont'd)
 Requirements for identifiers
 Can only contain:

 Letters

 Digits

 Underscores

 Dollar signs

 Cannot be Java reserved keyword

 Cannot be true, false, or null

 Access modifier
 Defines how class can be accessed
Understanding the First Class
(cont'd)
Understanding the First Class
(cont'd)
Understanding the First Class
(cont'd)
Understanding the main() Method
 static
 Reserved keyword

 Means method accessible and usable

 Even though no objects of class exist

 void
 Use in main() method header

 Does not indicate main() method empty

 Indicates main() method does not return value when


called
 Doesn’t mean main() doesn’t produce output
Shell Code
public class AnyClassName
{
public static void main(String[] args)
{
/********/
}
}
•shellcode
•replace AnyClassName with a class name you choose
•replace the line /********/ with any statement you want to
execute
Adding Comments to a Java Class
 Program comments
 Nonexecuting statements added to program for
documentation
 Use to leave notes for yourself or others

 Include author, date, class’s name or function

 Comment out a statement


 Turn it into a comment

 Compiler does not translate and the JVM does not


execute its command
Adding Comments to a Java Class
(cont'd)
 Types of Java comments
 Line comments
 Start with two forward slashes (//)
 continue to end of current line
 Do not require ending symbol
 Block comments
 Start with forward slash and asterisk (/*)
 End with asterisk and forward slash (*/)
Adding Comments to a Java Class
(cont'd)
 Types of Java comments (cont'd)

 Special case of block comments


 Begin with slash and two asterisks (/**)

 End with asterisk and forward slash (*/)

 Use to generate documentation


Saving, Compiling, and Running
and Modifying a Java Application
 Saving a Java class
 Save class in file with exactly same name and.java
extension
 For public classes

 Class name and filename must match exactly

 Compiling a Java class


 Compile source code into bytecode

 Translate bytecode into executable statements

 Using Java interpreter

 Type javac First.java


Saving, Compiling, and Running
and Modifying a Java Application (cont‘d)

 Compilation outcomes
 javac unrecognized command

 Program language error messages

 No messages indicating successful completion

 Reasons for error messages


 Misspelled command javac

 Misspelled filename

 Not within correct subfolder or subdirectory on command


line
 Java not installed properly
Running a Java Application
 Run application from command line
 Type java First

 Shows application’s output in command window


 Class stored in folder named Java on C drive
Modifying a Java Class
 Modify text file that contains existing class
 Save file with changes
 Using same filename

 Compile class with javac command


 Interpret class bytecode and execute class using
java command
Creating a Java Application Using GUI Output

 JOptionPane
 Produce dialog boxes

 Dialog box
 GUI object resembling window

 Messages placed for display

 Package
 Group of classes

 import statement
 Use to access built-in Java class
Creating a Java Application Using GUI Output
(cont’d)
import javax.swing.JOptionPane;
public class FirstDialog
{
public static void main(String[] args)
{
JOptionPane.showMessageDialog(null, "First Java dialog");
}
}
Correcting Errors and Finding Help
 First line of error message displays:
 Name of file where error found

 Line number

 Nature of error

 Next lines identify:


 Symbol

 Location

 Compile-time error
 Compiler detects violation of language rules

 Refuses to translate class to machine code


Correcting Errors and Finding Help
(cont'd)
 Parsing
 Process compiler uses to divide source code into
meaningful portions
 Logic error
 Syntax correct but produces incorrect results when
executed
 Usually more difficult to find and resolve

 Java API
 Also called the Java class library

 Prewritten Java classes


You Do It
 Your first application
 Adding comments to a class
 Modifying a class
 Creating a dialog box
Don’t Do It
 File’s name must match name of class
 Don’t confuse names parentheses, braces, brackets, curly
braces, square brackets, and angle brackets
 Don’t forget to end a block comment
 Don’t forget that Java is case sensitive
 End every statement with semicolon
 Do not end class or method headers with semicolon

 Recompile when making changes


Summary
 Computer program
 Set of instructions that tells a computer what to do
 Java virtual machine (JVM)
 Standardized hypothetical computer
 Everything in a Java program must be part of a class
 Access modifier
 Word that defines circumstances under which class can be
accessed
Summary (cont‘d)
 All Java applications must have method named main()
 Program comments
 Nonexecuting statements

 Add to file for documentation

 javac
 Compile command

 java
 Execute command
 JOptionPane
 GUI
 Provides methods for creating dialogs

You might also like