You are on page 1of 52

Java Standard Edition

Development Course

About the Course


Objectives : Learn fundamentals of Java programming Concepts, jdk, jre, variables, loops, arrays Learn object-oriented concepts including classes, packages, objects, methods, properties, abstraction, polymorphism, inheritance, encapsulation, and more Learn More Java Connecting to databases Using streams and Sockets

Today

Understand main programming concepts


Programming and Software Engineering. programming paradigms . Programming Languages Java Technology

First java application ( Hello.java) Be able to compile and run any java application. Java Program Structure Variables and Data Types Operators

Computer system and programming

Programmers usually Work here

Computer Science

Solving Problems

Targets of programming

To build Software applications (Desktop Programs)

Building Software Applications

Building Software Applications(Desktop games)

Building Software Applications


Build Software applications (Mobile apps)

Building Software Applications


To build Software applications (Mobile Games)

What is Programming

Programming
The

science of building computer software. We make computer software by writing instructions using some language which is understood by computers (as a machine).

Software Development

Software Development Life Cycles


Analysis Design Implementation Testing Maintenance

Programming Languages paradigms

Linear Programming
Line by line execution Go To Example: Basic

Structured Programming
Modularity Functions Example: C

Object Oriented Programming


Objects

Classes
Examples: C++, JAVA,C#

How to solve problems


Computers cant think or make decisions unless you provide them with the detailed instructions. So to solve any problem we have to make Well defined systematic steps to solve specific problem. (Algorithm) Ways of making our Algorithms
Flowchart

Pseudo

code

Flow chat

Pseudo Code

Programming Languages

The language we write software with Computer only understands machine language Languages differ in syntax, platform they run on, Applications they can do, Supported Libraries,

Examples: Assembly, C, C++, Java, Visual Basic, C#, Perl, Python, HTML, PHP, ASP, JSP.

Low level languages

Language close to the machine language

Not easy to learn for programmers

Examples: Assembly

High level Languages


C, C++, JAVA
Example if (examResult< 60 ) printf( He failed); else

printf(He succeeded );

Tools used in developing Software

Tools
Text Editor

text editor to write your code in


notepad in windows gedit in linux.

Example

Translator

Translate code to machine language or intermediate phases. Compiler Interpreter

Example

Debugger

Application that helps you to discover and solve software errors (bugs)

IDE

All the previous in one tool.

Example : Net beans, Eclipse, Visual Studio.

Java

What is java

Java is a programming language developed by SUN Microsystems (Currently acquired by Oracle) in 1995.
Originally created for controlling hardware and it was very advanced.

Java

In 1991, a small group of Sun engineers called the "Green Team, Led by James Gosling created the programming language that would revolutionize our world Java.

Aims of Java
The aims of the Java language

Simple to learn, & closely based on C++, but reduced in complexity. Object-oriented Robust: Java programs are strictly checked by software before they run Secure: Java ensures that programs running over networks cannot damage your computer files or introduce viruses. Portable: Java programs can easily be transferred from one platform (e.g. Windows) to run on another platform (e.g. Linux) with little or no change. High performance (fast) Interpreted: a key aspect of Java portability (more in Section 3). Threaded: allow a program to do several things at once. Dynamic: Java programs can adapt to changes in their environment even while the program is running.

Java Virtual Machine

Java Virtual Machine is the runtime environment for any java application. Being available in different operating systems makes the java application portable to any platform.

The java virtual machine has different implementation on all of these platforms. The application run inside the java virtual machine

Required Tools
You need

The java compiler (javac)


The libraries you will use, The utilities and the java virtual machine.

Java Compiler

JVM JAVA Libraries

JDK

Java Platforms
Currently Java Platform has many editions suitable for different type of applications. J2SE: Desktop Apps J2EE: Web Apps J2ME: Mobile Apps

Related Technology

Android & BlackBerry JSP (Java Server pages) and Servlets JSF (java server faces)

Download Java Development Kit


Download the JDK from this link http://www.oracle.com/technetwork/java/j avase/downloads/index.html Double click on the downloaded file and install it.

Run Java Without an IDE

Write ;PATHOFJAVABIN without the quotes at the end of the value stored in the Path environment variable. Example: ;C:\Program Files\Java\jdk1.7.0\bin Do not forget the semicolon ; before the path

First application
public class Hello {
public static void main(String[] args) { System.out.println("Hello Java"); }

Save it As Hello.java

Write your java code in any text editor and save it in .java format

Note the Java Language is case sensitive


Open the Command line CMD Compile your code using the following command

javac Hello.java

To run the application

java Hello

Java Program Structure

Java Program Structure

Typical Java Application is a set of Java Classes.


You can define multiple classes in one source code file but it is not recommended.

Only 1 public class can be in a source file.


Methods are declared only inside classes. Statements are written inside methods within curly braces { } .

Classes

Object - Objects have states and behaviours. Example: A dog has states - colour, name, breed as well as behaviours -wagging, barking, eating. An object is an instance of a class. Class - A class can be defined as a template/blue print that describes the behaviours/states that object of its type support.

Attributes (properties)

Instance variables: Instance variables are variables within a class but outside any method. These variables are instantiated when the class is loaded. Instance variables can be accessed from inside any method, constructor or blocks of that particular class.

Constructors

When discussing about classes, one of the most important sub topic would be constructors. Every class has a constructor. If we do not explicitly write a constructor for a class the Java compiler builds a default constructor for that class.
Each time a new object is created, at least one constructor will be invoked. The main rule of constructors is that they should have the same name as the class. A class can have more than one constructor.

Methods
A Java method is a collection of statements that are grouped together to perform an operation.

Create Class in Java (Syntax)


public class class_name { // Class Attributes or properties

// Constructor
// Methods

Create Attributes or Properties Syntax

private datatype property_name ; Example : private String name ; private int number ; private String color ;

Create Constructor
public class_name () { // statments }
Example : public car () { color = red ; }

Create Methods
public returntype method_name () { //Statments } Example : Public void move () { x=x+1; }

Public class car

{
// Attributes private int modelNumber; private String color ; private int x ;

// Constructor public car () {` x=0; } // Method public void move () {

x = x +1 ;
} }

Any Questions ?

END

You might also like