Вы находитесь на странице: 1из 18

Java Introduction

Prepared by: Ragab Mustafa

Agenda
Overview of Programming Languages. Whats and why Java. Whats Eclipse . Writing first program in Java. Basics of java programming Language. Variables, Operators and Types. Methods, Conditionals and Loops.

Agenda cont.
Classes, Arrays and objects. Solving a problems in Java. Object-oriented Programming(OOP). Inheritance.

Overview of Programming Languages.


There are three types of programming languages:
Machine Languages that encoded in 1s and 0s, thats hard to write program in these languages. Low Level Languages(e.g. Assembly)its close to the machine code but not the same also its easer to write and read(understand). High Level Languages (e.g. C,C++,Java and C#)these Languages needs a compiler to translate the program into machine code.

Whats Java
Java is an OOP language developed at Sun Microsystems Labs by James Gosling at 1991. The first version called OAK but at 1995 Netscape announced that Java would be incorporated into Netscape Navigator. Sun formally announced Java at a major conference in May 1995. it is also a good not only in object-oriented programming but also in general programming language.

Why Java
Java has some advantages make it differ from the other languages as:
o That it is platform independent(mean work well in the internet). It achieves this by using something called the Java Virtual Machine (JVM).

Its a free source language.

Why Java cont.


Also its 1. Simple Architecture neutral . 2. Object oriented Portable . 3. Distributed High performance . 4. Multithreaded Robust . 5. Dynamic Secure.

Whats Eclipse
Eclipse is a portable IDE for java its easy and powerful. There are more than one IDE for java as NetBeans, JBuilder and JDeveloper.

Prepare your PC and yourself!


First you must download JDK from sun or go to here. Then run the IDE that you will treat with it here we will work by Eclipse. To download Eclipse IDE go to here or go to the home page of Eclipse . Just you download the IDE (hint: Eclipse is portable not installed) run it that will Explained by video.

The first program in java


Write the program:
public class FirstProgram { public static void main (String[] args) { System.out.print("Hello, 2 + 3 = "); System.out.println(5); System.out.println("Good Bye"); } }

Basics of Java
Program Structure class CLASSNAME { public static void main(String[] args) { STATEMENTS } }

Variables
Named location that stores a value Form: TYPE NAME; Example: String fName; class Hello { public static void main(String[] arguments) { String fName = ragab; System.out.println(fName); fName = "Something else"; System.out.println(fName); } }

Types
Limits a variable to kinds of values String: plain text (hello) double: Floating-point, real valued number(3.14, -7.0) int: integer (5, -18)
String fName = hello; double Pi = 3.14;

Types
Order of Operations :Precedence like math, left to right. Right hand side of = evaluated first.
double x= 20 double x =3 / 2+ 1; // x= 2.0

Conversion by casting
Int a = 2; // a = 2 double a = (double)2; // a = 2.0 double a = 2/3; // a = 0.0 double a = (double)2/3; // a = 0.6666 int a = (int)18.7; // a=18

Types
Conversion by method:
o Int to String:
String five = Integer.toString(5); String five = + 5; // five = 5

o String to int:
Int a=Integer.parseInt(18);

Mathematical Functions:
o Math.sin(x)

o Math.cos(Math.PI / 2) o Math.log(Math.log(x + y))

Operators
Symbols that perform simple computations Assignment: = Addition: + Subtraction: Multiplication: * Division: /

Example
class Math { public static void main(String[] arguments)
{ int score; score = 1 + 2 * 3; System.out.println(score); double copy = score; copy = copy / 2; System.out.println(copy); score = (int) copy; System.out.println(score); }

Assignment #1
Convert a temperature from Fahrenheit to Celsius using: C = (5 9) (F - 32) References :
1. Essential Java for Scientists and Engineers, Book. 2. Java how to program 6th edition, Book. 3. MIT Lectures.

Вам также может понравиться