Download presentation
Presentation is loading. Please wait.
Published byClaud Floyd Modified over 9 years ago
1
SE 360 Advances in Software Development Asst.Prof.Dr. Senem Kumova Metin
2
Introduction Instructor : Dr. Senem Kumova Metin Email: senem.kumova@ieu.edu.tr Room: 312 Course website: http://homes.ieu.edu.tr/skumova You have to check website regularly for announcements, homeworks, course slides and projects
3
Assignments Labs and Project Starting next lecture, there will be 1 hour lab time. Bring your laptops!!! In the second part you will do a course project, in Java. – Start thinking about your project now!!! – I leave the topic up to you. – Up to 2 people per group.
4
Syllabus
5
Classification of High level Programming languages Programming paradigm : Alternative approaches to the programming process – Imperative (Procedural) (Fortran, Algol, Pascal, Basic, C) – Functional (Lisp, ML) – Declarative(Logic) (Prolog,GPSS) – Object-Oriented (C++, Java, Scala, Smalltalk)
6
Programming Languages 1/2 Imperative: The language provides statements, such as assignment statements, which explicitly change the state of the memory of the computer. X:=X+1 Functional: In this paradigm we express computations as the evaluation of mathematical functions. (defun factorial (n) (if (<= n 1) 1 (* n (factorial (- n 1))))) The program can then be called as (factorial 10)
7
Programming Languages 2/2 Logic (Declarative): In this paradigm we express computation in exclusively in terms of mathematical logic brother(X,Y) /* X is the brother of Y */ :- /* if there are two people F and M for which*/ father(F,X), /* F is the father of X */ father(F,Y), /* and F is the father of Y */ mother(M,X), /* and M is the mother of X */ mother(M,Y), /* and M is the mother of Y */ male(X). /* and X is male */ uncle (X,Y) :- father(F,Y), brother(X,F ). Object-Oriented: In this paradigm we associate behavior with data-structures called " objects " which belong to classes which are usually structured into a hierarchy
8
What exactly is an object? An OBJECT is an identity which includes both Attributes and Behaviors EXAMPLE -- > PERSON OBJECT Attributes : Eye Color, Age, Height … Behaviors : Walking, Talking, Breathing …
9
The Object Model A OO-software system is a set of cooperating objects Objects have state and processing ability Objects exchange messages
10
Class and Object A class is a collection of objects that have common properties, operations and behaviors. A class is a data type, objects are instances of that data type.
11
Object Oriented Programming A programming paradigm that uses abstraction (in the form of classes and objects) to create models based on the real world environment. An object-oriented application uses a collection of objects, which communicate by passing messages to request services. Objects are capable of passing messages, receiving messages, and processing data. The aim of object-oriented programming is to try to increase the flexibility and maintainability of programs. Because programs created using an OO language are modular, they can be easier to develop, and simpler to understand after development.
12
Java Main topic of the course is Object Oriented Concepts The implementation will be done in Java You will learn Java, and use it in the project I will use Eclipse as the Java IDE – Free IDE, highly popular – Easy to use – The resource links are given in course web page
13
What is Java Java is a high level programming language Uses a virtual machine – Means your code is compiled for the VM and works in any architecture or OS (byte code – Performance penalty due to VM instead of native applications You can write applications or applets using Java Applet is a Java program that works on web pages.
14
Java: Write Once, Run Anywhere Consequence of Java’s history: platform-independence Mac user running Safari Windows user running Internet Explorer Web page stored on Unix server Click on link to Applet Byte code is downloaded Virtual machine translates byte code to native Mac code and the Applet is run Byte code (part of web page) From slides of James Tam
15
Java: Write Once, Run Anywhere Consequence of Java’s history: platform-independent Mac user running Safari Windows user running Internet Explorer Web page stored on Unix server Click on link to AppletByte code is downloaded Virtual machine translates byte code to native Windows code and the Applet is run From slides of James Tam
16
What is Java If you are a C/C++ programmer, Java is easier to code – No pointers – Has a garbage collection mechanism – Built in security Java is object oriented
17
A short history for Java The invention of the microprocessor revolutionized computers (from huge computers to smaller ones ) The next logical step for microprocessors was to have them run in intelligent consumer devices like cable TV switchboxes.. Sun Microsystems funded an internal research project “Green” to investigate this opportunity (~1991) – Result: A programming language called “Oak” JAVA
18
Java versus Java Script Java (this is what you need to know for this course) – A complete programming language developed by Sun – Can be used to develop either web based or stand-alone software – Many pre-created code libraries available – For more complex and powerful programs Java Script (not covered in this course) – A small language that’s mostly used for web-based applications (run through a web browser like Internet Explorer, Firefox, Safari, Chrome) – Good for programming simple special effects for your web page e.g., roll-overs – e.g.,
19
A High Level View Of Translating/Executing Java Programs Java compiler (javac) Java program Filename.java Java bytecode (generic binary) Filename.class Stage 1: Compilation From slides of James Tam
20
A High Level View Of Translating/Executing Java Programs Java interpreter (java) Java bytecode (generic binary) Filename.class Machine language instruction (UNIX) Machine language instruction (Windows) Machine language instruction (Apple) Stage 2: Interpreting and executing the byte code From slides of James Tam
21
Java Instructions Each Java instruction must be followed by a semi-colon! int num = 123; System.out.println(“Hello!");
22
Java Output System.out.print( +..); OR System.out.println( +..); public class OutputExample1 { public static void main (String [] args) { int num = 123; // More on this shortly System.out.println(“Hello!"); // prints to new line System.out.print(num); // prints to current line System.out.println("num="+num); }
23
Output : Some Escape Sequences For Formatting Escape sequenceDescription \tHorizontal tab \rCarriage return \nNew line \”Double quote \\Backslash
24
Variables Variables must be declared before they can be used. Variable declaration: – Creates a variable in memory. – Specify the name of the variable as well as the type of information that it will store. – E.g. int num ; Using variables – Only after a variable has been declared can it be used.
25
Declaring Variables: Syntax Format: ; Example: char myFirstInitial; Variables can be initialized (set to a starting value) as they’re declared: char myFirstInitial = ‘j’; int age = 30;
26
Some Built-In Types Of Variables In Java TypeDescription byte8 bit signed integer short16 bit signed integer int32 bit signed integer long64 bit signed integer float32 bit signed real number double64 bit signed real number char16 bit Unicode character (ASCII and beyond) boolean1 bit true or false value StringA sequence of characters between double quotes ( "" )
27
Location Of Variable Declarations public class { public static void main (String[] args) { // Local variable declarations occur here > : : }
28
Java Constants Reminder: constants are like variables in that they have a name and store a certain type of information but unlike variables they CANNOT change. Format: final = ; Example: final int SIZE = 100;
29
Location Of Constant Declarations public class { public static void main (String[] args) { // Local constant declarations occur here (more later) // Local variable declarations > : : }
30
Java Keywords abstractbooleanbreakbytecasecatchchar classconstcontinuedefaultdodoubleelse extendsfinalfinallyfloatforgotoif implementsimportinstanceofintinterfacelongnative newpackageprivateprotectedpublicreturnshort staticsuperswitchsynchronizedthisthrowthrows transienttryvoidvolatilewhile
31
Common Java Operators / Operator Precedence Precedence level OperatorDescriptionAssociativity 1expression++ expression-- Post-increment Post-decrement Right to left 2++expression --expression + - ! ~ (type) Pre-increment Pre-decrement Unary plus Unary minus Logical negation Bitwise complement Cast Right to left
32
Common Java Operators / Operator Precedence Precedence level OperatorDescriptionAssociativity 3*/%*/% Multiplication Division Remainder/modulus Left to right 4+-+- Addition or String concatenation Subtraction Left to right 5<< >> Left bitwise shift Right bitwise shift Left to right
33
Common Java Operators / Operator Precedence Precedence level OperatorDescriptionAssociativity 6< <= > >= Less than Less than, equal to Greater than Greater than, equal to Left to right 7= != Equal to Not equal to Left to right 8&Bitwise ANDLeft to right 9^Bitwise exclusive ORLeft to right
34
Common Java Operators / Operator Precedence Precedence level OperatorDescriptionAssociativity 10|Bitwise ORLeft to right 11&&Logical ANDLeft to right 12||Logical ORLeft to right
35
Common Java Operators / Operator Precedence Precedence level OperatorDescriptionAssociativity 13= += -= *= /= %= &= ^= |= <<= >>= Assignment Add, assignment Subtract, assignment Multiply, assignment Division, assignment Remainder, assignment Bitwise AND, assignment Bitwise XOR, assignment Bitwise OR, assignment Left shift, assignment Right shift, assignment Right to left
36
Post/Pre Operators public class Order1 { public static void main (String [] args) { int num = 5; System.out.println(num); // 5 num++; System.out.println(num);// 6 ++num; System.out.println(num);//7 System.out.println(++num);//8 System.out.println(num++);//8 }
37
Accessing Pre-Created Java Libraries It’s accomplished by placing an ‘import’ of the appropriate library at the top of your program. Syntax: import ; Example: import java.util.Scanner;
38
Getting Text Input You can use the pre-written methods (functions) in the Scanner class. General structure: import java.util.Scanner; main (String [] args) { Scanner = new Scanner (System.in); =. (); } Creating a scanner object (something that can scan user input) Using the capability of the scanner object (actually getting user input)
39
Getting Text Input (2) import java.util.Scanner; public class MyInput { public static void main (String [] args) { String str1; int num1; Scanner in = new Scanner (System.in); System.out.print ("Type in an integer: "); num1 = in.nextInt (); System.out.print ("Type in a line: "); in.nextLine (); str1 = in.nextLine (); System.out.println ("num1:" +num1 +"\t str1:" + str1); }
40
Useful Methods Of Class Scanner nextInt () nextLong () nextFloat () nextDouble () nextLine () next()
41
Decision Making In Java Java decision making constructs –if –if, else –if, else-if –switch
42
Decision Making: Logical Operators Logical OperationJava AND&& OR|| NOT!
43
Decision Making: If Format: if (Boolean Expression) Body Example: if (x != y) System.out.println("X and Y are not equal"); if ((x > 0) && (y > 0)) { System.out.println("X and Y are positive"); } Indenting the body of the branch is an important stylistic requirement of Java What distinguishes the body is either: 1.A semi colon (single statement branch) 2.Braces (a body that consists of multiple statements)
44
Decision Making: If, Else Format: if (Boolean expression) Body of if else Body of else Example: if (x < 0) System.out.println( " X is negative " ); else System.out.println( " X is non-negative " );
45
Example Program: If-Else import java.util.Scanner; public class BranchingExample1 { public static void main (String [] args) { Scanner in = new Scanner(System.in); final int WINNING_NUMBER = 131313; int playerNumber = -1; System.out.print("Enter ticket number: "); playerNumber = in.nextInt(); if (playerNumber == WINNING_NUMBER) System.out.println("You're a winner!"); else System.out.println("Try again."); }
46
If, Else-If Format: if (Boolean expression) Body of if else if (Boolean expression) Body of first else-if : :: else if (Boolean expression) Body of last else-if else Body of else
47
If, Else-If (2) import java.util.Scanner; public class BranchingExample2 { public static void main (String [] args) { Scanner in = new Scanner(System.in); int gpa = -1; System.out.print("Enter letter grade: "); gpa = in.nextInt();
48
If, Else-If (3) if (gpa == 4) System.out.println("A"); else if (gpa == 3) System.out.println("B"); else if (gpa == 2) System.out.println("C"); else if (gpa == 1) System.out.println("D"); else if (gpa == 0) System.out.println("F"); else System.out.println("Invalid letter grade"); }
49
Alternative To Multiple Else-If’s: Switch Format (character-based switch): switch (character variable name) { case ' ': Body break; case ' ': Body break; : default: Body } 1 The type of variable in the brackets can be a byte, char, short, int or long
50
Alternative To Multiple Else-If’s: Switch (2) Format (integer based switch): switch (integer variable name) { case : Body break; case : Body break; : default: Body } 1 The type of variable in the brackets can be a byte, char, short, int or long
51
Looping Statements Java Pre-test loops For While Java Post-test loop Do-while
52
While Loops Format: while (Boolean expression) Body Example: int i = 1; while (i <= 10) { // Some statements ; i = i + 1; }
53
For Loops Format: for (initialization; Boolean expression; update control) Body Example: for (i = 1; i <= 10; i++) { // some statements i = i + 1; }
54
Post-Test Loop: Do-While Recall: Post-test loops evaluate the Boolean expression after the body of the loop has executed. This means that post test loops will execute one or more times. Pre-test loops generally execute zero or more times.
55
Do-While Loops Format: do Body while (Boolean expression); Example: char ch = 'A'; do { System.out.println(ch); ch++; } while (ch <= ‘D'); Output : A B C D
56
Arrays Arrays are a collection of elements of same type int[] myInt = new int[3]; myInt[0]=1; myInt[1]=2; myInt[2]=3;
57
Arrays (2) Iterating an array : int[] myInt = new int[10]; for (int i=0; i<10; i++) {myInt[i]=i; System.out.println(myInt[i]);}
58
Homeworks Dowload JDK and Eclipse Read Chapter 2 + 3 from you course book..
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.