Chapt. 1 Introduction to Core Java. Lecture 1: Overview of Java.

Slides:



Advertisements
Similar presentations
1 pritisajja.info Unlocking the World of Java Programming….. Priti Srinivas Sajja February, 2014 Visit pritisajja.info for detail Future Technology for.
Advertisements

Introduction To Java Objectives For Today â Introduction To Java â The Java Platform & The (JVM) Java Virtual Machine â Core Java (API) Application Programming.
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Introduction to Java Kiyeol Ryu Java Programming Language.
Introduction to Java Programming, 4E
Chapter 1 Introduction.
JAVA ENVIRONMENT JDK, API, JVM. JAVA ENVIRONMENT  Java environment includes development tools and many classes and methods. Java Environment JDK (Java.
Introduction to Java.
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.
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
JAVA v.s. C++ Programming Language Comparison By LI LU SAMMY CHU By LI LU SAMMY CHU.
+ 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.
Advanced Java New York University School of Continuing and Professional Studies.
About the Java  Java technology is both a programming language and a platform –The Java Programming Language A high-level language that can be characterized.
 Java Programming Environment  Creating Simple Java Application  Lexical Issues  Java Class Library.
DAT602 Database Application Development Lecture 5 JAVA Review.
Introduction to Programming Languages. Problem Solving in Programming.
Java Introduction Lecture 1. Java Powerful, object-oriented language Free SDK and many resources at
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
1 Computer Systems -- Introduction  Chapter 1 focuses on:  the structure of a Java application  basic program elements  preparing and executing a program.
University of Houston-Clear Lake Proprietary© 1997 Evolution of Programming Languages Basic cycle of improvement –Experience software difficulties –Theory.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and Server Side Programming Very rich GUI libraries Portability (machine independence) A.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
JAVA Java is a programming language and computing platform first released by Sun Microsystems in It was first developed by James Gosling at Sun Microsystems,
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 and Features of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++
POS 406 Java Technology And Beginning Java Code
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Introduction to Java Programming with Forte Y. Daniel Liang.
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.
Object Oriented Programming Lecture 3. Introduction  In discussing Java, some items need to be clarified  The Java programming language  The Java virtual.
What Is Java? According to Sun in a white paper: Java: A simple, object-oriented, network-savvy, interpreted, robust, secure, architecture-neutral, portable,
National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.
We will talking about story of JAVA language. By Kristsada Songpartom.
Copyright © Mohamed Nuzrath Java Programming :: Syllabus & Chapters :: Prepared & Presented By :: Mohamed Nuzrath [ Major In Programming ] NCC Programme.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
1. An Introduction A Programming Language A Technology Java Development Kit Java API One Language: Three Editions Standard Edition Enterprise Edition.
JAVA INTRODUCTION. What is Java? 1. Java is a Pure Object – Oriented language 2. Java is developing by existing languages like C and C++. How Java Differs.
Developed at Sun Microsystems in 1991 James Gosling, initially named “OAK” Formally announced java in 1995 Object oriented and cant write procedural.
By Mr. Muhammad Pervez Akhtar
Today… “Hello World” ritual. Brief History of Java & How Java Works. Introduction to Java class structure. But first, next slide shows Java is No. 1 programming.
Reference Learning Java DDC publishing Herst, Yamauchi, Adler COP 3331 Object Oriented Analysis and Design Java Part I.
introductory lecture on java programming
ITP 109 Week 2 Trina Gregory Introduction to Java.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 15: Java Basics Fundamentals of Web Programming.
Features of JAVA PLATFORM INDEPENDENT LANGUAGE JAVA RUNTIME ENVIRONMENT (JRE) JAVA VIRTUAL MACHINE (JVM) JAVA APP BYTE CODE JAVA RUNTIME ENVIRONMENT.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Fundamental of Java Programming (630002) Unit – 1 Introduction to Java.
Object Oriented Programming in
Java™ 2 Platform Getting Started.
1. Introduction To JAVA.
JAVA MULTIPLE CHOICE QUESTION.
Chapter No. : 1 Introduction to Java.
Internet and Java Foundations, Programming and Practice
Introduction Enosis Learning.
Introduction Enosis Learning.
Starting JavaProgramming
Units with – James tedder
Units with – James tedder
(Computer fundamental Lab)
Chap 1. Getting Started Objectives
Chap 4. Programming Fundamentals
Computer Programming-1 CSC 111
Outcome of the Lecture Upon completion of this lecture you will be able to understand Fundamentals and Characteristics of Java Language Basic Terminology.
Presentation transcript:

Chapt. 1 Introduction to Core Java

Lecture 1: Overview of Java

Introduction Java is a programming language invented by James Gosling and others in originally named Oak,was developed as a part of the Green project at the Sun Company. A general-purpose object-oriented language Based on C/C++. Designed for easy Web/Internet applications. Widespread acceptance.

Java Features Java is simple Java is object-oriented Java is distributed Java is interpreted Java is robust Java is secure Java is architecture-neutral Java is portable High performance Java is multithreaded Java is dynamic

Java Features Simple  fixes some clumsy features of C++  no pointers  automatic garbage collection  rich pre-defined class library Object oriented  focus on the data (objects) and methods manipulating the data  all functions are associated with objects  almost all datatypes are objects (files, strings, etc.)  potentially better code organization and reuse

Complied and Interpreted  java compiler generate byte-codes, not native machine code  the compiled byte-codes are platform-independent  java bytecodes are translated on the fly to machine readable instructions in runtime (Java Virtual Machine) Platform Independent and Portable  same application runs on all platforms  the sizes of the primitive data types are always the same  the libraries define portable interfaces. Java Features

OS/Hardware machine code C source code myprog.c gcc myprog.exe Platform Dependent JVM bytecode Java source code myprog.java javac myprog.class OS/Hardware Platform Independent

Java Features Reliable (Robust)  extensive compile-time and runtime error checking.  no pointers but real arrays. Memory corruptions or unauthorized memory accesses are impossible.  automatic garbage collection tracks objects usage over time. Secure  usage in networked environments requires more security.  memory allocation model is a major defense.  access restrictions are forced (private, public).

Java Features Multithreaded and Interactive  multiple concurrent threads of executions can run simultaneously  utilizes a sophisticated set of synchronization primitives (based on monitors and condition variables paradigm) to achieve this.  Hence improves the interactive performance of graphics application. Dynamic and Extensible  java is designed to adapt to evolving environment.  libraries can freely add new methods and instance variables without any effect on their clients.  interfaces promote flexibility and reusability in code by specifying a set of methods an object can perform, but leaves open how these methods should be implemented.

Java Features (4) Dynamic and Extensible  Functions written in other languages can be accessed in java program can check the class type in runtime Distributed  Designed for creating applications on networks.  Can access remote object on Internet as easily as they can do in a local system.  Hence enables multiple programmer at multiple remote places can work on single project together. High Performance o Java performance is impressive due to use of byte code and multithreading.

Java Features Architecture-Neutral o Write once, run anywhere any time, forever.

JDK Environment & tools JDK comes with a collection of tools that are used for developing and running java programs. Sr. NoToolDescription 1Applet viewerEnables to run Java applets. 2JavaJava Interpreter runs application programs and applet by reading bytecode. 3JavacJava complier translate source code to byte code. 4JavadocCreates HTML documents from Java source code files. 5JavahProduces header files for use with native methods 6javapJava disassembler convert bytecode files into program description 7jdbJava debugger which helps us to find errors in our programs

Application Program Interface Java Standard library (API) includes hundreds of classes methods grouped into several packages. Sr. No Package Description 1Language Support Package Required for implementing basic features of java. 2Utilities PackageProvides utility functions such as date and time functions. 3Input/output PackageRequired for input/output manipulation. 4Networking PackageEnables to communicate with other computers via Internet. 5AWT PackageThe abstract Window Toolkit package contains classes that implements platform- independent GUI. 6Applet PackageIncludes set of classes that allows us to create Java applets.

Object Oriented Concepts with respect to java Class  A blueprint that defines the attributes and methods Object  An instance of a Class Abstraction  Hide certain details and show only essential details Encapsulation  Binding data and methods together Inheritance  Inherit the features of the superclass Polymorphism  One name having many forms

Difference between c++ & java Java is truly object oriented. Java does not support operater overloading. Java does not have template classes as in c++ Java does not support multiple inheritance of classes. But can be achieved by using interface. Java does not support global variables. Every variable and method is declared within a class and forms part of that class. Java does not use pointer.

Difference between c++ & java Java has relacesd destructor function with finalize() function. There are no header files in java.

Appendix A: Introduction to Java17 how Java Works?

Install Java TM 2 Platform on your machine Can be installed on different platforms:  Unix/Linux  Windows  Mac OS Follow the on-line instructions:

Getting Started: (1) Create the source file:  open a text editor, type in the code which defines a class (HelloWorldApp) and then save it in a file (HelloWorldApp.java)  file and class name are case sensitive and must be matched exactly (except the.java part) Example Code: HelloWorldApp.java /** * The HelloWorldApp class implements an application * that displays "Hello World!" to the standard output */ class HelloWorldApp { public static void main(String[] args) { // Display "Hello World!" System.out.println("Hello World!"); }  Java is CASE SENSITIVE!

Getting Started: (2) Compile the program:  compile HelloWorldApp.java by using the following command: javac HelloWorldApp.java it generates a file named HelloWorldApp.class  ‘javac’ is not recognized as an internal or external command, operable program or hatch file. javac: Command not found if you see one of these errors, you have two choices: 1) specify the full path in which the javac program locates every time. For example: C:\j2sdk1.4.2_09\bin\javac HelloWorldApp.java 2) set the PATH environment variable

Getting Started: (3) Run the program:  run the code through: java HelloWorldApp  Note that the command is java, not javac, and you refer to HelloWorldApp, not HelloWorldApp.java or HelloWorldApp.class  Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp if you see this error, you may need to set the environment variable CLASSPATH.

Java Programming Fundamentals Structure of Java Program Data Types Variables Operators Keywords

General Structure of Program Documentation Section Package Statement Import Statement Main Method Class { Main Method definition } Interface Statement Class Definition suggested Optional Essential

Java Tokens Smallest Individual unit in Java Program is called as Java Tokens Java includes five types of tokens o Reserved Keywords. o Identifiers o Literals o Operators o Separators

25 Java Keywords abstractbooleanbreakbytecasecatchchar classconstcontinuedefaultdodoubleelse extendsfinalfinallyfloatforgotoif implementsimportinstanceofintinterfacelongnative newpackageprivateprotectedpublicreturnshort staticstrictfpsuperswitchsynchronizedthisthrow throwstransienttryvoidvolatilewhileassert

Variables Variables:  Name  Type  Value Naming:  May contain numbers, underscore, dollar sign, or letters  Can not start with number  Can be any length  Reserved keywords  Case sensitive

Data Types Primitive(built-in) Non Primitive(Derived)  Arrays  Classes  Interface

Primitive data types Data TypesBitMin ValueMax Value Byte8-2 7 or (-128) r(127) Short or(-32768) or(32767) Int Long Float323.4e e+038 Double641.7e e+308 Boolean1truefalse Char16

29 Definition: An operator performs a particular operation on the operands it is applied on Types of operators  Assignment Operators  Arithmetic Operators  Unary Operators  Equality Operators  Relational Operators  Conditional Operators  instaceof Operator  Bitwise Operators  Shift Operators Operators - Types

30 Assignment Operator Arithmetic Operators OperatorDescriptionExample =Assignmentint i = 10; int j = i; Operators – Assignment Operators/Arithmetic Operators OperatorDescriptionExample +Additionint i = 8 + 9; byte b = (byte) 5+4; -Subtractionint i = 9 – 4; *Multiplicationint i = 8 * 6; /Divisionint i = 10 / 2; %Remainderint i = 10 % 3;

31 Unary Operators OperatorDescriptionExample +Unary plusint i = +1; -Unary minusint i = -1; ++Incrementint j = i++; --Decrementint j = i--; !Logical Notboolean j = !true; Operators – Unary Operators/Equality Operators OperatorDescriptionExample ==EqualityIf (i==1) !=Non equalityIf (i != 4) Equality Operators

32 Relational Operators OperatorDescriptionExample >Greater thanif ( x > 4) <Less thanif ( x < 4) >=Greater than or equal toif ( x >= 4) <=Less than or equal toif ( x <= 4) Operators – Relational Operators/Conditional Operators OperatorDescriptionExample &&Conditional andIf (a == 4 && b == 5) ||Conditional orIf (a == 4 || b == 5) Conditional Operators

33 instanceof Operator OperatorDescriptionExample instanceofInstamce ofIf (john instanceof person) Operators – instanceof Operator/Bitwise Operators/shift operators OperatorDescriptionExample &Bitwise and001 & 111 = 1 |Bitwise or001 | 110 = 111 ^Bitwise ex-or001 ^ 110 = 111 ~Reverse~011 = -10 Bitwise Operators Shift Operators OperatorDescriptionExample >>Right shift4 >> 1 = 100 >> 1 = 010 = 2 <<Left Shift4 << 1 = 100 << 1 = 1000 = 8 >>>Unsigned Right shift4 >>> 1 = 100 >>> 1 = 010 = 2

Increment Operator: ++ m++; ++m Decrement operator:-- m--;--m Conditional Operator exp?exp2:exp3 Dot Operator person. age, person. Salary(); Operators – Increment Operators/Decrement Operators /Conditional Operators

Java Expression

36 Flow Control – if-else if-else if-else SyntaxExample if ( ) { // logic for true condition-1 goes here } else if ( ) { // logic for true condition-2 goes here } else { // if no condition is met, control comes here } int a = 10; if (a < 10 ) { System.out.println(“Less than 10”); } else if (a > 10) { System.out.pritln(“Greater than 10”); } else { System.out.println(“Equal to 10”); } Result: Equal to 10s

37 Flow Control – switch SyntaxExample switch ( ) { case : // stmt-1 break; case : //stmt-2 break; default: //stmt-3 int a = 10; switch (a) { case 1: System.out.println(“1”); break; case 10: System.out.println(“10”); break; default: System.out.println(“None”); Result: 10 switch

38 Flow Control – do-while / while do-while SyntaxExample do { // stmt-1 } while ( ); int i = 0; do { System.out.println(“In do”); i++; } while ( i < 10); Result: Prints “In do” 11 times while SyntaxExample while ( ) { //stmt } int i = 0; while ( i < 10 ) { System.out.println(“In while”); i++; } Result: “In while” 10 times

39 Flow Control – for loop for SyntaxExample for ( initialize; condition; expression) { // stmt } for (int i = 0; i < 10; i++) { System.out.println(“In for”); } Result: Prints “In do” 10 times