SlideShare a Scribd company logo
1 of 46
Intro to structured
Programing with
java
lecture 1
Hello!
I am Mohamed Essam !
You can find me at
mohamedessam.cs@gmail.com
2
Let’s make the world a
better place
1
“
“Talk is cheap. Show me the
code.”
― Linus Torvalds
4
What Java is ?
○ Java is a general-purpose computer-programming language that is
concurrent, class-based, object-oriented and specifically designed to
have as few implementation dependencies as possible.
○ Java applications are typically compiled to bytecode that can run on
any Java virtual machine (JVM) regardless of computer architecture.
○ As of 2016, Java is one of the most popular programming languages in
use.
○ In Software engineering process the end one called maintaining which
enable the software engineering maintain the software instead of build
a new one from scratch and that is what make java developer still
required to maintain the current app even after using another
technologies for build android apps .
○ I can use it to build native Android Apps, Web Applications and desktop
Applications. 5
Who many java developer around the world?
European Union -27 Countries
6
Wikipedia say there are 10,000,000 and the majority lies in EU27 and
about 5,900,000
How many java developer
required in Egypt?
According to Wazzuf app for
offering job for software engineers i
Egypt at my current date now
at 01/03/2019 is 275 job.
7
Setting up
Environment
8
Java Development Tools
○ You can use a text editor, such as the Windows Notepad or
WordPad, to create Java programs and to compile and run the
programs from the command window.
○ You can also use a Java development tool, such as NetBeans or
Eclipse. These tools support an integrated development
environment (IDE) for developing Java programs quickly.
○ Editing, compiling, building, executing, and debugging programs
are integrated in one graphical user interface.
9
○ Using these tools effectively can greatly increase your programming
productivity. NetBeans and Eclipse are easy to use if you follow the
tutorials. Tutorials on NetBeans and Eclipse can be found under Tutorials
on the Student Companion Website at www.pearsonhighered.com/liang
10
Setting Up Java
○ You can get the latest, greatest versions of Java by
visiting
https://www.oracle.com/technetwork/java/javase/down
loads/index.html
Look for the newest available version of the JDK. Select a
version that runs on your computer’s operating system.
Figure 2-1 shows me clicking a Download JDK button
(circa March 2014) at the Oracle website.
11
Setting Up Java
12
Setting Up the NetBeans
Integrated Development
Environment
13
Here’s how you download NetBeans:
1. Visit www.eclipse.org.
2. Look for a way to download
NetBeans for your operating system
https://netbeans.org/downloads/8.0.2/
The Way Java Works
The goal is to write one application (in this
example, an interactive party invitation)
and have it work on whatever device your
friends have.
14
15
Source
code in
java
Good
Morning
1.Source
Create a source
document. Use
an established
protocol (in this
case, the Java
language).
2.Compilor
Run your document
through a source code
compiler. The compiler
checks for errors and
won’t let you compile until
it’s satisfied that
everything will run
correctly
3.Output(Code)
The compiler creates a
new document, coded
into Java byte code. Any
device capable of running
Java will be able to
interpret/translate this file
into something it can run.
The compiled byte code is
platform independent.
4.Virtual Machine
Your friends don’t have
a physical Java
Machine, but they all
have a virtual Java
machine
(implemented in
software) running
inside their electronic
gadgets. The virtual
machine reads and
runs the byte code.
Code structure in
Java
○ Put a class in a source file.
○ Put methods in a class.
○ Put statements in a method.
16
What goes in a
source file?
A source code file (with the .java
extension) holds one class definition.
The class represents a piece of your
program,
A class is an extensible program-
code-template for creating objects,
although a very tiny application
might need just a single class. The
class must go within a pair of curly
braces.
17
What goes in a
class?
A class has one or more methods. In
the Dog class, the bark method will
hold instructions for how the Dog
should bark. Your methods must be
declared inside a class (in other
words, within the curly braces of the
class)
18
What goes in a
method?
○ Within the curly braces of a
method, write your instructions
for how that method should be
performed. Method code is
basically a set of statements,
and for now you can think of a
method kind of like a function or
procedure.
19
What goes in a
method?
○ Example :
We can make a method for dog barking to
help a user know why his dog is barking
 Is that sign because of a medical problem?
 Is that because of the protective?
 Is he feel lonely or bored?
 Is it because feeling hungry and need a
