 Learning JAVA.  Understanding Salient features of JAVA.  Implementing JAVA PROGRAMS on your own.  Development of JAVA PROJECTS on your own.

Slides:



Advertisements
Similar presentations
INTRODUCTION TO JAVA.
Advertisements

 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
04/07/041 Intro to JAVA By: Riyaz Malbari. 04/07/042 History of JAVA  Came into existence at Sun Microsystems, Inc. in  Was initially called “
INTRODUCTION TO JAVA PROGRAMMING Chapter 1. What is Computer Programming?
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
C++ fundamentals.
Lecture 1: Overview of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++ Designed.
BASIC JAVA PROGRAMMING TUTORIAL. History  James Gosling and Sun Microsystems  Oak  Java, May 20, 1995, Sun World  Hot Java –The first Java-enabled.
+ Java vs. Javascript Jessi Style. + Java Compiled Can stand on its own Written once, run anywhere Two-stage debugging Java is an Object Oriented Programming.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
CONCEPTS OF OBJECT ORIENTED PROGRAMMING. Topics To Be Discussed………………………. Objects Classes Data Abstraction and Encapsulation Inheritance Polymorphism.
DAT602 Database Application Development Lecture 5 JAVA Review.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
INTRODUCTION TO JAVA CHAPTER 1 1. WHAT IS JAVA ? Java is a programming language and computing platform first released by Sun Microsystems in The.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Introduction to Java Programming. History F James Gosling and Sun Microsystems F Oak F Java, May 20, 1995, Sun World F HotJava –The first Java-enabled.
Chapter 1 Introduction to Java 10/8/2015 Lecture 1 1.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
The Java Programming Language
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
Introduction to Computer Systems and the Java Programming Language.
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
JAVA PROGRAMMING BASICS CHAPTER 2. History of Java Begin with project Green in 1991 founded by Patrick Noughton, Mike Sheridan and James Gosling who worked.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
What Is Java? According to Sun in a white paper: Java: A simple, object-oriented, network-savvy, interpreted, robust, secure, architecture-neutral, portable,
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
1 Programming Java Java Basics. 2 Java Program Java Application Program Application Program written in general programming language Applet Program running.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
August 6, 2009 Data Types, Variables, and Arrays.
Lecture 2 Software Concepts Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
1 The JAVA Language Object Oriented Technology Mithani Binjan M.
CSI 3125, Preliminaries, page 1 Data Type, Variables.
Developed at Sun Microsystems in 1991 James Gosling, initially named “OAK” Formally announced java in 1995 Object oriented and cant write procedural.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
COP 2551 Introduction to Object Oriented Programming with Java Topics –Introduction to the Java language –Code Commenting –Java Program Structure –Identifiers.
Java Computer Industry Lab. 1 Programming Java Java Basics Incheon Paik.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
 Array ◦ Single & Multi-dimensional  Java Operators ◦ Assignment ◦ Arithmetic ◦ Relational ◦ Logical ◦ Bitwise & other.
Features of JAVA PLATFORM INDEPENDENT LANGUAGE JAVA RUNTIME ENVIRONMENT (JRE) JAVA VIRTUAL MACHINE (JVM) JAVA APP BYTE CODE JAVA RUNTIME ENVIRONMENT.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
Introduction to Java Programming, 4E Y. Daniel Liang.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Fundamental of Java Programming (630002) Unit – 1 Introduction to Java.
Introduction to JAVA Infobizzs.com.
G. Pullaiah College of Engineering and Technology
JAVA MULTIPLE CHOICE QUESTION.
Unit-1 JAVA Programming.
Chapter No. : 1 Introduction to Java.
Yanal Alahmad Java Workshop Yanal Alahmad
Programming Language Concepts (CIS 635)
An Overview of Java.
IDENTIFIERS CSC 111.
An Introduction to Java – Part I, language basics
Chapter 2: Java Fundamentals
Units with – James tedder
Units with – James tedder
Presentation transcript:

 Learning JAVA.  Understanding Salient features of JAVA.  Implementing JAVA PROGRAMS on your own.  Development of JAVA PROJECTS on your own.

 About JAVA language.  Program structures  Simple program  JVM  OOP principles.  keywords  Data types  Operations  Arrays

Java History L 1.1 Computer language innovation and development occurs for two fundamental reasons: 1) to adapt to changing environments and uses 2) to implement improvements in the art of programming The development of Java was driven by both in equal measures. Many Java features are inherited from the earlier languages: B  C  C++  Java

