Top Banner
Introduction to Java
37
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to java

Introduction to Java

Page 2: Introduction to java

Name : Muhammad Asif Subhani

Email: [email protected]

Course Structure: Lectures: 2

Instructor

Page 3: Introduction to java

Attendance as per university policy. However, if you do decide to join, you are not

allowed to leave the class before its completion without the permission of the instructor

Drink food not allowed in class Use of cell phones and similar devices is not

permissible during the class. Your phones should not be visible or heard during the class

Automated tools to check for plagiarism

Rules & Policies

Page 4: Introduction to java

Grading Scheme Quizzes (10%)Assignments (15%)Mid Term Exam (15%)Project (30%)Final Exam (30%)

Page 5: Introduction to java

10-15 minutes duration Will cover assignments and material covered

in the class Unannounced No make-ups We will be dropping some quizzes from the

final grade

Class Quizzes

Page 6: Introduction to java

Assignments are individual or may be in group.

No late submissions I encourage you to discuss your

assignments with your friends but no copying is allowed. Both the copier and the originator will get 0.

20% marks deduction on per day late submission.

100% Deduction on no submission.

Assignment

Page 7: Introduction to java

MIDTERM:A single midterm exam that will cover all material covered till the midterm.

FINAL: Will cover the entire course. The final will contain tough programming tasks

Midterm /Final

Page 8: Introduction to java

Project will be in group and the submission of project in deliverables.

No late submission of project deliverables. Project deadline and other detail will be

announced later.

Project

Page 9: Introduction to java

Introduction to Java Basic I/O concepts, String, Wrapper Classes, Collections, Streams OOP Concepts – Encapsulation, Inheritance, Polymorphism OOP in Java – Inheritance, Abstract superclasses, Interfaces, Inner classes,

Packages. Exception Handling Building GUIs with Swing. Components, drawing, layouts, graphics Events and Event Handling Threads and concurrency- Threads, synchronization JDBC – Database Application Networking – Client Server Application Using 3rd party API

Course Outline …

Page 10: Introduction to java

Agile Development Project Management & Documentation Testing UML Diagrams Code Refactoring ,Design Pattern Version Control System Project Demos / Presentation

Course Outline

Page 11: Introduction to java

Java as a second language course◦ Teaches programming in Java for people who already know how to program in

C or similar language The Java programming language is a high-level language that can be

characterized by all of the following buzzwords:◦ Simple◦ Object oriented◦ Distributed◦ Multithreaded◦ Dynamic◦ Architecture neutral◦ Portable◦ High performance◦ Robust◦ Secure

Pre-requisites◦ Basic programming background (C/C++)◦ Problem solving techniques◦ Debugging skills

Course Overview

Page 12: Introduction to java

The Java Language runs on a “Java Virtual Machine”

The Java compiler (javac) compiles Java code into byte-code

The Java Virtual Machine

Page 13: Introduction to java

Java is Platform Independent

Page 14: Introduction to java

 Java Development Kit (JDK) is an implementation of either one of the Java SE, Java EE or Java ME platforms released by Oracle Corporation 

The Java platform has two components:◦ The Java Virtual Machine◦ The Java Application Programming Interface (API)

JDK /Java Platform

Page 15: Introduction to java

Development Tools: compiling(javac compiler), running, monitoring, debugging, and documenting (javadoc documentation )your applications.

Application Programming Interface (API): The API provides the core functionality of the Java programming language.. It spans everything from basic objects, to networking and security, to XML generation and database access, and more.

Deployment Technologies: Java Web Start software and Java Plug-In.

User Interface Toolkits: The Swing and Java 2D toolkits. Integration Libraries: JDBC™ API, Java RMI

JDK /Java Platform

Page 16: Introduction to java

Java Architecture

.java Editor JDK Computer.jar/

.class

10101

.jar/.class

JVM Computer101111101010

1

.c/.cpp

Compiler .obj Computer.exe

10101

Page 17: Introduction to java

Core language◦ Ints, array, objects, loops and conditionals

Libraries◦ This is where the power of Java really emerges

String, ArrayList, HashMap, String Tokenizer

◦ Networking, Graphics, Database connectivity,◦ Re-use at it’s best (so far).

Language + Libraries

Page 18: Introduction to java

Similar to C/C++ in syntax But eliminates several complexities of

◦ No operator overloading◦ No direct pointer manipulation or pointer arithmetic◦ No multiple inheritance◦ No malloc() and free() – handles memory

automatically◦ Garbage Collector

Lots more things which make Java more attractive.

Avoid platform dependencies. Write once, run anywhere. 

How Will Java Technology Change your Life?

Page 19: Introduction to java

http://www.oracle.com/technetwork/java/javase/downloads/index.html

Download JDK

Page 20: Introduction to java

JDK Path

1

2

3

Page 21: Introduction to java

JDK Path Via Command

C:\>set path="c:\programfiles\Java\jdk1.7.0_17\bin" C:\>set classpath=%classpath%;.;

Page 22: Introduction to java

Your first application, HelloWorldApp, will simply display the greeting "Hello world!". To create this program, you will:

  Create a source file A source file contains code, written in the Java programming language,

that you and other programmers can understand. You can use any text editor to create and edit source files.

