SlideShare a Scribd company logo
1 of 52
INTRODUCTION TOCOMPUTER SCIENCE
CSC 1302
LECTURE 6
Department of Maths and Computer-
Science
Faculty of Natural and Applied Science
BY
UMAR DANJUMA MAIWADA
OBJECTIVES
 Programing tools
 Computer programming
 Programming language levels
 Introduction to JAVA language
 Syntax of JAVA
2
PSEUDOCODE
 Pseudocode is an abbreviated version of
actual computer code (hence, pseudocode).
The geometric symbols used in flowcharts
are replaced by English-like statements that
outline the process.
 Pseudocode allows the programmer to
focus on the steps required to solve a
problem rather than on how to use the
computer language.
 Pseudocode has several advantages. It is
compact and probably will not extend for
many pages as flowcharts commonly do.
3
PROGRAMMING TOOLS
 A programming tool may be any software program
or utility that aids software developers or
programmers in creating, editing, debugging,
maintaining and/or performing any programming or
development-specific task.
 Programming tools were initially designed to
support or complement programming languages by
providing the functionality and features these
languages did not have.
 Compilers, linkers, assemblers, disassemblers,
load testers, performance analysts, GUI
development tools and code editors are also all
forms of programming tools.
4
COMPUTER PROGRAMMING
 Programming is all about designing and coding algorithm
for solving problems.
 Computers are not very intelligent, the instruction they
receive must be extraordinary special.
 We write computer instructions in programming
languages, which are more constrained and exact than
human languages are.
 It must follow a series of algorithm.
 As a programmer your job is to decompose a task into
individual, ordered steps of input, calculating, comparing,
rearranging and outputting.
 The order in which the individual statements, instructions
or function calls of an imperative or a declarative
program are executed or evaluated by the computer is
5
THERE ARE FOUR DIFFERENT WAYS THAT THE
FLOW OF CONTROL CAN PROGRESS THROUGH A
PROGRAM.
 Sequential execution
 Method call
 Selection
 Looping
6
PROGRAMMING LANGUAGE LEVELS
1. Machine languages
2. Assembly languages
3. High-level languages
 The following section of an assembly-language
program also adds overtime pay to base pay and
stores the result in gross pay, but somewhat more
clearly than its machine-language equivalent.
 LOAD BASEPAY
 ADD OVERPAY
 STORE GROSSPAY 7
Machine Instruction Machine Operation
00000000 Stop Program
00000001 Turn bulb fully on
00000010 Turn bulb fully off
00000100 Dim bulb by 10%
00001000 Brighten bulb by 10%
00010000 If bulb is fully on, skip over next instruction
00100000 If bulb is fully off, skip over next instruction
01000000 Go to start of program (address 0)
INTRODUCTION TO JAVA LANGUAGE
 Java was developed by a team lead by James gosling
at microsystem. Originally called Oak.
 It was designed in 1991 for used in embedded
consumer appliance.
 In 1995, renamed Java. It was designed for
developing internet applications
 Java is a full-featured, general purpose programming
language that is capable of developing robust
mission-critical applications. Today, it is used not only
for web programming, but also for developing
standalone applications across platforms on server,
desktops, and mobile devices. 9
BENEFITS OF USING JAVA
 Syntax identical to that of C++, except that java
eliminates some of the C++’s more complex features
 Object orientation
 Internet-related features, such as applets, which are
run by the browser, and servlets, which are run by the
web server.
 An extensive library of classes that can be reused
readily, including swing classes for providing graphical
user interface and java database connectivity (JDBC)
for communication with a database.
 Portability among every platform that supports a java
virtual machine
 Built-in networking
 Open source availability of the java development kits
10
SYNTAX OF JAVA PROGRAM
 /*
 This is a simple syntax of Java program.
 Call this file classname.java.
 */
 class classname {
 // A Java program begins with a call to main().
 public static void main(String args[]) {
 statement1;
 statement2;
 …
 …
 Statementn;
 }
 }
11
THREE STEPS
 Enter the program.
 Compile the program.
 Run the program
