Professional Documents
Culture Documents
Programming
CPE313,MIS313,ISYE313,CMPE313,IT31,ITEC313,ISE313
by
Dr. Cain Kazimoglu
1
Contact Details
Course Details
The course will be taught in two different phases :
2
How to survive this course
3
This is how you should learn
programming
Pair programming, discussing with your colleagues,
generating abstract solutions through team-work is
the key in being sucessfull in learning programming
4
Why Java? Why not any
other language?
10
5
What is Java? (1)
Java is an OOP (Object Oriented Programming)
language developed by James Gosling of Sun
Microsystems in 1990.
11
12
6
What is the current version
of Java?
The current stable and long-term version of Java
is JAVA SE 17.
13
Java
compiler
High Level
Machine Language
101010100100111
bit
14
7
Interpreter & Compiler
High
Level
Languages
(source code)
Compiler
Machine language
Compiler converts source code in three steps : (object program)
1. Lexical Analysis
Machine controls if corresponding commands have equivalents in machine
language
2. Syntax Analysis
Checks the grammer rules of the programming language chosen
3. Code generator
Converts programming code into machine language
15
Writing program
.java 001010100...
interpreting interpreter
compiler .class
16
8
What can you do with
Java?
Amongst many other things, you can:
Produce stand-alone applications which run directly on a
computer (or a mobile).
17
The use of the same bytecode for all JVMs on all platforms allows
Java to be described as a write once, run anywhere
programming language, versus write once, compile anywhere,
which describes cross-platform compiled languages.
18
9
What else can you do with
Java?
Android phones have Java installed as standard.
19
20
10
Creating Java applications
Ordinary text created
MyProgram.java
1.Editor and saved by you
(source code)
Byte code
MyProgram.class created and saved
2.Compiler by compiler
Assembled and
3.Loader Library connected with all
classes used
Now in
machine memory
Byte code
translated and
executed on your
MyProgram
4.Interpreter runs
machine
21
Integrated Development
Editors (IDEs)
To develop your application you will need to write your
instructions for the computer.
22
11
A variety of places to write
code
23
Notepad
A standard windows accessory. This is probably a terrible
choice for the long term, but please be aware that you do not
need an IDE to write Java codes – you only need a SDK to
compile
Pros
Simple to use.
Can write and edit large amounts of text.
Cons
It gives no help with format or errors.
It has no additional facilities for building GUI.
You cannot compile and run a program directly from this editor.
24
12
NetBeans
Pros
Netbeans is the official ide by oracle.
Integrated development modules for JAVA.
Easy to use Swing GUI design tool (drag & drop).
It can give hints on debugging code.
Autocompletes code and provide hints
Version control system and many advanced tools.
Cons
Takes up more memory than Eclipse and other IDEs
You might need some training to use advanced toolset
25
Eclipse
Pros
Fairly straightforward installation
Can write and edit large amounts of text.
It can give hints on debugging code.
It can be linked to compile and run from the editor.
Cons
Does not have drag and drop GUI features by default
(you can add this feature through a plug-in though)
Learning-curve, can be a bit complicated at the start.
26
13
IntelliJ
Pros
Developed by the same people as Android Studio
Once advanced in Java, this IDE can do a lot of
sophisticated work.
Displays data types as you type along.
Cons
IntelliJ is not free; it has a price (there is, however, a
community edition)
Small ecosystem and a singly company product.
27
28
14
Java for dummies ???
Some of you will be experienced programmers already and
this will be familiar – however, for many this will be a new
experience.
At the start you may feel you are copying a lot of words down
which you don’t yet understand.
For the moment just copy the Java we give you while you
learn the process of editing, saving, compiling and executing
programs.
29
30
15
Create a new Java Project
The latest version of JDK 17.
31
32
16
Coding in Java
33
34
17
package myFirstProject;
35
System.out.format
public class Root {
public static void main(String[] args) {
int i = 2;
double r = Math.sqrt(i);
System.out.format("The square root of
%d is %f.%n", i, r);
}
}
36
18
Case Sensitivity
Note that:
Java is case sensitive. For example HelloWorld is
not the same as helloWorld.
Spaces are significant. For example Hello World
is not the same as HelloWorld.
The file name must be the same as the class name
(class HelloWorld, file HelloWorld.java here).
37
package myFirstProject;
38
19
Main method in Java apps
On the other hand, you will discover that not all java
classes have a main method due to its object oriented
structure. Please be aware that there is usually only one
main class in a java application.
39
Example – HelloWorld
package myFirstProgram;
40
20
Running hello world
Running a java program
41
New Exercise :
HelloName.Java
Now we will run a new Java class called
HelloName.java which should look like this:
Note : import static
javax.swing.JOptionPane.*;
Means import all system classes
under swing library
42
21
Variables
43
Running HelloName.java
Use Run File and type a name into the
input dialog box.
44
22
The Variable name
45
JOptionPane.ShowInputDialog is an assignment
statement which takes a value from the prompt such as
“Cain” whatever the user typed – and puts it into the
variable name on the left hand side.
46
23
Self-test Exercises
47
48
24
What next?
Tutorial in labs (each week):
See the tutorial sheet for each week’s exercises.
Use IDEs (Eclipse ,Netbeans or IntelliJ) to write, save,
compile and run.
Bring a flash disk to back-up your programs.
Keep your folders and files organised.
49
Revision
What is Java? What can Java do for you?
What is an Interface Development Environment (IDE)?
Eclipse ,Netbeans or IntelliJ as development environments
First Java Program : Hello World!
Hello Name exercise.
50
25