food ?
The method can give a detailed instruction
and guide the user to know the reason of
barking.
20
What method is ?
○ You can think of function as a black box take an input
and produce an output and it’s not important to know
what is the algorithm inside of it , just enough to know
how you can use and what is their function
21
Hello,World
○ It’s something similar to the coffee machine take input
and produce output and we don't know what is the
algorithm that written inside of it just we have to know
how we can use it.
22
○ Later we will learn how to define an algorithm and it will be
something like CHORUS in songs lyrics.
○ The function make your code more organized.
23
Anatomy of a class
 the JVM runs everything between the curly braces { } of
your main method. Every Java application has to have at
least one class, and at least one main method (not one
main per class; just one main per application).
 The main() method is where your program starts running
like (When Green Flag clicked ) in Scratch. 24
public static void main (String[] args)
{
// your code goes here
}
 When the JVM starts running, it looks for the
class you give it at the command line. Then it
starts looking for a specially-written method
that looks exactly like:
25
26
everything goes in a class.
 You’ll type your source code file (with a .java extension),
 then compile it into a new class file (with a .class extension). When you
run your program, you’re really running a class. Running a program
means telling the Java Virtual Machine (JVM) to “Load the MyFirstApp
class,
 then start executing its main() method. Keep running ‘til all the code in
main is finished.”.
Writing a class with
a main In Java,
27
Once you’re inside main (or any method), the
fun begins. You can say all the normal things
that you say in most programming languages
to make the computer do something. Your code
can tell the JVM to:
 Do Something
 Do Something Again and Again
 Do something under a Condition