12
EXAMPLE 1
1. Public class Hello
2. {
3. /**
4. * My first program in java
5. */
6. public static void main(String [] args) {
7. // prints the string “Hello World” on screen
8. System.out.println(“Hello World”);
9. }
10. } 13
ANALYZING MY FIRST PROGRAM IN JAVA
1. Public class Hello
2. {
3. /**
4. * My first program in java
5. */
• Indicates the name of the class which is Hello
• In java all codes should be placed inside a class
declaration
• The class uses an access specifier public, which
indicates that
our class is accessible to other class in other package
(collection of class). Package and access specifier
will be
14
1. PUBLIC CLASS HELLO
2. {
3. /**
4. * MY FIRST PROGRAM IN JAVA
5. */
• THE SECOND LINE CONTAINS A CURLY BRACE {
WHICH INDICATE THE START OF A
BLOCK.
• IN THIS CODE WE PLACED THE CURLY BRACE AT
THE NEXT LINE AFTER THE CLASS
DECLARATION, HOWEVER, WE CAN ALSO PLACED
THIS NEXT TO THE FIRST LINE OF
OUR CODE, SO WE COULD ACTUALLY WRITE OUR
CODE AS
PUBLIC CLASS HELLO{
15
1. PUBLIC CLASS HELLO
2. {
3. /**
4. * MY FIRST PROGRAM IN JAVA
5. */
• THE NEXT THREE LINES INDICATES A JAVA
COMMENT
• A COMMENT
- SOMETHING USED TO DOCUMENT A PART OF A
CODE
- IT IS NOT PART OF THE PROGRAM ITSELF, BUT
ONLY FOR
DOCUMENTATION PURPOSE
- IT IS A GOOD PROGRAMING PRACTICE TO ADD A
COMMENT TO YOUR CODE 16
1. PUBLIC CLASS HELLO
2. {
3. /**
4. * MY FIRST PROGRAM IN JAVA
5. */
6. PUBLIC STATIC VOID MAIN(STRING [] ARGS) {
• INDICATES THE NAME OF THE METHOD IN HELLO
CLASS WHICH IS THE
MAIN METHOD
• ALL PROGRAMS EXCEPT APPLET (TO BE DISCUSS
LATER IN THIS COURSE)
WRITTEN IN JAVA STARTS WITH THE MAIN METHOD
• BE CAREFUL TO FOLLOW THE SYNTAX 17
1. PUBLIC CLASS HELLO
2. {
3. /**
4. * MY FIRST PROGRAM IN JAVA
5. */
6. PUBLIC STATIC VOID MAIN(STRING [] ARGS)
{
7. // PRINTS THE STRING “HELLO WORLD”
ON SCREEN
• THIS IS ALSO A COMMENT IN JAVA
18
1. PUBLIC CLASS HELLO
2. {
3. /**
4. * MY FIRST PROGRAM IN JAVA
5. */
6. PUBLIC STATIC VOID MAIN(STRING [] ARGS)
{
7. // PRINTS THE STRING “HELLO WORLD” ON
SCREEN
8. SYSTEM.OUT.PRINTLN(“HELLO WORLD”);
• THIS COMMAND SYSTEM.OUT.PRINTLN(),
PRINTS THE TEXT ENCLOSED
BY QUOTATION ON THE SCREEN 19
1. PUBLIC CLASS HELLO
2. {
3. /**
4. * MY FIRST PROGRAM IN JAVA
5. */
6. PUBLIC STATIC VOID MAIN(STRING [] ARGS) {
7. // PRINTS THE STRING “HELLO WORLD” ON
SCREEN
8. SYSTEM.OUT.PRINTLN(“HELLO WORLD”);
9. }
10. }
• THE LAST TWO LINES CONTAINING THE CURLY
BRACES ARE USED TO CLOSE THE
MAIN METHOD AND THE CLASS RESPECTIVELY 20
THE MAIN METHOD
main method can be written in any of the following forms:
public static void main(String [] args)
or
public static void main(String args [])
 the public keyword is an access specifier.
 The keyword static allow main() to be called without
having to
instantiate a particular instance of the class
+ This is necessary since main() is called by the java
interpreter before any object is made
 void means main() does not return any value.
 String args[] declares a parameter named args, which
is an array of
instance of the class String.
+ args receive any command line arguments presents
when the program executed
21
JAVA KEYWORDS
 They are predefined identifiers reserved by java
for a specific purpose.
 They can not be used as a names of variables,
classes, methods, etc.
22
JAVA KEYWORDS
 double, int, super, abstract
 Boolean, switch, else, interface
 Break, extends, long, synchronized
 Case, finally, null, throw
 Byte, false, native, this
 Catch, float, package, transient
 Byvalue, final, threadsafe, new
 For, private, true, class
 If, public, void, char
 Class, protected, goto, try
 While, continue, implement, break
 Else, case, string, return
 Static, short, import, default 23
PRIMITIVE DATA TYPE
 • The Java programming language defines eight
primitive data
types.
 – boolean (for logical)
 – char (for textual)
 – byte
 – short
 – int
 – long (integral)
 – double
 – float (floating point).
24
VARIABLE
 A variable is a named memory location that can be
assigned a value.
 As you learned earlier, variables are declared using
this form of statement,
type var-name;
 A variable is an item of data used to store the state
of objects.
 A variable has a:
– data type
 The data type indicates the type of value that the
variable can hold.
– name
 The variable name must follow rules for identifiers.
Declaration and Initializing variable
 Declare a variable as follows:
25
HOW TO INITIALIZE VARIABLE
 . One way to give a variable a value is through an
assignment statement, as you have already seen.
 To do this, follow the variable’s name with an equal sign
and the value being assigned.
 The general form of initialization is shown here:
type varname = value;
 int count = 10; // give count an initial value of 10
 char ch = 'X'; // initialize ch with the letter X
 float f = 1.2F; // f is initialized with 1.2
 When declaring two or more variables of the same type
using a comma-separated list, you can give one or more of
those variables an initial value. For example:
 int a, b = 8, c = 19, d; // b and c have initializations
 In this case, only b and c are initialized.
 Int a = 3, b = 8, c = 19; //a, b, c all have initializations
 In this case a, b, c are initialized.
26
DECLARING AND INITIALIZING VARIABLES
SAMPLE PROGRAM
1. public class VariableSamples {
2. public static void main( String[] args ){
3. //declare a data type with variable name
4. // result and boolean data type
5. boolean result;
6.
7. //declare a data type with variable name
8. // option and char data type
9. char option;
10. option = 'C'; //assign 'C' to option
11.
12. //declare a data type with variable name
13. //grade, double data type and initialized
14. //to 0.0
15. double grade = 0.0;
16. }
17. }
27
EXAMPLE 2
28
 The following program creates two
variables called x and y.
 /*
 This demonstrates a variable.
 Call this file Example2.java.
 */
 class Example2 {
 public static void main(String args[]) {
 int x; // this declares a variable
 int y; // this declares another variable
 x = 1024; // this assigns 1024 to x
 System.out.println("x contains " + x);
 y = x / 2;
 System.out.print("y contains x / 2: ");
 System.out.print(y);
 }
 }
 When you run this program, you will
see the following output:
 x contains 1024
 y contains x / 2: 512
DECLARING AND INITIALIZING VARIABLES:
CODING GUIDELINES
1. It always good to initialize your variables as you declare
them.
2. Use descriptive names for your variables. Like for
example, if
you want to have a variable that contains a grade for a
student, name it as, grade and not just some random
letters you choose.
3. Declare one variable per line of code. For example, the
variable declarations,
double exam=0;
double quiz=10;
double grade = 0;
is preferred over the declaration,
double exam=0, quiz=10, grade=0;
29
OUTPUTTING VARIABLE DATA
• In order to output the value of a certain variable, we can use the following
commands:
System.out.println()
System.out.print()
Sample program
1. public class OutputVariable {
2. public static void main( String[] args ){
3. int value = 10;
4. char x;
5. x =
6.
7. System.out.println( value );
8. System.out.println(
9. }
10. }
The program will output the following text on screen:
10
The value of x=A
30
OPERATORS
• Different types of operators:
– arithmetic operators
– relational operators
– logical operators
– conditional operators
• These operators follow a certain kind of precedence
so that the compiler will
know which operator to evaluate first in case multiple
operators are used in
one statement.
31
ARITHMETIC OPERATORS
operator Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
++ Increment
-- decrement
32
EXAMPLE 3
33
The following program demonstrates the
modulus operator.
// Demonstrate the % operator.
class ModDemo {
public static void main(String args[]) {
int iresult, irem;
double dresult, drem;
iresult = 10 / 3;
irem = 10 % 3;
dresult = 10.0 / 3.0;
drem = 10.0 % 3.0;
System.out.println("Result and remainder of 10 /
3 = " + iresult + " " + irem);
System.out.println("Result and remainder of
10.0 / 3.0 = " + dresult + " " + drem);
}
}
The output from the program is shown
here are:
Result and remainder of 10 / 3 = 3 1
Result and remainder of 10.0 / 3.0 =
3.3333333333333335 1.0
As you can see, the% yields a
remainder of 1 for both integer and
floating-point operations.
RELATIONAL OPERATORS
• Relational operators compare two values and
determines the relationship
between those values.
• The output of evaluation are the boolean values true
or false.
34
CONTROL STATEMENTS
 Java Control statements control the order of
execution in a java program, based on
data values and conditional logic.
 There are three main categories of control flow
statements;
· Selection statements: if, if-else and switch.
· Loop statements: while, do-while and for.
· Transfer statements: break, continue, return, try-
catch-finally and assert.
35
SELECTION STATEMENTS
 The If Statement
 The if statement executes a block of code only if
the specified expression is true. If the value is false,
then the if block is skipped and execution continues with
the rest of the program. You can either have a single
statement or a block of code within an if statement.
 if (<conditional expression>)
<statement action>
36
37
public class IfStatementDemo {
public static void main(String[] args) {
int a = 10, b = 20;
if (a > b)
System.out.println("a > b");
if (a < b)
System.out.println("b > a");
}
}
The program will print b > a
THE IF-ELSE STATEMENT
 The if/else statement is an extension of the if
statement. If the statements in the if statement fails,
the statements in the else block are executed. You
can either have a single statement or a block
of code within if-else blocks.
 The if-else statement has the following syntax:
if (<conditional expression>)
<statement action>
else
<statement action>
38
39
public class IfElseStatementDemo {
public static void main(String[] args) {
int a = 10, b = 20;
if (a > b) {
System.out.println("a > b");
} else {
System.out.println("b > a");
}
}
}
Output displays b > a
SWITCH CASE STATEMENT
 The switch case statement, also called a case statement is a
multi-way branch with several choices. A switch is easier to
implement than a series of if/else statements. The switch
statement begins with a keyword, followed by an expression
that equates to a no long integral value. Following the
controlling expression is a code block that contains zero or
more labelled cases. Each label must equate to an
integer constant and each must be unique. When the switch
statement executes, it compares the value of the controlling
expression to the values of each case label.
 switch (<non-long integral expression>) {
case label1: <statement1>
case label2: <statement2>
…
case labeln: <statementn>
default: <statement>
} // end switch
40
41
public class SwitchCaseStatementDemo {
public static void main(String[] args) {
int a = 10, b = 20, c = 30;
int status = -1;
if (a > b && a > c) {
status = 1;
} else if (b > c) {
status = 2;
} else {
status = 3;
}
switch (status) {
case 1:
System.out.println("a is the greatest");
break;
case 2:
System.out.println("b is the greatest");
break;
case 3:
System.out.println("c is the greatest");
break;
default:
System.out.println("Cannot be determined");
}
}
}
Output displayed is: c is the greatest
ITERATION STATEMENTS
While Statement
 The while statement is a looping construct control
statement that executes a block of code while a
condition is true. You can either have
a single statement or a block of code within the
while loop. The loop will never be executed if the
testing expression evaluates to false.
 The syntax of the while loop is
while (<loop condition>)
<statements>
42
43
public class WhileLoopDemo {
public static void main(String[] args) {
int count = 1;
System.out.println("Printing Numbers from 1 to
10"); while (count <= 10) {
System.out.println(count++); } }}
Output
Printing Numbers from 1 to 10
1
2
3
4
5
6
7
8
9
10
DO-WHILE LOOP STATEMENT
 The do-while loop is similar to the while loop,
except that the test is performed at the end of the
loop instead of at the beginning.
This ensures that the loop will be executed at least
once. A do-while loop begins with the keyword do,
followed by the statements that make up the body
of the loop.
 The syntax of the do-while loop is
do
<loop body>
while (<loop condition>);
44
45
public class DoWhileLoopDemo {
public static void main(String[] args) {
int count = 1;
System.out.println("Printing Numbers from 1 to 10");
do {
System.out.println(count++);
}
while (count <= 10);
}}
Output
Printing Numbers from 1 to 10
1
2
3
4
5
6
7
8
9
10
FOR LOOPS
 The for loop is a looping construct which can
execute a set of instructions a specified number of
times. It’s a counter controlled loop.
 The syntax of the loop is as follows:
for (<initialization>; <loop condition>;
<increment expression>)
<loop body>
46
47
public class ForLoopDemo {
public static void main(String[] args) {
System.out.println("Printing Numbers from 1 to
10"); for (int count = 1; count <= 10; count++) {
System.out.println(count); }
}}
Output
Printing Numbers from 1 to 10
1
2
3
4
5
6
7
8
9
10
TRANSFER STATEMENTS
Continue Statement
 A continue statement stops the iteration of a loop
(while, do or for) and causes execution to
resume at the topof the nearest enclosing loop. You
use a continue statement when you do not want to
execute the remaining statements in the loop, but
you do not want to exit the loop itself.
 The syntax of the continue statement is
continue; // the unlabeled form
continue <label>; // the labeled form
48
49
public class ContinueExample {
public static void main(String[] args) {
System.out.println("Odd Numbers");
for (int i = 1; i <= 10; ++i) {
if (i % 2 == 0)
continue;
// Rest of loop body skipped when i is even
System.out.println(i + "t"); } }}
Output
Odd Numbers
1
3
5
7
9
BREAK STATEMENT
 The break statement transfers control out of
the enclosing loop ( for, while, do or
switch statement). You use a break statement when
you want to jump immediately to
the statement following the enclosing control
structure. You can also provide a loop with a label,
and then use the label in your break statement.
 The Syntax for break statement is as shown below;
break; // the unlabeled form
break <label>; // the labeled form
50
51
public class BreakExample {
public static void main(String[] args) {
System.out.println("Numbers 1 - 10");
for (int i = 1;; ++i) {
if (i == 11)
break;
// Rest of loop body skipped when i is even
System.out.println(i + "t");
} }}
Output
Numbers 1 – 10
1
2
3
4
5
6
7
8
9
10
QUESTIONS???
THANK YOU FOR YOUR ATTENTION
52

More Related Content

What's hot

Chapter 13.1.11
Chapter 13.1.11Chapter 13.1.11
Chapter 13.1.11patcha535
 
Interface java
Interface java Interface java
Interface java atiafyrose
 
Module 05 Preprocessor and Macros in C
Module 05 Preprocessor and Macros in CModule 05 Preprocessor and Macros in C
Module 05 Preprocessor and Macros in CTushar B Kute
 
Basic construction of c
Basic construction of cBasic construction of c
Basic construction of ckinish kumar
 
Ooabap notes with_programs
Ooabap notes with_programsOoabap notes with_programs
Ooabap notes with_programsKranthi Kumar
 
Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1sotlsoc
 
Interfaces in JAVA !! why??
Interfaces in JAVA !!  why??Interfaces in JAVA !!  why??
Interfaces in JAVA !! why??vedprakashrai
 
SULTHAN's - C Programming Language notes
SULTHAN's - C Programming Language notesSULTHAN's - C Programming Language notes
SULTHAN's - C Programming Language notesSULTHAN BASHA
 
Chapter 2.4
Chapter 2.4Chapter 2.4
Chapter 2.4sotlsoc
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directivesVikash Dhal
 
Big Java Chapter 1
Big Java Chapter 1Big Java Chapter 1
Big Java Chapter 1Maria Joslin
 
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...Akhil Mittal
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c languagetanmaymodi4
 

What's hot (19)

Basics1
Basics1Basics1
Basics1
 
Java interface
Java interfaceJava interface
Java interface
 
Chapter 13.1.11
Chapter 13.1.11Chapter 13.1.11
Chapter 13.1.11
 
Interface java
Interface java Interface java
Interface java
 
Module 05 Preprocessor and Macros in C
Module 05 Preprocessor and Macros in CModule 05 Preprocessor and Macros in C
Module 05 Preprocessor and Macros in C
 
Preprocessors
Preprocessors Preprocessors
Preprocessors
 
Programming by imitation
Programming by imitationProgramming by imitation
Programming by imitation
 
Basic construction of c
Basic construction of cBasic construction of c
Basic construction of c
 
Ooabap notes with_programs
Ooabap notes with_programsOoabap notes with_programs
Ooabap notes with_programs
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1
 
Interfaces in JAVA !! why??
Interfaces in JAVA !!  why??Interfaces in JAVA !!  why??
Interfaces in JAVA !! why??
 
SULTHAN's - C Programming Language notes
SULTHAN's - C Programming Language notesSULTHAN's - C Programming Language notes
SULTHAN's - C Programming Language notes
 
Chapter 2.4
Chapter 2.4Chapter 2.4
Chapter 2.4
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directives
 
Java Programming Assignment
Java Programming AssignmentJava Programming Assignment
Java Programming Assignment
 
Big Java Chapter 1
Big Java Chapter 1Big Java Chapter 1
Big Java Chapter 1
 
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c language
 

Similar to lecture 6

Similar to lecture 6 (20)

Basics of java 1
Basics of java 1Basics of java 1
Basics of java 1
 
a basic java programming and data type.ppt
a basic java programming and data type.ppta basic java programming and data type.ppt
a basic java programming and data type.ppt
 
Unit of competency
Unit of competencyUnit of competency
Unit of competency
 
Java lab1 manual
Java lab1 manualJava lab1 manual
Java lab1 manual
 
java intro.pptx.pdf
java intro.pptx.pdfjava intro.pptx.pdf
java intro.pptx.pdf
 
Introduction
IntroductionIntroduction
Introduction
 
01slide
01slide01slide
01slide
 
01slide
01slide01slide
01slide
 
java
javajava
java
 
Java lab-manual
Java lab-manualJava lab-manual
Java lab-manual
 
Java for Mainframers
Java for MainframersJava for Mainframers
Java for Mainframers
 
Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6
 
Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6
 
(Ebook pdf) java programming language basics
(Ebook pdf)   java programming language basics(Ebook pdf)   java programming language basics
(Ebook pdf) java programming language basics
 
Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6
 
Java programming language basics
Java programming language basicsJava programming language basics
Java programming language basics
 
Unit2 java
Unit2 javaUnit2 java
Unit2 java
 
JAVA_BASICS.ppt
JAVA_BASICS.pptJAVA_BASICS.ppt
JAVA_BASICS.ppt
 
Intro to programing with java-lecture 1
Intro to programing with java-lecture 1Intro to programing with java-lecture 1
Intro to programing with java-lecture 1
 
Professional-core-java-training
Professional-core-java-trainingProfessional-core-java-training
Professional-core-java-training
 

More from umardanjumamaiwada (20)

Seminar Information Protection & Computer Security (Cryptography).pptx
Seminar Information Protection & Computer Security  (Cryptography).pptxSeminar Information Protection & Computer Security  (Cryptography).pptx
Seminar Information Protection & Computer Security (Cryptography).pptx
 
Oop using JAVA
Oop using JAVAOop using JAVA
Oop using JAVA
 
C++
C++ C++
C++
 
Computer hardware
Computer hardware Computer hardware
Computer hardware
 
2javascript web programming with JAVA script
2javascript web programming with JAVA script2javascript web programming with JAVA script
2javascript web programming with JAVA script
 
1 web programming
1 web programming1 web programming
1 web programming
 
0 csc 3311 slide internet programming
0 csc 3311 slide internet programming0 csc 3311 slide internet programming
0 csc 3311 slide internet programming
 
0 lecture 6 wp wireless protocol
0 lecture 6 wp wireless protocol0 lecture 6 wp wireless protocol
0 lecture 6 wp wireless protocol
 
0 lecture 5 wp wireless protocol
0 lecture 5 wp wireless protocol0 lecture 5 wp wireless protocol
0 lecture 5 wp wireless protocol
 
0 lecture 4 wp wireless protocol
0 lecture 4 wp wireless protocol0 lecture 4 wp wireless protocol
0 lecture 4 wp wireless protocol
 
0 lecture 3 wp wireless protocol
0 lecture 3 wp wireless protocol0 lecture 3 wp wireless protocol
0 lecture 3 wp wireless protocol
 
0 lecture 2 wp wireless protocol
0 lecture 2 wp wireless protocol0 lecture 2 wp wireless protocol
0 lecture 2 wp wireless protocol
 
0 lecture 1 wp wireless protocol
0 lecture 1 wp wireless protocol0 lecture 1 wp wireless protocol
0 lecture 1 wp wireless protocol
 
lecture 5
 lecture 5 lecture 5
lecture 5
 
lecture 4
 lecture 4 lecture 4
lecture 4
 
lecture 3
 lecture 3  lecture 3
lecture 3
 
lecture 2
 lecture 2 lecture 2
lecture 2
 
lecture 1
 lecture 1 lecture 1
lecture 1
 
lecture 5
 lecture 5 lecture 5
lecture 5
 
lecture 4
 lecture 4 lecture 4
lecture 4
 

Recently uploaded

Grafana in space: Monitoring Japan's SLIM moon lander in real time
Grafana in space: Monitoring Japan's SLIM moon lander  in real timeGrafana in space: Monitoring Japan's SLIM moon lander  in real time
Grafana in space: Monitoring Japan's SLIM moon lander in real timeSatoshi NAKAHIRA
 
Analytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptxAnalytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptxSwapnil Therkar
 
BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.
BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.
BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.PraveenaKalaiselvan1
 
Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...
Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...
Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...lizamodels9
 
Twin's paradox experiment is a meassurement of the extra dimensions.pptx
Twin's paradox experiment is a meassurement of the extra dimensions.pptxTwin's paradox experiment is a meassurement of the extra dimensions.pptx
Twin's paradox experiment is a meassurement of the extra dimensions.pptxEran Akiva Sinbar
 
Microphone- characteristics,carbon microphone, dynamic microphone.pptx
Microphone- characteristics,carbon microphone, dynamic microphone.pptxMicrophone- characteristics,carbon microphone, dynamic microphone.pptx
Microphone- characteristics,carbon microphone, dynamic microphone.pptxpriyankatabhane
 
Harmful and Useful Microorganisms Presentation
Harmful and Useful Microorganisms PresentationHarmful and Useful Microorganisms Presentation
Harmful and Useful Microorganisms Presentationtahreemzahra82
 
TOPIC 8 Temperature and Heat.pdf physics
TOPIC 8 Temperature and Heat.pdf physicsTOPIC 8 Temperature and Heat.pdf physics
TOPIC 8 Temperature and Heat.pdf physicsssuserddc89b
 
Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Nistarini College, Purulia (W.B) India
 
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxSOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxkessiyaTpeter
 
insect anatomy and insect body wall and their physiology
insect anatomy and insect body wall and their  physiologyinsect anatomy and insect body wall and their  physiology
insect anatomy and insect body wall and their physiologyDrAnita Sharma
 
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptx
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptxLIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptx
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptxmalonesandreagweneth
 
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Solution chemistry, Moral and Normal solutions
Solution chemistry, Moral and Normal solutionsSolution chemistry, Moral and Normal solutions
Solution chemistry, Moral and Normal solutionsHajira Mahmood
 
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.aasikanpl
 
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSpermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSarthak Sekhar Mondal
 
Call Girls in Hauz Khas Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Hauz Khas Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Hauz Khas Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Hauz Khas Delhi 💯Call Us 🔝9953322196🔝 💯Escort.aasikanpl
 
Heredity: Inheritance and Variation of Traits
Heredity: Inheritance and Variation of TraitsHeredity: Inheritance and Variation of Traits
Heredity: Inheritance and Variation of TraitsCharlene Llagas
 
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |aasikanpl
 
THE ROLE OF PHARMACOGNOSY IN TRADITIONAL AND MODERN SYSTEM OF MEDICINE.pptx
THE ROLE OF PHARMACOGNOSY IN TRADITIONAL AND MODERN SYSTEM OF MEDICINE.pptxTHE ROLE OF PHARMACOGNOSY IN TRADITIONAL AND MODERN SYSTEM OF MEDICINE.pptx
THE ROLE OF PHARMACOGNOSY IN TRADITIONAL AND MODERN SYSTEM OF MEDICINE.pptxNandakishor Bhaurao Deshmukh
 

Recently uploaded (20)

Grafana in space: Monitoring Japan's SLIM moon lander in real time
Grafana in space: Monitoring Japan's SLIM moon lander  in real timeGrafana in space: Monitoring Japan's SLIM moon lander  in real time
Grafana in space: Monitoring Japan's SLIM moon lander in real time
 
Analytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptxAnalytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptx
 
BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.
BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.
BIOETHICS IN RECOMBINANT DNA TECHNOLOGY.
 
Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...
Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...
Best Call Girls In Sector 29 Gurgaon❤️8860477959 EscorTs Service In 24/7 Delh...
 
Twin's paradox experiment is a meassurement of the extra dimensions.pptx
Twin's paradox experiment is a meassurement of the extra dimensions.pptxTwin's paradox experiment is a meassurement of the extra dimensions.pptx
Twin's paradox experiment is a meassurement of the extra dimensions.pptx
 
Microphone- characteristics,carbon microphone, dynamic microphone.pptx
Microphone- characteristics,carbon microphone, dynamic microphone.pptxMicrophone- characteristics,carbon microphone, dynamic microphone.pptx
Microphone- characteristics,carbon microphone, dynamic microphone.pptx
 
Harmful and Useful Microorganisms Presentation
Harmful and Useful Microorganisms PresentationHarmful and Useful Microorganisms Presentation
Harmful and Useful Microorganisms Presentation
 
TOPIC 8 Temperature and Heat.pdf physics
TOPIC 8 Temperature and Heat.pdf physicsTOPIC 8 Temperature and Heat.pdf physics
TOPIC 8 Temperature and Heat.pdf physics
 
Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...
 
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxSOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
 
insect anatomy and insect body wall and their physiology
insect anatomy and insect body wall and their  physiologyinsect anatomy and insect body wall and their  physiology
insect anatomy and insect body wall and their physiology
 
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptx
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptxLIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptx
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptx
 
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
 
Solution chemistry, Moral and Normal solutions
Solution chemistry, Moral and Normal solutionsSolution chemistry, Moral and Normal solutions
Solution chemistry, Moral and Normal solutions
 
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
 
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSpermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
 
Call Girls in Hauz Khas Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Hauz Khas Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Hauz Khas Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Hauz Khas Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
 
Heredity: Inheritance and Variation of Traits
Heredity: Inheritance and Variation of TraitsHeredity: Inheritance and Variation of Traits
Heredity: Inheritance and Variation of Traits
 
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
 
THE ROLE OF PHARMACOGNOSY IN TRADITIONAL AND MODERN SYSTEM OF MEDICINE.pptx
THE ROLE OF PHARMACOGNOSY IN TRADITIONAL AND MODERN SYSTEM OF MEDICINE.pptxTHE ROLE OF PHARMACOGNOSY IN TRADITIONAL AND MODERN SYSTEM OF MEDICINE.pptx
THE ROLE OF PHARMACOGNOSY IN TRADITIONAL AND MODERN SYSTEM OF MEDICINE.pptx
 

lecture 6

  • 1. INTRODUCTION TOCOMPUTER SCIENCE CSC 1302 LECTURE 6 Department of Maths and Computer- Science Faculty of Natural and Applied Science BY UMAR DANJUMA MAIWADA
  • 2. OBJECTIVES  Programing tools  Computer programming  Programming language levels  Introduction to JAVA language  Syntax of JAVA 2
  • 3. PSEUDOCODE  Pseudocode is an abbreviated version of actual computer code (hence, pseudocode). The geometric symbols used in flowcharts are replaced by English-like statements that outline the process.  Pseudocode allows the programmer to focus on the steps required to solve a problem rather than on how to use the computer language.  Pseudocode has several advantages. It is compact and probably will not extend for many pages as flowcharts commonly do. 3
  • 4. PROGRAMMING TOOLS  A programming tool may be any software program or utility that aids software developers or programmers in creating, editing, debugging, maintaining and/or performing any programming or development-specific task.  Programming tools were initially designed to support or complement programming languages by providing the functionality and features these languages did not have.  Compilers, linkers, assemblers, disassemblers, load testers, performance analysts, GUI development tools and code editors are also all forms of programming tools. 4
  • 5. COMPUTER PROGRAMMING  Programming is all about designing and coding algorithm for solving problems.  Computers are not very intelligent, the instruction they receive must be extraordinary special.  We write computer instructions in programming languages, which are more constrained and exact than human languages are.  It must follow a series of algorithm.  As a programmer your job is to decompose a task into individual, ordered steps of input, calculating, comparing, rearranging and outputting.  The order in which the individual statements, instructions or function calls of an imperative or a declarative program are executed or evaluated by the computer is 5
  • 6. THERE ARE FOUR DIFFERENT WAYS THAT THE FLOW OF CONTROL CAN PROGRESS THROUGH A PROGRAM.  Sequential execution  Method call  Selection  Looping 6
  • 7. PROGRAMMING LANGUAGE LEVELS 1. Machine languages 2. Assembly languages 3. High-level languages  The following section of an assembly-language program also adds overtime pay to base pay and stores the result in gross pay, but somewhat more clearly than its machine-language equivalent.  LOAD BASEPAY  ADD OVERPAY  STORE GROSSPAY 7
  • 8. Machine Instruction Machine Operation 00000000 Stop Program 00000001 Turn bulb fully on 00000010 Turn bulb fully off 00000100 Dim bulb by 10% 00001000 Brighten bulb by 10% 00010000 If bulb is fully on, skip over next instruction 00100000 If bulb is fully off, skip over next instruction 01000000 Go to start of program (address 0)
  • 9. INTRODUCTION TO JAVA LANGUAGE  Java was developed by a team lead by James gosling at microsystem. Originally called Oak.  It was designed in 1991 for used in embedded consumer appliance.  In 1995, renamed Java. It was designed for developing internet applications  Java is a full-featured, general purpose programming language that is capable of developing robust mission-critical applications. Today, it is used not only for web programming, but also for developing standalone applications across platforms on server, desktops, and mobile devices. 9
  • 10. BENEFITS OF USING JAVA  Syntax identical to that of C++, except that java eliminates some of the C++’s more complex features  Object orientation  Internet-related features, such as applets, which are run by the browser, and servlets, which are run by the web server.  An extensive library of classes that can be reused readily, including swing classes for providing graphical user interface and java database connectivity (JDBC) for communication with a database.  Portability among every platform that supports a java virtual machine  Built-in networking  Open source availability of the java development kits 10
  • 11. SYNTAX OF JAVA PROGRAM  /*  This is a simple syntax of Java program.  Call this file classname.java.  */  class classname {  // A Java program begins with a call to main().  public static void main(String args[]) {  statement1;  statement2;  …  …  Statementn;  }  } 11
  • 12. THREE STEPS  Enter the program.  Compile the program.  Run the program 12
  • 13. EXAMPLE 1 1. Public class Hello 2. { 3. /** 4. * My first program in java 5. */ 6. public static void main(String [] args) { 7. // prints the string “Hello World” on screen 8. System.out.println(“Hello World”); 9. } 10. } 13
  • 14. ANALYZING MY FIRST PROGRAM IN JAVA 1. Public class Hello 2. { 3. /** 4. * My first program in java 5. */ • Indicates the name of the class which is Hello • In java all codes should be placed inside a class declaration • The class uses an access specifier public, which indicates that our class is accessible to other class in other package (collection of class). Package and access specifier will be 14
  • 15. 1. PUBLIC CLASS HELLO 2. { 3. /** 4. * MY FIRST PROGRAM IN JAVA 5. */ • THE SECOND LINE CONTAINS A CURLY BRACE { WHICH INDICATE THE START OF A BLOCK. • IN THIS CODE WE PLACED THE CURLY BRACE AT THE NEXT LINE AFTER THE CLASS DECLARATION, HOWEVER, WE CAN ALSO PLACED THIS NEXT TO THE FIRST LINE OF OUR CODE, SO WE COULD ACTUALLY WRITE OUR CODE AS PUBLIC CLASS HELLO{ 15
  • 16. 1. PUBLIC CLASS HELLO 2. { 3. /** 4. * MY FIRST PROGRAM IN JAVA 5. */ • THE NEXT THREE LINES INDICATES A JAVA COMMENT • A COMMENT - SOMETHING USED TO DOCUMENT A PART OF A CODE - IT IS NOT PART OF THE PROGRAM ITSELF, BUT ONLY FOR DOCUMENTATION PURPOSE - IT IS A GOOD PROGRAMING PRACTICE TO ADD A COMMENT TO YOUR CODE 16
  • 17. 1. PUBLIC CLASS HELLO 2. { 3. /** 4. * MY FIRST PROGRAM IN JAVA 5. */ 6. PUBLIC STATIC VOID MAIN(STRING [] ARGS) { • INDICATES THE NAME OF THE METHOD IN HELLO CLASS WHICH IS THE MAIN METHOD • ALL PROGRAMS EXCEPT APPLET (TO BE DISCUSS LATER IN THIS COURSE) WRITTEN IN JAVA STARTS WITH THE MAIN METHOD • BE CAREFUL TO FOLLOW THE SYNTAX 17
  • 18. 1. PUBLIC CLASS HELLO 2. { 3. /** 4. * MY FIRST PROGRAM IN JAVA 5. */ 6. PUBLIC STATIC VOID MAIN(STRING [] ARGS) { 7. // PRINTS THE STRING “HELLO WORLD” ON SCREEN • THIS IS ALSO A COMMENT IN JAVA 18
  • 19. 1. PUBLIC CLASS HELLO 2. { 3. /** 4. * MY FIRST PROGRAM IN JAVA 5. */ 6. PUBLIC STATIC VOID MAIN(STRING [] ARGS) { 7. // PRINTS THE STRING “HELLO WORLD” ON SCREEN 8. SYSTEM.OUT.PRINTLN(“HELLO WORLD”); • THIS COMMAND SYSTEM.OUT.PRINTLN(), PRINTS THE TEXT ENCLOSED BY QUOTATION ON THE SCREEN 19
  • 20. 1. PUBLIC CLASS HELLO 2. { 3. /** 4. * MY FIRST PROGRAM IN JAVA 5. */ 6. PUBLIC STATIC VOID MAIN(STRING [] ARGS) { 7. // PRINTS THE STRING “HELLO WORLD” ON SCREEN 8. SYSTEM.OUT.PRINTLN(“HELLO WORLD”); 9. } 10. } • THE LAST TWO LINES CONTAINING THE CURLY BRACES ARE USED TO CLOSE THE MAIN METHOD AND THE CLASS RESPECTIVELY 20
  • 21. THE MAIN METHOD main method can be written in any of the following forms: public static void main(String [] args) or public static void main(String args [])  the public keyword is an access specifier.  The keyword static allow main() to be called without having to instantiate a particular instance of the class + This is necessary since main() is called by the java interpreter before any object is made  void means main() does not return any value.  String args[] declares a parameter named args, which is an array of instance of the class String. + args receive any command line arguments presents when the program executed 21
  • 22. JAVA KEYWORDS  They are predefined identifiers reserved by java for a specific purpose.  They can not be used as a names of variables, classes, methods, etc. 22
  • 23. JAVA KEYWORDS  double, int, super, abstract  Boolean, switch, else, interface  Break, extends, long, synchronized  Case, finally, null, throw  Byte, false, native, this  Catch, float, package, transient  Byvalue, final, threadsafe, new  For, private, true, class  If, public, void, char  Class, protected, goto, try  While, continue, implement, break  Else, case, string, return  Static, short, import, default 23
  • 24. PRIMITIVE DATA TYPE  • The Java programming language defines eight primitive data types.  – boolean (for logical)  – char (for textual)  – byte  – short  – int  – long (integral)  – double  – float (floating point). 24
  • 25. VARIABLE  A variable is a named memory location that can be assigned a value.  As you learned earlier, variables are declared using this form of statement, type var-name;  A variable is an item of data used to store the state of objects.  A variable has a: – data type  The data type indicates the type of value that the variable can hold. – name  The variable name must follow rules for identifiers. Declaration and Initializing variable  Declare a variable as follows: 25
  • 26. HOW TO INITIALIZE VARIABLE  . One way to give a variable a value is through an assignment statement, as you have already seen.  To do this, follow the variable’s name with an equal sign and the value being assigned.  The general form of initialization is shown here: type varname = value;  int count = 10; // give count an initial value of 10  char ch = 'X'; // initialize ch with the letter X  float f = 1.2F; // f is initialized with 1.2  When declaring two or more variables of the same type using a comma-separated list, you can give one or more of those variables an initial value. For example:  int a, b = 8, c = 19, d; // b and c have initializations  In this case, only b and c are initialized.  Int a = 3, b = 8, c = 19; //a, b, c all have initializations  In this case a, b, c are initialized. 26
  • 27. DECLARING AND INITIALIZING VARIABLES SAMPLE PROGRAM 1. public class VariableSamples { 2. public static void main( String[] args ){ 3. //declare a data type with variable name 4. // result and boolean data type 5. boolean result; 6. 7. //declare a data type with variable name 8. // option and char data type 9. char option; 10. option = 'C'; //assign 'C' to option 11. 12. //declare a data type with variable name 13. //grade, double data type and initialized 14. //to 0.0 15. double grade = 0.0; 16. } 17. } 27
  • 28. EXAMPLE 2 28  The following program creates two variables called x and y.  /*  This demonstrates a variable.  Call this file Example2.java.  */  class Example2 {  public static void main(String args[]) {  int x; // this declares a variable  int y; // this declares another variable  x = 1024; // this assigns 1024 to x  System.out.println("x contains " + x);  y = x / 2;  System.out.print("y contains x / 2: ");  System.out.print(y);  }  }  When you run this program, you will see the following output:  x contains 1024  y contains x / 2: 512
  • 29. DECLARING AND INITIALIZING VARIABLES: CODING GUIDELINES 1. It always good to initialize your variables as you declare them. 2. Use descriptive names for your variables. Like for example, if you want to have a variable that contains a grade for a student, name it as, grade and not just some random letters you choose. 3. Declare one variable per line of code. For example, the variable declarations, double exam=0; double quiz=10; double grade = 0; is preferred over the declaration, double exam=0, quiz=10, grade=0; 29
  • 30. OUTPUTTING VARIABLE DATA • In order to output the value of a certain variable, we can use the following commands: System.out.println() System.out.print() Sample program 1. public class OutputVariable { 2. public static void main( String[] args ){ 3. int value = 10; 4. char x; 5. x = 6. 7. System.out.println( value ); 8. System.out.println( 9. } 10. } The program will output the following text on screen: 10 The value of x=A 30
  • 31. OPERATORS • Different types of operators: – arithmetic operators – relational operators – logical operators – conditional operators • These operators follow a certain kind of precedence so that the compiler will know which operator to evaluate first in case multiple operators are used in one statement. 31
  • 32. ARITHMETIC OPERATORS operator Meaning + Addition - Subtraction * Multiplication / Division % Modulus ++ Increment -- decrement 32
  • 33. EXAMPLE 3 33 The following program demonstrates the modulus operator. // Demonstrate the % operator. class ModDemo { public static void main(String args[]) { int iresult, irem; double dresult, drem; iresult = 10 / 3; irem = 10 % 3; dresult = 10.0 / 3.0; drem = 10.0 % 3.0; System.out.println("Result and remainder of 10 / 3 = " + iresult + " " + irem); System.out.println("Result and remainder of 10.0 / 3.0 = " + dresult + " " + drem); } } The output from the program is shown here are: Result and remainder of 10 / 3 = 3 1 Result and remainder of 10.0 / 3.0 = 3.3333333333333335 1.0 As you can see, the% yields a remainder of 1 for both integer and floating-point operations.
  • 34. RELATIONAL OPERATORS • Relational operators compare two values and determines the relationship between those values. • The output of evaluation are the boolean values true or false. 34
  • 35. CONTROL STATEMENTS  Java Control statements control the order of execution in a java program, based on data values and conditional logic.  There are three main categories of control flow statements; · Selection statements: if, if-else and switch. · Loop statements: while, do-while and for. · Transfer statements: break, continue, return, try- catch-finally and assert. 35
  • 36. SELECTION STATEMENTS  The If Statement  The if statement executes a block of code only if the specified expression is true. If the value is false, then the if block is skipped and execution continues with the rest of the program. You can either have a single statement or a block of code within an if statement.  if (<conditional expression>) <statement action> 36
  • 37. 37 public class IfStatementDemo { public static void main(String[] args) { int a = 10, b = 20; if (a > b) System.out.println("a > b"); if (a < b) System.out.println("b > a"); } } The program will print b > a
  • 38. THE IF-ELSE STATEMENT  The if/else statement is an extension of the if statement. If the statements in the if statement fails, the statements in the else block are executed. You can either have a single statement or a block of code within if-else blocks.  The if-else statement has the following syntax: if (<conditional expression>) <statement action> else <statement action> 38
  • 39. 39 public class IfElseStatementDemo { public static void main(String[] args) { int a = 10, b = 20; if (a > b) { System.out.println("a > b"); } else { System.out.println("b > a"); } } } Output displays b > a
  • 40. SWITCH CASE STATEMENT  The switch case statement, also called a case statement is a multi-way branch with several choices. A switch is easier to implement than a series of if/else statements. The switch statement begins with a keyword, followed by an expression that equates to a no long integral value. Following the controlling expression is a code block that contains zero or more labelled cases. Each label must equate to an integer constant and each must be unique. When the switch statement executes, it compares the value of the controlling expression to the values of each case label.  switch (<non-long integral expression>) { case label1: <statement1> case label2: <statement2> … case labeln: <statementn> default: <statement> } // end switch 40
  • 41. 41 public class SwitchCaseStatementDemo { public static void main(String[] args) { int a = 10, b = 20, c = 30; int status = -1; if (a > b && a > c) { status = 1; } else if (b > c) { status = 2; } else { status = 3; } switch (status) { case 1: System.out.println("a is the greatest"); break; case 2: System.out.println("b is the greatest"); break; case 3: System.out.println("c is the greatest"); break; default: System.out.println("Cannot be determined"); } } } Output displayed is: c is the greatest
  • 42. ITERATION STATEMENTS While Statement  The while statement is a looping construct control statement that executes a block of code while a condition is true. You can either have a single statement or a block of code within the while loop. The loop will never be executed if the testing expression evaluates to false.  The syntax of the while loop is while (<loop condition>) <statements> 42
  • 43. 43 public class WhileLoopDemo { public static void main(String[] args) { int count = 1; System.out.println("Printing Numbers from 1 to 10"); while (count <= 10) { System.out.println(count++); } }} Output Printing Numbers from 1 to 10 1 2 3 4 5 6 7 8 9 10
  • 44. DO-WHILE LOOP STATEMENT  The do-while loop is similar to the while loop, except that the test is performed at the end of the loop instead of at the beginning. This ensures that the loop will be executed at least once. A do-while loop begins with the keyword do, followed by the statements that make up the body of the loop.  The syntax of the do-while loop is do <loop body> while (<loop condition>); 44
  • 45. 45 public class DoWhileLoopDemo { public static void main(String[] args) { int count = 1; System.out.println("Printing Numbers from 1 to 10"); do { System.out.println(count++); } while (count <= 10); }} Output Printing Numbers from 1 to 10 1 2 3 4 5 6 7 8 9 10
  • 46. FOR LOOPS  The for loop is a looping construct which can execute a set of instructions a specified number of times. It’s a counter controlled loop.  The syntax of the loop is as follows: for (<initialization>; <loop condition>; <increment expression>) <loop body> 46
  • 47. 47 public class ForLoopDemo { public static void main(String[] args) { System.out.println("Printing Numbers from 1 to 10"); for (int count = 1; count <= 10; count++) { System.out.println(count); } }} Output Printing Numbers from 1 to 10 1 2 3 4 5 6 7 8 9 10
  • 48. TRANSFER STATEMENTS Continue Statement  A continue statement stops the iteration of a loop (while, do or for) and causes execution to resume at the topof the nearest enclosing loop. You use a continue statement when you do not want to execute the remaining statements in the loop, but you do not want to exit the loop itself.  The syntax of the continue statement is continue; // the unlabeled form continue <label>; // the labeled form 48
  • 49. 49 public class ContinueExample { public static void main(String[] args) { System.out.println("Odd Numbers"); for (int i = 1; i <= 10; ++i) { if (i % 2 == 0) continue; // Rest of loop body skipped when i is even System.out.println(i + "t"); } }} Output Odd Numbers 1 3 5 7 9
  • 50. BREAK STATEMENT  The break statement transfers control out of the enclosing loop ( for, while, do or switch statement). You use a break statement when you want to jump immediately to the statement following the enclosing control structure. You can also provide a loop with a label, and then use the label in your break statement.  The Syntax for break statement is as shown below; break; // the unlabeled form break <label>; // the labeled form 50
  • 51. 51 public class BreakExample { public static void main(String[] args) { System.out.println("Numbers 1 - 10"); for (int i = 1;; ++i) { if (i == 11) break; // Rest of loop body skipped when i is even System.out.println(i + "t"); } }} Output Numbers 1 – 10 1 2 3 4 5 6 7 8 9 10
  • 52. QUESTIONS??? THANK YOU FOR YOUR ATTENTION 52

Editor's Notes

  1. Scalability of handover framework to handle increased handovers without compromising latency performance Flexibility to support various 4G deployments