C language designed by Dennis Ritchie in 1970s. C++ designed by Bjarne Stroustrup in In 1990, Sun Microsystems started a project called Green. Objective: to develop software for consumer electronics. Project was assigned to James Gosling, a veteran of classic network software design. Others included Patrick Naughton, ChrisWarth, Ed Frank, and Mike Sheridan. In 1994, an early web browser called WebRunner was written in Oak. WebRunner was later renamed HotJava. In 1995, Oak was renamed Java.

Java Buzzwords L 1.9  Simple  Secure  Portable  Object-oriented  Robust  Multithreaded  Architecture-neutral  Interpreted  High performance  Distributed  Dynamic

Structure of C

Structure of JAVA Document section Package section Import statements Class definitions { Variables Methods } Main Class { Main Method Definition }

/*A program to add two numbers*/ package mypack; import java.lang. *; import java. util.*; class Addition { int a,b,c; void sum(int a, int b) { c=a+b; System.out.println(“sum is +c”); } class Additionop { public static void main(String args[]) { Addition ad=new Additon(); ad.sum(3,5) }

class Welcome { public static void main(String args[]) { System.out.println(“WELCOME TO JAVA WORLD”); }

Naming conventions specify the rules to be followed by a Java programmer while writing the names of packages, classes, methods etc. Package names are written in small letters. ex: java.io, java.lang, java.awt etc Each word of class name and interface name starts with a capital ex: Sample, AddTwoNumbers Method names start with small letters then each word start with a capital ex: sum (), sumTwoNumbers (), minValue () · Variable names also follow the same above method rule ex: sum, count, totalCount · Constants should be written using all capital letters ex: PI, COUNT · Keywords are reserved words and are written in small letters. ex: int, short, float, public, void

Compiling the Program To compile the program, execute the compiler, javac, specifying the name of the source file on the command line. C:\>javac Welcome.java To actually run the program, you must use the Java interpreter, called java. To do C:\>java Welcome When the program is run, the following output is displayed: “WELCOME TO JAVA WORLD”.

Java Virtual Machine(JVM) Java compiler translate source code into machine code. java compilers produces an intermediate code known as Byte code for a machine. this machine is called Java Virtual Machine, and it exists only inside the computer memory. the virtual machine code is not machine specific, the machine code is generated by Java interpreter.

source code Byte code Process of compilation virtual machine real machine Process of converting byte code into machine code Java program Byte codeJava interpreterMachine code Java compilerVirtual machine

OOP Vs POP Object oriented programingProcedural oriented programing The unit in object-oriented programming is class.The unit in procedural programming is function. It is concerned to develop an application based on real time. POP are more concerned with the processing of procedures and functions. It providing more security to data.It providing less security to data. In OOP the Objects communicate with each other via Functions. There is no communication in POP rather its simply a passing values to the Arguments to the Functions and or procedures. OOP follows Bottom Up Approach of Program Execution. POP follows Top Down Approach of Program Execution. OOP includes Inheritance, Encapsulation and Data Abstraction, Late Binding, Polymorphism, Multithreading, and Message Passing. POP is simply a programming in a traditional way of calling functions and returning values. The list of OOL languages :- JAVA, VB.NET, C#.NET The list of PPL languages :- C, VB, Perl, Basic, FORTRAN.

PRINCIPLES Encapsulation: It is the mechanism that binds together code and the data it manipulates. info. in info. out Data &Method

Inheritance: It is the process by which objects of one class acquire the properties of objects of another class. Bird attributes Flying birds Nonflying birds RobinSwallow PenguinKiwi

Polymorphism: It means the ability to take more than one form. Shape Draw() Circle object Draw(circle) Box object Draw(box) Triangle object Draw(triangle)

CLASS L 4.3 A class is a blueprint,that defines the variables and methods common to all objects of a certain kind. An object holds values for the variables defines in the class. “Object” is an instance of a class. Each object has a class which defines its data and behavior. An object is called an instance of the Class

Structure of Class A class is declared by use of the class keyword. class classname { type instance-variable1; type instance-variable2; //... type instance-variableN; type methodname1(parameter-list) { // body of method } type methodname2(parameter-list } //... type methodnameN(parameter-list) { // body of method }

The Java Keywords abstractcontinuegotopackagesynchronized assertdefaultifprivatethis booleandoimplementsprotectedthrow breakdoubleimportpublicthrows byteelseinstanceofreturntransient caseextendsintshorttry catchfinalinterfacestaticvoid charfinallylongstrictfipvolatile classfloatnativesuperwhile constFornewswitch

Data Types L 1.14 Java defines eight simple types: 1)byte – 8-bit integer type 2)short – 16-bit integer type 3)int – 32-bit integer type 4)long – 64-bit integer type 5)float – 32-bit floating-point type 6)double – 64-bit floating-point type 7)char – symbols in a character set 8)boolean – logical values true and false