What can you say in
the main method?
28
A First Simple Program
/* This is a simple Java program. Call this file "Example.java".
*/
class Example
{
// Your program begins with a call to main().
public static void main(String args[])
{
System.out.println(“First Line.");
System.out.println(“Second Line.");
System.out.println(“Third Line.");
}
}
29
A Closer Look at the First Simple Program
○ To compile the Example program Click in the green sign above, as shown.
○ When the program is run, the following output is displayed:
○ First Line.
○ Second Line.
○ Third Line.
○ The Compile runs the files line by line so they printed in this sequence
/*
This is a simple Java program. Call this file "Example.java".
*/
○ This is a comment. Like most other programming languages, Java lets you enter a
remark into a program’s source file. The contents of a comment are ignored by the
compiler. Instead, a comment describes or explains the operation of the program
to anyone who is reading its source code. In this case, the comment describes the
program and reminds you that the source file should be called Example.java. Of
course, in real applications, comments generally explain how some part of the
program works or what a specific feature does.
30
“
“Programs must be written
for people to read, and only
incidentally for machines to
execute.”
― Harold Abelson
31
A Closer Look at the First Simple Program
○ Java supports three styles of comments. The one shown at the top of
the program is called a multiline comment. This type of comment
must begin with /* and end with */. Anything between these two
comment symbols is ignored by the compiler. As the name suggests,
a multiline comment may be several lines long.
○ The next line of code in the program is shown here:
○ This line uses the keyword class to declare that a new class is
being defined. Example is an identifier that is the name of the
class. The entire class definition, including all of its members, will
be between the opening curly brace ({) and the closing curly
brace (}).
32
A Closer Look at the First Simple Program
○ The next line in the program is the single-line comment:
○ shown here: // Your program begins with a call to main().
○ This is the second type of comment supported by Java. A single-
line comment begins with a // and ends at the end of the line. As a
general rule, programmers use multiline comments for longer
remarks and single-line comments for brief, line-by-line
descriptions.
33
A Closer Look at the First Simple Program
○ The next line of code is shown here:
○ public static void main(String args[]) {
○ This line begins the main( ) method. As the comment preceding it suggests,
this is the line at which the program will begin executing. All Java
applications begin execution by calling main( ).
○ The next line of code is shown here. Notice that it occurs inside main( ).
System.out.println(“First Line.");
This line outputs the string “This is a simple Java program.” followed by a
newline on the screen. Output is actually accomplished by the built-in
println( ) method. In this case, println( ) displays the string which is
passed to it.
○ Notice that the println( ) statement ends with a semicolon. All statements in
Java end with a semicolon.
34
Data types
○ Java defines eight primitive types of data:
○ byte, short, int, long, char, float, double, and boolean.
○ The primitive types are also commonly referred to as simple types, and both
terms will be used in this book. These can be put in four groups:
○ Integers This group includes byte, short, int, and long, which are for whole-
valued signed numbers.
○ Floating-point numbers This group includes float and double, which represent
numbers with fractional precision. Characters This group includes char, which
represents symbols in a character set, like letters and numbers.
○ Boolean This group includes boolean, which is a special type for representing
true/false values.
35
A Second program
○ Further, you can perform mathematical computations and display
the result on the console. Listing 1.3 gives an example of evaluating.
public class ComputeExpression {
public static void main(String[] args) {
System.out.println((10.5 + 2 * 3) / (45 – 3.5));
}
}
○ Output:
0.39759036144578314
36
Variable
○ You can think of variable as a little box or a container to store
data in, in the memory of the computer and every data type
has its own variable.
37
38
But What would happen
represented a 8 bytes number in
a 4 bytes variable ?
39
Arian 5 the most expensive software failures
in history.
40
○ On June 4th, 1996, the very first Ariane 5 rocket ignited its engines and began
speeding away from the coast of French Guiana. 37 seconds later, the
rocket flipped 90 degrees in the wrong direction, and less than two seconds
later, aerodynamic forces ripped the boosters apart from the main stage at a
height of 4km. This caused the self-destruct mechanism to trigger, and the
spacecraft was consumed in a gigantic fireball of liquid hydrogen.
○ The disastrous launch cost approximately $370m, led to a public inquiry, and
through the destruction of the rocket’s payload, delayed scientific research into
workings of the Earth’s magnetosphere for almost 4 years. The Ariane 5 launch is
widely acknowledged as one of the most expensive software failures in history.
○ The fault was quickly identified as a software bug in the rocket’s Inertial
Reference System. The rocket used this system to determine whether it was
pointing up or down, which is formally known as the horizontal bias, or informally
as a BH value. This value was represented by a 64-bit floating variable, which
was perfectly adequate.
○ However, problems began to occur when the software attempted to stuff this
64-bit variable, which can represent billions of potential values, into a 16-bit
integer, which can only represent 65,535 potential values. For the first few
seconds of flight, the rocket’s acceleration was low, so the conversion between
these two values was successful. However, as the rocket’s velocity increased, the
64-bit variable exceeded 65k, and became too large to fit in a 16-bit variable. It
was at this point that the processor encountered an operand error, and
populated the BH variable with a diagnostic value. 41
A Third program
○ // Compute distance light travels using long variables.
class Light {
public static void main(String args[])
{
int lightspeed;
long days;
long seconds;
long distance;
// approximate speed of light in miles per second
lightspeed = 186000;
days = 1000;
42
A Third program
seconds = days * 24 * 60 * 60;
// convert to seconds
distance = lightspeed * seconds;
// compute distance
System.out.print("In " + days);
System.out.print(" days light will travel about ");
System.out.println(distance + " miles.");
}
}
43
Let’s write a simple
traffic light code
○ First we will write a code for a traffic
light system to prompt the user for
input and check if the input is red
will print go , if yellow will print wait
and if green it will print go!
○ Hint take care and use else
statement to avoid any
problem in the traffic light
○ After that we can make it more
difficult by using a counter instead
of the user input .
44
references
○ Beginning Programming with Java For Dummies, 4th Edition.
○ Data Structures and Problem Solving Using Java4edWeiss.
○ fundamentals-of-computer-science-using-java.
○ Head First Java.
○ Java The Complete Reference, 7th Edition.
○ CS50 introduction to Computer Science.
45
46
Thanks!
Any questions?

More Related Content

What's hot

Selenium web driver | java
Selenium web driver | javaSelenium web driver | java
Selenium web driver | javaRajesh Kumar
 
Mi0041 java and web design
Mi0041  java and web designMi0041  java and web design
Mi0041 java and web designsmumbahelp
 
SMI - Introduction to Java
SMI - Introduction to JavaSMI - Introduction to Java
SMI - Introduction to JavaSMIJava
 
Mi0041 java and web design
Mi0041  java and web designMi0041  java and web design
Mi0041 java and web designsmumbahelp
 
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfJAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfnofakeNews
 
Single Responsibility Principle
Single Responsibility PrincipleSingle Responsibility Principle
Single Responsibility PrincipleBADR
 
Selenium online training
Selenium online trainingSelenium online training
Selenium online trainingDivya Shree
 
Machine learning in php Using PHP-ML
Machine learning in php Using PHP-MLMachine learning in php Using PHP-ML
Machine learning in php Using PHP-MLAgbagbara Omokhoa
 
25 php interview questions – codementor
25 php interview questions – codementor25 php interview questions – codementor
25 php interview questions – codementorArc & Codementor
 
0. Course Introduction
0. Course Introduction0. Course Introduction
0. Course IntroductionIntro C# Book
 
Assignment2 btkr1343 sem2_20122013
Assignment2 btkr1343 sem2_20122013Assignment2 btkr1343 sem2_20122013
Assignment2 btkr1343 sem2_20122013Sulaiman Sabikan
 
Basic online java course - Brainsmartlabs
Basic online java course  - BrainsmartlabsBasic online java course  - Brainsmartlabs
Basic online java course - Brainsmartlabsbrainsmartlabsedu
 
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...DevDay.org
 

What's hot (16)

Java Programming Fundamentals
Java Programming Fundamentals Java Programming Fundamentals
Java Programming Fundamentals
 
Selenium web driver | java
Selenium web driver | javaSelenium web driver | java
Selenium web driver | java
 
Mi0041 java and web design
Mi0041  java and web designMi0041  java and web design
Mi0041 java and web design
 
SMI - Introduction to Java
SMI - Introduction to JavaSMI - Introduction to Java
SMI - Introduction to Java
 
Mi0041 java and web design
Mi0041  java and web designMi0041  java and web design
Mi0041 java and web design
 
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfJAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
 
Single Responsibility Principle
Single Responsibility PrincipleSingle Responsibility Principle
Single Responsibility Principle
 
Code Smells
Code SmellsCode Smells
Code Smells
 
Selenium online training
Selenium online trainingSelenium online training
Selenium online training
 
Machine learning in php Using PHP-ML
Machine learning in php Using PHP-MLMachine learning in php Using PHP-ML
Machine learning in php Using PHP-ML
 
25 php interview questions – codementor
25 php interview questions – codementor25 php interview questions – codementor
25 php interview questions – codementor
 
0. Course Introduction
0. Course Introduction0. Course Introduction
0. Course Introduction
 
Basics of java 1
Basics of java 1Basics of java 1
Basics of java 1
 
Assignment2 btkr1343 sem2_20122013
Assignment2 btkr1343 sem2_20122013Assignment2 btkr1343 sem2_20122013
Assignment2 btkr1343 sem2_20122013
 
Basic online java course - Brainsmartlabs
Basic online java course  - BrainsmartlabsBasic online java course  - Brainsmartlabs
Basic online java course - Brainsmartlabs
 
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
 

Similar to Intro to programing with java-lecture 1

Similar to Intro to programing with java-lecture 1 (20)

Java lab1 manual
Java lab1 manualJava lab1 manual
Java lab1 manual
 
Programming in Java: Getting Started
Programming in Java: Getting StartedProgramming in Java: Getting Started
Programming in Java: Getting Started
 
Java for Mainframers
Java for MainframersJava for Mainframers
Java for Mainframers
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010
 
Unit2 java
Unit2 javaUnit2 java
Unit2 java
 
Professional-core-java-training
Professional-core-java-trainingProfessional-core-java-training
Professional-core-java-training
 
Unit of competency
Unit of competencyUnit of competency
Unit of competency
 
MC0078 SMU 2013 Fall session
MC0078 SMU 2013 Fall sessionMC0078 SMU 2013 Fall session
MC0078 SMU 2013 Fall session
 
Professional-core-java-training
Professional-core-java-trainingProfessional-core-java-training
Professional-core-java-training
 
Compiling and understanding first program in java
Compiling and understanding first program in javaCompiling and understanding first program in java
Compiling and understanding first program in java
 
Java_presesntation.ppt
Java_presesntation.pptJava_presesntation.ppt
Java_presesntation.ppt
 
Java programming language basics
Java programming language basicsJava programming language basics
Java programming language basics
 
Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1
 
Java introduction
Java introductionJava introduction
Java introduction
 
OBJECT ORIENTED PROGRAMMING LANGUAGE - SHORT NOTES
OBJECT ORIENTED PROGRAMMING LANGUAGE - SHORT NOTESOBJECT ORIENTED PROGRAMMING LANGUAGE - SHORT NOTES
OBJECT ORIENTED PROGRAMMING LANGUAGE - SHORT NOTES
 
01slide
01slide01slide
01slide
 
01slide
01slide01slide
01slide
 
(Ebook pdf) java programming language basics
(Ebook pdf)   java programming language basics(Ebook pdf)   java programming language basics
(Ebook pdf) java programming language basics
 
Java intro
Java introJava intro
Java intro
 
01slide
01slide01slide
01slide
 

More from Mohamed Essam

Data Science Crash course
Data Science Crash courseData Science Crash course
Data Science Crash courseMohamed Essam
 
2.Feature Extraction
2.Feature Extraction2.Feature Extraction
2.Feature ExtractionMohamed Essam
 
Introduction to Robotics.pptx
Introduction to Robotics.pptxIntroduction to Robotics.pptx
Introduction to Robotics.pptxMohamed Essam
 
Introduction_to_Gui_with_tkinter.pptx
Introduction_to_Gui_with_tkinter.pptxIntroduction_to_Gui_with_tkinter.pptx
Introduction_to_Gui_with_tkinter.pptxMohamed Essam
 
Getting_Started_with_DL_in_Keras.pptx
Getting_Started_with_DL_in_Keras.pptxGetting_Started_with_DL_in_Keras.pptx
Getting_Started_with_DL_in_Keras.pptxMohamed Essam
 
Let_s_Dive_to_Deep_Learning.pptx
Let_s_Dive_to_Deep_Learning.pptxLet_s_Dive_to_Deep_Learning.pptx
Let_s_Dive_to_Deep_Learning.pptxMohamed Essam
 
OOP-Advanced_Programming.pptx
OOP-Advanced_Programming.pptxOOP-Advanced_Programming.pptx
OOP-Advanced_Programming.pptxMohamed Essam
 
Regularization_BY_MOHAMED_ESSAM.pptx
Regularization_BY_MOHAMED_ESSAM.pptxRegularization_BY_MOHAMED_ESSAM.pptx
Regularization_BY_MOHAMED_ESSAM.pptxMohamed Essam
 
1.What_if_Adham_Nour_tried_to_make_a_Machine_Learning_Model_at_Home.pptx
1.What_if_Adham_Nour_tried_to_make_a_Machine_Learning_Model_at_Home.pptx1.What_if_Adham_Nour_tried_to_make_a_Machine_Learning_Model_at_Home.pptx
1.What_if_Adham_Nour_tried_to_make_a_Machine_Learning_Model_at_Home.pptxMohamed Essam
 
2.Data_Strucures_and_modules.pptx
2.Data_Strucures_and_modules.pptx2.Data_Strucures_and_modules.pptx
2.Data_Strucures_and_modules.pptxMohamed Essam
 
Activation_function.pptx
Activation_function.pptxActivation_function.pptx
Activation_function.pptxMohamed Essam
 
Deep_Learning_Frameworks
Deep_Learning_FrameworksDeep_Learning_Frameworks
Deep_Learning_FrameworksMohamed Essam
 

More from Mohamed Essam (20)

Data Science Crash course
Data Science Crash courseData Science Crash course
Data Science Crash course
 
2.Feature Extraction
2.Feature Extraction2.Feature Extraction
2.Feature Extraction
 
Data Science
Data ScienceData Science
Data Science
 
Introduction to Robotics.pptx
Introduction to Robotics.pptxIntroduction to Robotics.pptx
Introduction to Robotics.pptx
 
Introduction_to_Gui_with_tkinter.pptx
Introduction_to_Gui_with_tkinter.pptxIntroduction_to_Gui_with_tkinter.pptx
Introduction_to_Gui_with_tkinter.pptx
 
Getting_Started_with_DL_in_Keras.pptx
Getting_Started_with_DL_in_Keras.pptxGetting_Started_with_DL_in_Keras.pptx
Getting_Started_with_DL_in_Keras.pptx
 
Linear_algebra.pptx
Linear_algebra.pptxLinear_algebra.pptx
Linear_algebra.pptx
 
Let_s_Dive_to_Deep_Learning.pptx
Let_s_Dive_to_Deep_Learning.pptxLet_s_Dive_to_Deep_Learning.pptx
Let_s_Dive_to_Deep_Learning.pptx
 
OOP-Advanced_Programming.pptx
OOP-Advanced_Programming.pptxOOP-Advanced_Programming.pptx
OOP-Advanced_Programming.pptx
 
1.Basic_Syntax
1.Basic_Syntax1.Basic_Syntax
1.Basic_Syntax
 
KNN.pptx
KNN.pptxKNN.pptx
KNN.pptx
 
Regularization_BY_MOHAMED_ESSAM.pptx
Regularization_BY_MOHAMED_ESSAM.pptxRegularization_BY_MOHAMED_ESSAM.pptx
Regularization_BY_MOHAMED_ESSAM.pptx
 
1.What_if_Adham_Nour_tried_to_make_a_Machine_Learning_Model_at_Home.pptx
1.What_if_Adham_Nour_tried_to_make_a_Machine_Learning_Model_at_Home.pptx1.What_if_Adham_Nour_tried_to_make_a_Machine_Learning_Model_at_Home.pptx
1.What_if_Adham_Nour_tried_to_make_a_Machine_Learning_Model_at_Home.pptx
 
Clean_Code
Clean_CodeClean_Code
Clean_Code
 
Linear_Regression
Linear_RegressionLinear_Regression
Linear_Regression
 
2.Data_Strucures_and_modules.pptx
2.Data_Strucures_and_modules.pptx2.Data_Strucures_and_modules.pptx
2.Data_Strucures_and_modules.pptx
 
Naieve_Bayee.pptx
Naieve_Bayee.pptxNaieve_Bayee.pptx
Naieve_Bayee.pptx
 
Activation_function.pptx
Activation_function.pptxActivation_function.pptx
Activation_function.pptx
 
Deep_Learning_Frameworks
Deep_Learning_FrameworksDeep_Learning_Frameworks
Deep_Learning_Frameworks
 
Neural_Network
Neural_NetworkNeural_Network
Neural_Network
 

Recently uploaded

Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 

Recently uploaded (20)

Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 

Intro to programing with java-lecture 1

  • 1. Intro to structured Programing with java lecture 1
  • 2. Hello! I am Mohamed Essam ! You can find me at mohamedessam.cs@gmail.com 2
  • 3. Let’s make the world a better place 1
  • 4. “ “Talk is cheap. Show me the code.” ― Linus Torvalds 4
  • 5. What Java is ? ○ Java is a general-purpose computer-programming language that is concurrent, class-based, object-oriented and specifically designed to have as few implementation dependencies as possible. ○ Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of computer architecture. ○ As of 2016, Java is one of the most popular programming languages in use. ○ In Software engineering process the end one called maintaining which enable the software engineering maintain the software instead of build a new one from scratch and that is what make java developer still required to maintain the current app even after using another technologies for build android apps . ○ I can use it to build native Android Apps, Web Applications and desktop Applications. 5
  • 6. Who many java developer around the world? European Union -27 Countries 6 Wikipedia say there are 10,000,000 and the majority lies in EU27 and about 5,900,000
  • 7. How many java developer required in Egypt? According to Wazzuf app for offering job for software engineers i Egypt at my current date now at 01/03/2019 is 275 job. 7
  • 9. Java Development Tools ○ You can use a text editor, such as the Windows Notepad or WordPad, to create Java programs and to compile and run the programs from the command window. ○ You can also use a Java development tool, such as NetBeans or Eclipse. These tools support an integrated development environment (IDE) for developing Java programs quickly. ○ Editing, compiling, building, executing, and debugging programs are integrated in one graphical user interface. 9
  • 10. ○ Using these tools effectively can greatly increase your programming productivity. NetBeans and Eclipse are easy to use if you follow the tutorials. Tutorials on NetBeans and Eclipse can be found under Tutorials on the Student Companion Website at www.pearsonhighered.com/liang 10
  • 11. Setting Up Java ○ You can get the latest, greatest versions of Java by visiting https://www.oracle.com/technetwork/java/javase/down loads/index.html Look for the newest available version of the JDK. Select a version that runs on your computer’s operating system. Figure 2-1 shows me clicking a Download JDK button (circa March 2014) at the Oracle website. 11
  • 13. Setting Up the NetBeans Integrated Development Environment 13 Here’s how you download NetBeans: 1. Visit www.eclipse.org. 2. Look for a way to download NetBeans for your operating system https://netbeans.org/downloads/8.0.2/
  • 14. The Way Java Works The goal is to write one application (in this example, an interactive party invitation) and have it work on whatever device your friends have. 14
  • 15. 15 Source code in java Good Morning 1.Source Create a source document. Use an established protocol (in this case, the Java language). 2.Compilor Run your document through a source code compiler. The compiler checks for errors and won’t let you compile until it’s satisfied that everything will run correctly 3.Output(Code) The compiler creates a new document, coded into Java byte code. Any device capable of running Java will be able to interpret/translate this file into something it can run. The compiled byte code is platform independent. 4.Virtual Machine Your friends don’t have a physical Java Machine, but they all have a virtual Java machine (implemented in software) running inside their electronic gadgets. The virtual machine reads and runs the byte code.
  • 16. Code structure in Java ○ Put a class in a source file. ○ Put methods in a class. ○ Put statements in a method. 16
  • 17. What goes in a source file? A source code file (with the .java extension) holds one class definition. The class represents a piece of your program, A class is an extensible program- code-template for creating objects, although a very tiny application might need just a single class. The class must go within a pair of curly braces. 17
  • 18. What goes in a class? A class has one or more methods. In the Dog class, the bark method will hold instructions for how the Dog should bark. Your methods must be declared inside a class (in other words, within the curly braces of the class) 18
  • 19. What goes in a method? ○ Within the curly braces of a method, write your instructions for how that method should be performed. Method code is basically a set of statements, and for now you can think of a method kind of like a function or procedure. 19
  • 20. What goes in a method? ○ Example : We can make a method for dog barking to help a user know why his dog is barking  Is that sign because of a medical problem?  Is that because of the protective?  Is he feel lonely or bored?  Is it because feeling hungry and need a food ? The method can give a detailed instruction and guide the user to know the reason of barking. 20
  • 21. What method is ? ○ You can think of function as a black box take an input and produce an output and it’s not important to know what is the algorithm inside of it , just enough to know how you can use and what is their function 21 Hello,World
  • 22. ○ It’s something similar to the coffee machine take input and produce output and we don't know what is the algorithm that written inside of it just we have to know how we can use it. 22
  • 23. ○ Later we will learn how to define an algorithm and it will be something like CHORUS in songs lyrics. ○ The function make your code more organized. 23
  • 24. Anatomy of a class  the JVM runs everything between the curly braces { } of your main method. Every Java application has to have at least one class, and at least one main method (not one main per class; just one main per application).  The main() method is where your program starts running like (When Green Flag clicked ) in Scratch. 24 public static void main (String[] args) { // your code goes here }  When the JVM starts running, it looks for the class you give it at the command line. Then it starts looking for a specially-written method that looks exactly like:
  • 25. 25
  • 26. 26 everything goes in a class.  You’ll type your source code file (with a .java extension),  then compile it into a new class file (with a .class extension). When you run your program, you’re really running a class. Running a program means telling the Java Virtual Machine (JVM) to “Load the MyFirstApp class,  then start executing its main() method. Keep running ‘til all the code in main is finished.”. Writing a class with a main In Java,
  • 27. 27
  • 28. Once you’re inside main (or any method), the fun begins. You can say all the normal things that you say in most programming languages to make the computer do something. Your code can tell the JVM to:  Do Something  Do Something Again and Again  Do something under a Condition What can you say in the main method? 28
  • 29. A First Simple Program /* This is a simple Java program. Call this file "Example.java". */ class Example { // Your program begins with a call to main(). public static void main(String args[]) { System.out.println(“First Line."); System.out.println(“Second Line."); System.out.println(“Third Line."); } } 29
  • 30. A Closer Look at the First Simple Program ○ To compile the Example program Click in the green sign above, as shown. ○ When the program is run, the following output is displayed: ○ First Line. ○ Second Line. ○ Third Line. ○ The Compile runs the files line by line so they printed in this sequence /* This is a simple Java program. Call this file "Example.java". */ ○ This is a comment. Like most other programming languages, Java lets you enter a remark into a program’s source file. The contents of a comment are ignored by the compiler. Instead, a comment describes or explains the operation of the program to anyone who is reading its source code. In this case, the comment describes the program and reminds you that the source file should be called Example.java. Of course, in real applications, comments generally explain how some part of the program works or what a specific feature does. 30
  • 31. “ “Programs must be written for people to read, and only incidentally for machines to execute.” ― Harold Abelson 31
  • 32. A Closer Look at the First Simple Program ○ Java supports three styles of comments. The one shown at the top of the program is called a multiline comment. This type of comment must begin with /* and end with */. Anything between these two comment symbols is ignored by the compiler. As the name suggests, a multiline comment may be several lines long. ○ The next line of code in the program is shown here: ○ This line uses the keyword class to declare that a new class is being defined. Example is an identifier that is the name of the class. The entire class definition, including all of its members, will be between the opening curly brace ({) and the closing curly brace (}). 32
  • 33. A Closer Look at the First Simple Program ○ The next line in the program is the single-line comment: ○ shown here: // Your program begins with a call to main(). ○ This is the second type of comment supported by Java. A single- line comment begins with a // and ends at the end of the line. As a general rule, programmers use multiline comments for longer remarks and single-line comments for brief, line-by-line descriptions. 33
  • 34. A Closer Look at the First Simple Program ○ The next line of code is shown here: ○ public static void main(String args[]) { ○ This line begins the main( ) method. As the comment preceding it suggests, this is the line at which the program will begin executing. All Java applications begin execution by calling main( ). ○ The next line of code is shown here. Notice that it occurs inside main( ). System.out.println(“First Line."); This line outputs the string “This is a simple Java program.” followed by a newline on the screen. Output is actually accomplished by the built-in println( ) method. In this case, println( ) displays the string which is passed to it. ○ Notice that the println( ) statement ends with a semicolon. All statements in Java end with a semicolon. 34
  • 35. Data types ○ Java defines eight primitive types of data: ○ byte, short, int, long, char, float, double, and boolean. ○ The primitive types are also commonly referred to as simple types, and both terms will be used in this book. These can be put in four groups: ○ Integers This group includes byte, short, int, and long, which are for whole- valued signed numbers. ○ Floating-point numbers This group includes float and double, which represent numbers with fractional precision. Characters This group includes char, which represents symbols in a character set, like letters and numbers. ○ Boolean This group includes boolean, which is a special type for representing true/false values. 35
  • 36. A Second program ○ Further, you can perform mathematical computations and display the result on the console. Listing 1.3 gives an example of evaluating. public class ComputeExpression { public static void main(String[] args) { System.out.println((10.5 + 2 * 3) / (45 – 3.5)); } } ○ Output: 0.39759036144578314 36
  • 37. Variable ○ You can think of variable as a little box or a container to store data in, in the memory of the computer and every data type has its own variable. 37
  • 38. 38 But What would happen represented a 8 bytes number in a 4 bytes variable ?
  • 39. 39 Arian 5 the most expensive software failures in history.
  • 40. 40 ○ On June 4th, 1996, the very first Ariane 5 rocket ignited its engines and began speeding away from the coast of French Guiana. 37 seconds later, the rocket flipped 90 degrees in the wrong direction, and less than two seconds later, aerodynamic forces ripped the boosters apart from the main stage at a height of 4km. This caused the self-destruct mechanism to trigger, and the spacecraft was consumed in a gigantic fireball of liquid hydrogen. ○ The disastrous launch cost approximately $370m, led to a public inquiry, and through the destruction of the rocket’s payload, delayed scientific research into workings of the Earth’s magnetosphere for almost 4 years. The Ariane 5 launch is widely acknowledged as one of the most expensive software failures in history.
  • 41. ○ The fault was quickly identified as a software bug in the rocket’s Inertial Reference System. The rocket used this system to determine whether it was pointing up or down, which is formally known as the horizontal bias, or informally as a BH value. This value was represented by a 64-bit floating variable, which was perfectly adequate. ○ However, problems began to occur when the software attempted to stuff this 64-bit variable, which can represent billions of potential values, into a 16-bit integer, which can only represent 65,535 potential values. For the first few seconds of flight, the rocket’s acceleration was low, so the conversion between these two values was successful. However, as the rocket’s velocity increased, the 64-bit variable exceeded 65k, and became too large to fit in a 16-bit variable. It was at this point that the processor encountered an operand error, and populated the BH variable with a diagnostic value. 41
  • 42. A Third program ○ // Compute distance light travels using long variables. class Light { public static void main(String args[]) { int lightspeed; long days; long seconds; long distance; // approximate speed of light in miles per second lightspeed = 186000; days = 1000; 42
  • 43. A Third program seconds = days * 24 * 60 * 60; // convert to seconds distance = lightspeed * seconds; // compute distance System.out.print("In " + days); System.out.print(" days light will travel about "); System.out.println(distance + " miles."); } } 43
  • 44. Let’s write a simple traffic light code ○ First we will write a code for a traffic light system to prompt the user for input and check if the input is red will print go , if yellow will print wait and if green it will print go! ○ Hint take care and use else statement to avoid any problem in the traffic light ○ After that we can make it more difficult by using a counter instead of the user input . 44
  • 45. references ○ Beginning Programming with Java For Dummies, 4th Edition. ○ Data Structures and Problem Solving Using Java4edWeiss. ○ fundamentals-of-computer-science-using-java. ○ Head First Java. ○ Java The Complete Reference, 7th Edition. ○ CS50 introduction to Computer Science. 45