You are on page 1of 45

Type java –version to check if JAVA JDK is present.

As you can see you have only JAVA RUNTIME not JAVA JDK, so you need to
install it by downloading it.
First of all you need to download and install
your java JDK to compile and run the codes

JDK= Java Development Kit


https://www.oracle.com/br/java/technologies/javase-downloads.html
Follow the steps(MAC or Windows) to install your java JDK.
Type javac –version to check if JAVA JDK is present.

You can create java code with


Any text editor.
But a colored text editor like sublime is better
You can install ECLIPSE, NETBEANS OF VS CODE to edit and compile the java code.

https://youtu.be/YhRagbmHLpU?si=qLqjqENUSy-ahZeP

https://code.visualstudio.com/

https://www.eclipse.org/downloads/

https://netbeans.apache.org/
Installing java on VSCODE
https://code.visualstudio.com/
Java is a programming language.
Java Tutorial Java is used to develop mobile apps, web apps,
desktop apps, games and much more.
Java Quickstart
In Java, every application begins with a class name, and that class must match the filename.
Let's create our first Java file, called P1_Hello.java, which can be done in any text editor (like
Notepad).
The file should contain a "Hello World" message, which is written with the following code:

Note: Java is
case-
sensitive:
"MyClass"
and
"myclass"
has different
meaning.
Unit1. Computer Programming,
numerical base systems (BIN, OCTAL,
HEX and DEC).
Before we start programming

We need to understand the numerical


base system: Decimal, Binary, Octal, Hexadecimal.

A good programmer must know this.

Conversion between them.

D(23) = B(???)=O(???)=H(???)
Numerical system
Numerical system
Numerical system
Numerical system
OCTAL to Hexa (Vice versa)
EXERCISES(Choose at least two letters from each question): TASK TO BE DONE
1- Convert to the binary base the following numbers on a decimal basis: a) 72; b) 127; c) 35; d) 23; e) 165; f) 40; g)
22; h) 14

2- Convert to the decimal base the following numbers in binary basis: a) 100001; b) 11011; c) 1100100; d)
10000000; e) 11001011; f) 10110001; g) 10110001; h) 100110000

3- Convert to the octal base the following numbers on a decimal basis: a) 567; b) 983; c) 1020; d) 65; e) 680; f) 105;
g) 294; h) 679

4- Convert the following numbers to the Hexadecimal base on a decimal basis: a) 567; b) 983; c) 1020; d) 65; e) 680;
f) 105; g) 294; h) 679

5- Convert to the Octal base the following numbers in Hexadecimal basis: a) F5; b) AB7; c) 98A; d) F1E2; e) E229; f)
135; g) 710; h) CE1

6- Convert to Binary base the following numbers in Octal base: a) 3365; b) 752; c) 625; d) 13703; e) 67105; f) 2004;
g) 321; h) 7654

7- Convert to Octal base the following numbers in Binary basis: a) 1110101; b) 11110011; c)
1010011100101110111000; d) 111101110; e) 10101010101010; f) 111101001010; g) 110100010; h) 10111110011;
h) 10111110011

8- Convert to Hexadecimal base the following numbers in Binary base: a) 1100101001011010; b)


1111101011001010; c) 11010000000111011010; d) 1110110100010001; e) 100110101011110011011110;
f)10010001101000101 g) 11001111000100)
Unit2. Java Intro, Get Started, Syntax,
Comments, Variables, Input and Output
Java Identifiers
All Java variables must be identified with unique names.
These unique names are called identifiers.
Identifiers can be short names (like x and y) or more descriptive names (age, sum,
totalVolume).
Note: It is recommended to use descriptive names in order to create understandable
and maintainable code:
Unit 3. Java Data Types, Type
Casting, Operators, Strings, 9.
Immutable Objects, Mutable
Objects, functions(methods)
Integer Types
Byte
The byte data type can store whole numbers from -128 to 127. This can be used instead of int or other integer
types to save memory when you are certain that the value will be within -128 and 127:

Example
byte myNum = 100;
System.out.println(myNum);

Short
The short data type can store whole numbers from -32768 to 32767:
Example
short myNum = 5000;
System.out.println(myNum);

Int
The int data type can store whole numbers from -2147483648 to 2147483647. In general, and in our
tutorial, the int data type is the preferred data type when we create variables with a numeric value.
Example
int myNum = 100000;
System.out.println(myNum);
Long
The long data type can store whole numbers from -9223372036854775808 to
9223372036854775807. This is used when int is not large enough to store the value. Note that
you should end the value with an "L":
Example
long myNum = 15000000000L;
System.out.println(myNum);

Float
The float data type can store fractional numbers from 3.4e−038 to 3.4e+038. Note that you
should end the value with an "f":
Example
float myNum = 5.75f;
System.out.println(myNum);

The double data type can store fractional numbers from 1.7e−308 to 1.7e+308. Note
that you should end the value with a "d":
Example
double myNum = 19.99d;
System.out.println(myNum);
Booleans
A boolean data type is declared with the boolean keyword and can
only take the values true or false:
Example
boolean isJavaFun = true;
boolean isFishTasty = false;
System.out.println(isJavaFun); // Outputs true
System.out.println(isFishTasty); // Outputs false
Mutable vs Immutable Objects
A mutable object can be changed after it's created, and an immutable object
can't.

In Java, everything (except for strings) is mutable by default:


Java User Input
The Scanner class is used to get user input, and it is found in the java.util package.
To use the Scanner class, create an object of the class and use any of the available methods
found in the Scanner class documentation. In our example, we will use the nextLine() method,
which is used to read Strings:
Blank slide
Java Exceptions
When executing Java code, different errors can occur: coding errors made by the programmer, errors due to wrong
input, or other unforeseeable things.
When an error occurs, Java will normally stop and generate an error message. The technical term for this is: Java
will throw an exception (throw an error).

Java try and catch


The try statement allows you to define a block of code to be tested for errors while it is
being executed.
The catch statement allows you to define a block of code to be executed, if an error occurs
in the try block.
The try and catch keywords come in pairs:
Finally
The finally statement lets you execute code, after try...catch, regardless of the result:
The throw keyword
The throw statement allows you to create a custom error.
The throw statement is used together with an exception type. There are many exception types
available in
Java: ArithmeticException, FileNotFoundException, ArrayIndexOutOfBoundsException, SecurityExce
ption, etc:

You might also like