Variables L 2.2 Java uses variables to store data. To allocate memory space for a variable JVM requires: 1) to specify the data type of the variable 2) to associate an identifier with the variable 3) the variable may be assigned an initial value All done as part of variable declaration.

Variable Declaration L 2.4 datatype identifier [=value]; datatype must be A simple datatype User defined datatype (class type) We can declare several variables at the same time: type identifier [=value][, identifier [=value] …]; Examples: int a, b, c; int d = 3, e, f = 5; byte g = 22; double pi = ; char ch = 'x';

Variable Scope L 2.5 Scope determines the visibility of program elements with respect to other program elements. In Java, scope is defined separately for classes and methods: 1) variables defined by a class have a global scope 2) variables defined by a method have a local scope A scope is defined by a block: { … } A variable declared inside the scope is not visible outside: { int n; } n = 1;// this is illegal

Arrays L 2.7 An array is a group of liked-typed variables referred to by a common name, with individual variables accessed by their index. Arrays are: 1) declared 2) created 3) initialized 4) used Also, arrays can have one or several dimensions.

Array Declaration L 2.8 Array declaration involves: 1) declaring an array identifier 2) declaring the number of dimensions 3) declaring the data type of the array elements Two styles of array declaration: type array-variable[]; or type [] array-variable;

Array Creation L 2.9 After declaration, no array actually exists. In order to create an array, we use the new operator: type array-variable[]; array-variable = new type[size]; This creates a new array to hold size elements of type type, which reference will be kept in the variable array- variable.

Array Initialization L 2.11 Arrays can be initialized when they are declared: int monthDays[] = {31,28,31,30,31,30,31,31,30,31,30,31}; Note: 1) there is no need to use the new operator 2) the array is created large enough to hold all specified elements

Array Indexing L 2.10 Later we can refer to the elements of this array through their indexes: array-variable[index] The array index always starts with zero! The Java run-time system makes sure that all array indexes are in the correct range, otherwise raises a run-time error.

int[] abc, xyz; abc = new int[5]; // Instantiate an array of 5 integers xyz = abc; // xyz and abc refer to the same array xyz[3] = 100; // Changing xyz changes abc as well. System.out.println (abc[3]); // 100 is displayed

Multidimensional Arrays L 2.12 Multidimensional arrays are arrays of arrays: 1) declaration: int array[][]; 2) creation: int array = new int[2][3]; 3) initialization int array[][] = { {1, 2, 3}, {4, 5, 6} }; Two-dimensional array

Average an array of values class Average { public static void main(String args[]) { double nums[] = {10.1, 11.2, 12.3, 13.4, 14.5}; double result = 0; int i; for(i=0; i<5; i++) result = result + nums[i]; System.out.println("Average is " + result / 5); }

Two-dimensional array class TwoDArray { public static void main(String args[]) { int twoD[][]= new int[4][5]; int i, j, k = 0; for(i=0; i<4; i++) for(j=0; j<5; j++) { twoD[i][j] = k; k++; } for(i=0; i<4; i++) { for(j=0; j<5; j++) System.out.print(twoD[i][j] + " "); System.out.println(); }

Output

Operators Types L 2.13 Java operators are used to build value expressions. Java provides a rich set of operators: 1) assignment 2) arithmetic 3) relational 4) logical 5) bitwise

Arithmetic assignments +=v += expr;v = v + expr ; -=v -=expr;v = v - expr ; *=v *= expr;v = v * expr ; /=v /= expr;v = v / expr ; %=v %= expr;v = v % expr ; L 2.14

Basic Arithmetic Operators +op1 + op2ADD -op1 - op2SUBSTRACT *op1 * op2MULTIPLY /op1 / op2DIVISION %op1 % op2REMAINDER L 2.15

Relational operator ==Equals toApply to any type !=Not equals toApply to any type >Greater thanApply to numerical type <Less thanApply to numerical type >=Greater than or equalApply to numerical type <=Less than or equalApply to numerical type L 2.16

Logical operators &op1 & op2Logical AND |op1 | op2Logical OR &&op1 && op2Short-circuit AND ||op1 || op2Short-circuit OR !! opLogical NOT ^op1 ^ op2Logical XOR L 2.17

Bitwise operators program class Bits { public static void main(String args[]) { byte x,y; x=10; y=11; System.out.println("~x="+(~x));-> -11 System.out.println("x&y="+(x&y));-> 10 System.out.println("x/y="+(x/y));-> 11 System.out.println("x^y="+(x^y));-> 1 System.out.println("x 40 System.out.println("x>>2="+(x>>2));-> 22 System.out.println("x>>>2="+(x>>2));-> 22 }

presented by U. LOVARAJU Assoc. Professor IT-Department