Compile the source file into a .class file The Java programming language compiler (javac) takes your source file

and translates its text into instructions that the Java virtual machine can understand. The instructions contained within this file are known as bytecodes.

Run the program The Java application launcher tool (java) uses the Java virtual machine to

run your application.

Creating Your First Application (NotePad)

Page 23: Introduction to java

class HelloWorldApp {      public static void main(String[] args)

{          System.out.println("Hello World!");

 } }

HelloWorld Code

Page 24: Introduction to java

Save the code in a file with the name HelloWorldApp.java. To do this in Notepad, first choose the File > Save As menu item. Then, in the Save As dialog box:

Using the Save in combo box, specify the folder (directory) where you'll save your file. In this example, the directory is java on the C drive.

In the File name text field, type "HelloWorldApp.java", including the quotation marks.

From the Save as type combo box, choose Text Documents (*.txt). In the Encoding combo box, leave the encoding as ANSI. When you're finished, the dialog box should look like this.

The Save As dialog just before you click Save. Now click Save, and exit Notepad.

HelloWorld with Notepad

Page 25: Introduction to java

Comiple & Run JDK

Page 26: Introduction to java

Download JDK with NetBeanhttp://www.oracle.com/technetwork/java/javase/downloads/jdk-7-netbeans-download-432126.html

Page 27: Introduction to java

Your first application, HelloWorldApp, will simply display the greeting "Hello World!" To create this program, you will:

Create an IDE project When you create an IDE project, you create an environment in which to build and

run your applications. Using IDE projects eliminates configuration issues normally associated with developing on the command line. You can build or run your application by choosing a single menu item within the IDE.

Add code to the generated source file A source file contains code, written in the Java programming language, that you

and other programmers can understand. As part of creating an IDE project, a skeleton source file will be automatically generated. You will then modify the source file to add the "Hello World!" message.

Compile the source file into a .class file The IDE invokes the Java programming language compiler (javac), which takes your

source file and translates its text into instructions that the Java virtual machine can understand. The instructions contained within this file are known as bytecodes.

Run the program The IDE invokes the Java application launcher tool (java), which uses the Java

virtual machine to run your application.

Creating Your First Application (NetBeans)

Page 28: Introduction to java

To create an IDE project:1.Launch the NetBeans IDE.

◦ On Microsoft Windows systems, you can use the NetBeans IDE item in the Start menu.

2.In the NetBeans IDE, choose File | New Project.

HelloWorld with NetBeans

Page 29: Introduction to java

3.In the New Project wizard, expand the Java category and select Java Application as shown in the following figure:

HelloWorld with NetBeans …

Page 30: Introduction to java

4.In the Name and Location page of the wizard, do the following (as shown in the figure below):

In the Project Name field, type Hello World App. In the Create Main Class field, type helloworldapp.HelloWorldApp. Leave the Set as Main Project checkbox selected.

5.Click Finish.

HelloWorld with NetBeans …

Page 31: Introduction to java

The project is created and opened in the IDE. You should see the following components: The Projects window, which contains a tree view of the components of the project,

including source files, libraries that your code depends on, and so on. The Source Editor window with a file called HelloWorldApp open. The Navigator window, which you can use to quickly navigate between elements

within the selected class.

HelloWorld with NetBeans …

Page 32: Introduction to java

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package helloworldapp;

/**

* The HelloWorldApp class implements an application that

* simply prints "Hello World!" to standard output.

*/

public class HelloWorldApp {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

System.out.println("Hello World!"); // Display the string.

}

}

HelloWorld Code NetBeans

Page 33: Introduction to java

6.To compile your source file, choose Run | Build Main Project from the IDE's main menu.

HelloWorld with NetBeans …

Page 34: Introduction to java

7.From the IDE's menu bar, choose Run | Run Main Project.

HelloWorld with NetBeans …

Page 35: Introduction to java

Comments are ignored by the compiler but are useful to other programmers. The Java programming language supports three kinds of comments:

/* text */ The compiler ignores everything from /* to */. /** documentation */ This indicates a documentation comment (doc comment, for

short). The compiler ignores this kind of comment, just like it ignores comments that use /* and */. The javadoc tool uses doc comments when preparing automatically generated documentation. For more information on javadoc, see the Javadoc™ tool documentation .

// text The compiler ignores everything from // to the end of the line.

Comments in Java

Page 36: Introduction to java

In the Java programming language, every application must contain a main method whose signature is:

public static void main(String[] args) The modifiers public and static can be written in

either order (public static or static public), but the convention is to use public static as shown above. You can name the argument anything you want, but most programmers choose "args" or "argv".

The main method is similar to the main function in C and C++; it's the entry point for your application and will subsequently invoke all the other methods required by your program.

Main Method in Java

Page 37: Introduction to java

The main method accepts a single argument: an array of elements of type String.

public static void main(String[] args) This array is the mechanism through which the runtime system

passes information to your application. For example:java MyApp arg1 arg2

Each string in the array is called a command-line argument. Command-line arguments let users affect the operation of the

application without recompiling it. For example, a sorting program might allow the user to specify that

the data be sorted in descending order with this command-line argument:

-descending The "Hello World!" application ignores its command-line arguments,

but you should be aware of the fact that such arguments do exist.

Main Method in Java