SlideShare a Scribd company logo
© Oxford University Press 2013. All rights reserved.
Programming in Java, 2e
Sachin Malhotra
Saurabh Choudhary
© Oxford University Press 2013. All rights reserved.
Chapter 2
Getting started with java
© Oxford University Press 2013. All rights reserved.
Objective
• Know the Java Features and its Runtime
Environment
• Get familiar with new releases in Java
• Understand the basic structure of a Java
program
• Get into the details about JDK Installation
• Know about the various constituents of JDK
and its development environments.
© Oxford University Press 2013. All rights reserved.
Introduction
• Java is a programming language invented by
James Gosling and others in 1994.
• originally named Oak ,was developed as a part
of the Green project at the Sun Company.
• Java 7 is latest stable release.
© Oxford University Press 2013. All rights reserved.
Java Essentials
• A high level language
• Java Bytecode – intermediate code
• Java Virtual Machine (JVM) – interpreter for
bytecode
© Oxford University Press 2013. All rights reserved.
Java Runtime
JAVA SOURCE CODE
JAVA BYTE CODE
JAVA VIRTUAL MACHINE
(JVM)
Compilation
Interpretation
Java Runtime Environment includes JVM, class
libraries and other supporting files.
© Oxford University Press 2013. All rights reserved.
Java Approach
© Oxford University Press 2013. All rights reserved.
Java Features
• Platform Independence
• Object oriented
• Compiled and interpreted
• Robust
• Security
– Strictly typed language
– Lack of pointers
– Garbage collection
– Strict compile time checking
– Sandbox security
© Oxford University Press 2013. All rights reserved.
Java Features
• Multithreaded
• Dynamic binding
• Performance
• Networking
• No pointers
• No global variables
• Automatic Garbage collection
© Oxford University Press 2013. All rights reserved.
Java 5 New features
• Autoboxing and unboxing
• Enhanced For loop
• Metadata
• Variable arguments
• Static import
• Graphics enhancemnets
• Generics
• Enum
• StringBuilder class
© Oxford University Press 2013. All rights reserved.
Java 6 New features
• Enhancements in Collections API
• Console class
• Jar and Zip enhacements
• Enhancements to Network Interface
• Enhancements in Java web start and plug in
© Oxford University Press 2013. All rights reserved.
Java 7 New Features
• String in switch…case Statement
• Unicode 6.0.0 Support
• Binary Literals and Numeric Literals (with
Underscores)
• Automatic Resource Management
• Improved Exception Handling
• nio 2.0 (Non-blocking I/O)—New File System
API
© Oxford University Press 2013. All rights reserved.
Java 7 features (contd.)
• Fork and Join for parallel processing
• Supporting Dynamism using invokedynamic to
let JVM resolve type info at runtime
• No need of Diamond Operator <> on right side
of the expression
• Swing Enhancements
• Java FX 2.2.3 provides the new GUI toolkit for
creating rich cross-platform user interfaces
Comparison of Java Version
© Oxford University Press 2013. All rights reserved.
Differences between C++ and Java
• Multiple Inheritance not allowed
– Multi level inheritance is enforced, which makes the design clearer. Multiple
inheritance among classes is not supported in java. Interfaces are used for
supporting multiple inheritance
• Common parent
– All classes are single-rooted. The class Object is the parent of all the classes in
java.
• Packages
– The concept of packages is used, i.e. a large, hierarchical namespace is
provided. This prevents naming ambiguities in libraries.
• In-source documentation
– In-source code documentation comments are provided. Documentation
keywords are provided for e.g.: @author, @version e.t.c.
• All code inside class
– All code resides inside a class. Global data declaration outside the class is not
allowed. However, static data within classes is supported.
© Oxford University Press 2013. All rights reserved.
Differences between C++ and Java
• Operator overloading
– Operator overloading is not supported in java but there are few
operator which are already overloaded by java for e.g. +. Programmers
do not have the option of overloading operators.
• Explicit boolean type
– boolean is an explicit type, different from int. Only two boolean literals
are provided i.e. true and false. These cannot be compared with
integers 0 and 1 as used in some other languages.
• Array length accessible
– All array objects in java have a length variable associated with them to
determine the length of the array.
© Oxford University Press 2013. All rights reserved.
Differences between C++ and Java
• goto
– Instead of goto, break and continue are supported.
• Pointers
– There are no pointers in java.
• null pointers reasonably caught
– Null pointers are caught by a NullPointerException.
• Memory management
– Explicit destructor is not needed. The use of garbage collection
prevents memory leaks and referencing freed memory.
• Automatic variable initialization
– Variables are automatically initialized except local variables.
• Runtime container bounds checks
– The bounds of containers (arrays, strings, etc.) are checked at runtime
and an IndexOutOfBoundsException is thrown if necessary.
© Oxford University Press 2013. All rights reserved.
Differences between C++ and Java
• All definitions are well defined
– Methods and fields carry explicitly one of the access modifiers.
• Sizes of the integer types defined
– The sizes of the integer type’s byte, short, int and long are defined to
be 1, 2, 4 and 8 bytes.
• Unicode provided
– Unicode represents character in most of the languages for e.g.
Japanese, Latin e.t.c.
• String class
– An explicit predefined String class is provided along with StringBuffer
and new StringBuilder class.
© Oxford University Press 2013. All rights reserved.
Differences between C++ and Java
• Extended utility class libraries: package java.util
– Supported among others: Enumeration (an Iterator interface),
Hashtable, Vector.
• Multithreading support with synchronization
– Java supports Multithreading with synchronization among them.
• Default access specifier added
– By default, in java all variables, methods and classes have default privileges
which are different from private access specifier. Private is the default access
specifier in C++.
© Oxford University Press 2013. All rights reserved.
JVM and JRE
• JVM is a part of JRE
Java Runtime Environment
Operating Systems (Windows, Unix, etc.)
Hardware (Intel, Motorola, Alpha, etc.)
Program Structure
• A Java Application
consists of a collection of
classes.
• A class is a template
containing methods and
variables.
© Oxford University Press 2013. All rights reserved.
First Java Program
/* Call this file “Example.java”.*/
class Example {
//your program starts execution with a call to
//main()
public static void main(String args[ ]){
System.out.println(“This is a simple Java program”);
}
}
© Oxford University Press 2013. All rights reserved.
Executing Java Programs
• Entering the source code: text editor like notepad or any IDE
• Saving the source code:
– Select File | Save As from the notepad menu.
– In the ‘File name’ field, type “Example.java” within the double quotes
– In the ‘Save as type’ field select All Files (*.*).
– Click enter to save the file.
• Compiling & running the source
– type cmd at the run prompt
– move to the folder that contains the saved Example.java file
– compile the program using javac,
– C:javaeg>javac Example.java
© Oxford University Press 2013. All rights reserved.
Executing Java Programs
• Compilation creates a file called Example.class
• This class contains bytecode which is interpreted by
JVM.
• To execute the program type the following command
at the dos prompt:
– C:javaeg>java Example
• The output of the program is shown below:
– This is a simple Java program
© Oxford University Press 2013. All rights reserved.
Why save as Example.java?
• The name of the .class file will match exactly with the
name of the source file.
• That is why it is a good idea to give the Java source
files the same name as that of the class they contain.
• Java is case-sensitive.
• So example and Example are two different class
names.
© Oxford University Press 2013. All rights reserved.
Your Turn
• Let us revise the concepts
– What is platform independence?
– What is the relation between JVM and JRE?
– Differences between C++ and Java?
– Why the source file is named after the class name
in java?
© Oxford University Press 2013. All rights reserved.
Installation of Java
• Download the JDK installer
• Run the JDK installer.
• Update PATH Environment variables.
• Test the installation – run javac and java on
command prompt
Installed Directory structure
© Oxford University Press 2013. All rights reserved.
Installed Directory Structure
• src.zip file contains all the core class binaries, and is used by
JDK in this form.
• include directory contains a set of C and C++ header files for
interacting with C and C++.
• lib directory contains non-core classes like dt.jar and
tools.jar used by tools and utilities in JDK.
• bin The bin directory contains the binary executables for Java. For
example, Java Compiler (Java), Java Interpreter (Java) , rmicompiler, (rmic)
etc.
• jre is the root directory for the Java runtime environment.
• db contains java database
© Oxford University Press 2013. All rights reserved.
Exploring the JDK
© Oxford University Press 2013. All rights reserved.
Exploring the JDK
JDK=JRE + JAVA API
Tools in JDK
• Basic Tools in Java
© Oxford University Press 2013. All rights reserved.
IDE
• tools specifically designed for writing Java code.
• tools offer a GUI environment to compile and debug
your Javaprogram easily from the editor
environment, as well as browse through your classes
etc.
• Popular IDE’s
– Eclipse
– Netbeans
– Kawa
– JCreator
© Oxford University Press 2013. All rights reserved.
Summary
• Java is an object-oriented language.
• Java is designed to be platform Independent, so it can run on
multiple platforms.
• Every Java program consists of one or more classes.
• A class is nothing but a template for creating objects.
• In Java, code reside inside a class.
• Java bytecode executes on a special type of microprocessor.
• As, there was not a hardware implementation of this
microprocessor available when Java was first released, the
complete processor architecture was emulated by a software
known as virtual machine. (popularly known as JVM)

More Related Content

What's hot

Object oriented concepts with java
Object oriented concepts with javaObject oriented concepts with java
Object oriented concepts with java
ishmecse13
 
Introduction to oop and java fundamentals
Introduction to oop and java fundamentalsIntroduction to oop and java fundamentals
Introduction to oop and java fundamentals
AnsgarMary
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java Programming
Math-Circle
 
Short notes of oop with java
Short notes of oop with javaShort notes of oop with java
Short notes of oop with java
Mohamed Fathy
 
CS8392 OOP
CS8392 OOPCS8392 OOP
Practical OOP In Java
Practical OOP In JavaPractical OOP In Java
Practical OOP In Java
wiradikusuma
 
1. Overview of Java
1. Overview of Java1. Overview of Java
1. Overview of Java
Nilesh Dalvi
 
Abstract class and Interface
Abstract class and InterfaceAbstract class and Interface
Abstract class and Interface
Haris Bin Zahid
 
java training in jaipur|java training|core java training|java training compa...
 java training in jaipur|java training|core java training|java training compa... java training in jaipur|java training|core java training|java training compa...
java training in jaipur|java training|core java training|java training compa...
infojaipurinfo Jaipur
 
Packages
PackagesPackages
Packages
Ravi Kant Sahu
 
Core java
Core java Core java
Core java
Ravi varma
 
Basics of Java
Basics of JavaBasics of Java
Basics of Java
Sherihan Anver
 
6. Exception Handling
6. Exception Handling6. Exception Handling
6. Exception Handling
Nilesh Dalvi
 
Object+oriented+programming+in+java
Object+oriented+programming+in+javaObject+oriented+programming+in+java
Object+oriented+programming+in+java
Ye Win
 
Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101
kankemwa Ishaku
 
Core java notes with examples
Core java notes with examplesCore java notes with examples
Core java notes with examples
bindur87
 
Object oriented programming-with_java
Object oriented programming-with_javaObject oriented programming-with_java
Object oriented programming-with_java
Hoang Nguyen
 
Core java
Core javaCore java
Core java
kasaragaddaslide
 

What's hot (18)

Object oriented concepts with java
Object oriented concepts with javaObject oriented concepts with java
Object oriented concepts with java
 
Introduction to oop and java fundamentals
Introduction to oop and java fundamentalsIntroduction to oop and java fundamentals
Introduction to oop and java fundamentals
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java Programming
 
Short notes of oop with java
Short notes of oop with javaShort notes of oop with java
Short notes of oop with java
 
CS8392 OOP
CS8392 OOPCS8392 OOP
CS8392 OOP
 
Practical OOP In Java
Practical OOP In JavaPractical OOP In Java
Practical OOP In Java
 
1. Overview of Java
1. Overview of Java1. Overview of Java
1. Overview of Java
 
Abstract class and Interface
Abstract class and InterfaceAbstract class and Interface
Abstract class and Interface
 
java training in jaipur|java training|core java training|java training compa...
 java training in jaipur|java training|core java training|java training compa... java training in jaipur|java training|core java training|java training compa...
java training in jaipur|java training|core java training|java training compa...
 
Packages
PackagesPackages
Packages
 
Core java
Core java Core java
Core java
 
Basics of Java
Basics of JavaBasics of Java
Basics of Java
 
6. Exception Handling
6. Exception Handling6. Exception Handling
6. Exception Handling
 
Object+oriented+programming+in+java
Object+oriented+programming+in+javaObject+oriented+programming+in+java
Object+oriented+programming+in+java
 
Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101
 
Core java notes with examples
Core java notes with examplesCore java notes with examples
Core java notes with examples
 
Object oriented programming-with_java
Object oriented programming-with_javaObject oriented programming-with_java
Object oriented programming-with_java
 
Core java
Core javaCore java
Core java
 

Similar to GETTING STARTED WITH JAVA(beginner)

oop unit1.pptx
oop unit1.pptxoop unit1.pptx
oop unit1.pptx
sureshkumara29
 
Java Introduction
Java IntroductionJava Introduction
Java Introduction
sunmitraeducation
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introduction
jyoti_lakhani
 
OOP with Java
OOP with JavaOOP with Java
OOP with Java
OmegaHub
 
JAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptxJAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptx
Murugesh33
 
JAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptxJAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptx
Murugesh33
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
Professional Guru
 
Presentation 1.pptx
Presentation 1.pptxPresentation 1.pptx
Presentation 1.pptx
PranavSoni19
 
java full 1 (Recovered).docx
java full 1 (Recovered).docxjava full 1 (Recovered).docx
java full 1 (Recovered).docx
SATHYAKALAKSKPRCASBS
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
Professional Guru
 
java completed units.docx
java completed units.docxjava completed units.docx
java completed units.docx
SATHYAKALAKSKPRCASBS
 
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptxJAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
AALIM MUHAMMED SALEGH COLLEGE OF ENGINEERING
 
Comp102 lec 3
Comp102   lec 3Comp102   lec 3
Comp102 lec 3
Fraz Bakhsh
 
java full 1.docx
java full 1.docxjava full 1.docx
java full 1.docx
SATHYAKALAKSKPRCASBS
 
java full.docx
java full.docxjava full.docx
java full.docx
SATHYAKALAKSKPRCASBS
 
Skillwise Elementary Java Programming
Skillwise Elementary Java ProgrammingSkillwise Elementary Java Programming
Skillwise Elementary Java Programming
Skillwise Group
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
Phaniu
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
javeed_mhd
 
Java Basics
Java BasicsJava Basics
Java Basics
Khan625
 
Java in Mule
Java in MuleJava in Mule
Java in Mule
Shahid Shaik
 

Similar to GETTING STARTED WITH JAVA(beginner) (20)

oop unit1.pptx
oop unit1.pptxoop unit1.pptx
oop unit1.pptx
 
Java Introduction
Java IntroductionJava Introduction
Java Introduction
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introduction
 
OOP with Java
OOP with JavaOOP with Java
OOP with Java
 
JAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptxJAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptx
 
JAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptxJAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptx
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Presentation 1.pptx
Presentation 1.pptxPresentation 1.pptx
Presentation 1.pptx
 
java full 1 (Recovered).docx
java full 1 (Recovered).docxjava full 1 (Recovered).docx
java full 1 (Recovered).docx
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
java completed units.docx
java completed units.docxjava completed units.docx
java completed units.docx
 
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptxJAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
 
Comp102 lec 3
Comp102   lec 3Comp102   lec 3
Comp102 lec 3
 
java full 1.docx
java full 1.docxjava full 1.docx
java full 1.docx
 
java full.docx
java full.docxjava full.docx
java full.docx
 
Skillwise Elementary Java Programming
Skillwise Elementary Java ProgrammingSkillwise Elementary Java Programming
Skillwise Elementary Java Programming
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Java in Mule
Java in MuleJava in Mule
Java in Mule
 

More from HarshithaAllu

Environmenal protection
Environmenal protectionEnvironmenal protection
Environmenal protection
HarshithaAllu
 
Social project work-political parties
Social project work-political partiesSocial project work-political parties
Social project work-political parties
HarshithaAllu
 
ROLE OF PRINT MEDIA IN FREEDOM STRUGGLE
ROLE OF PRINT MEDIA IN FREEDOM STRUGGLEROLE OF PRINT MEDIA IN FREEDOM STRUGGLE
ROLE OF PRINT MEDIA IN FREEDOM STRUGGLE
HarshithaAllu
 
Operating system
Operating systemOperating system
Operating system
HarshithaAllu
 
java programming - applets
java programming - appletsjava programming - applets
java programming - applets
HarshithaAllu
 
PRAGRAMMING IN JAVA (BEGINNER)
PRAGRAMMING IN JAVA (BEGINNER)PRAGRAMMING IN JAVA (BEGINNER)
PRAGRAMMING IN JAVA (BEGINNER)
HarshithaAllu
 
Structure of neuron
Structure of neuronStructure of neuron
Structure of neuron
HarshithaAllu
 
Hyper text transport protocol
Hyper text transport protocolHyper text transport protocol
Hyper text transport protocol
HarshithaAllu
 
PRESSENTATION SKILLS
PRESSENTATION SKILLSPRESSENTATION SKILLS
PRESSENTATION SKILLS
HarshithaAllu
 
IR remote sensing technology
IR remote sensing technologyIR remote sensing technology
IR remote sensing technology
HarshithaAllu
 
Closed loop (automated) insulin delivery
Closed loop (automated) insulin delivery Closed loop (automated) insulin delivery
Closed loop (automated) insulin delivery
HarshithaAllu
 

More from HarshithaAllu (11)

Environmenal protection
Environmenal protectionEnvironmenal protection
Environmenal protection
 
Social project work-political parties
Social project work-political partiesSocial project work-political parties
Social project work-political parties
 
ROLE OF PRINT MEDIA IN FREEDOM STRUGGLE
ROLE OF PRINT MEDIA IN FREEDOM STRUGGLEROLE OF PRINT MEDIA IN FREEDOM STRUGGLE
ROLE OF PRINT MEDIA IN FREEDOM STRUGGLE
 
Operating system
Operating systemOperating system
Operating system
 
java programming - applets
java programming - appletsjava programming - applets
java programming - applets
 
PRAGRAMMING IN JAVA (BEGINNER)
PRAGRAMMING IN JAVA (BEGINNER)PRAGRAMMING IN JAVA (BEGINNER)
PRAGRAMMING IN JAVA (BEGINNER)
 
Structure of neuron
Structure of neuronStructure of neuron
Structure of neuron
 
Hyper text transport protocol
Hyper text transport protocolHyper text transport protocol
Hyper text transport protocol
 
PRESSENTATION SKILLS
PRESSENTATION SKILLSPRESSENTATION SKILLS
PRESSENTATION SKILLS
 
IR remote sensing technology
IR remote sensing technologyIR remote sensing technology
IR remote sensing technology
 
Closed loop (automated) insulin delivery
Closed loop (automated) insulin delivery Closed loop (automated) insulin delivery
Closed loop (automated) insulin delivery
 

Recently uploaded

Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
Hironori Washizaki
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Undress Baby
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Envertis Software Solutions
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
lorraineandreiamcidl
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
aymanquadri279
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 

Recently uploaded (20)

Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 

GETTING STARTED WITH JAVA(beginner)

  • 1. © Oxford University Press 2013. All rights reserved. Programming in Java, 2e Sachin Malhotra Saurabh Choudhary
  • 2. © Oxford University Press 2013. All rights reserved. Chapter 2 Getting started with java
  • 3. © Oxford University Press 2013. All rights reserved. Objective • Know the Java Features and its Runtime Environment • Get familiar with new releases in Java • Understand the basic structure of a Java program • Get into the details about JDK Installation • Know about the various constituents of JDK and its development environments.
  • 4. © Oxford University Press 2013. All rights reserved. Introduction • Java is a programming language invented by James Gosling and others in 1994. • originally named Oak ,was developed as a part of the Green project at the Sun Company. • Java 7 is latest stable release.
  • 5. © Oxford University Press 2013. All rights reserved. Java Essentials • A high level language • Java Bytecode – intermediate code • Java Virtual Machine (JVM) – interpreter for bytecode
  • 6. © Oxford University Press 2013. All rights reserved. Java Runtime JAVA SOURCE CODE JAVA BYTE CODE JAVA VIRTUAL MACHINE (JVM) Compilation Interpretation Java Runtime Environment includes JVM, class libraries and other supporting files.
  • 7. © Oxford University Press 2013. All rights reserved. Java Approach
  • 8. © Oxford University Press 2013. All rights reserved. Java Features • Platform Independence • Object oriented • Compiled and interpreted • Robust • Security – Strictly typed language – Lack of pointers – Garbage collection – Strict compile time checking – Sandbox security
  • 9. © Oxford University Press 2013. All rights reserved. Java Features • Multithreaded • Dynamic binding • Performance • Networking • No pointers • No global variables • Automatic Garbage collection
  • 10. © Oxford University Press 2013. All rights reserved. Java 5 New features • Autoboxing and unboxing • Enhanced For loop • Metadata • Variable arguments • Static import • Graphics enhancemnets • Generics • Enum • StringBuilder class
  • 11. © Oxford University Press 2013. All rights reserved. Java 6 New features • Enhancements in Collections API • Console class • Jar and Zip enhacements • Enhancements to Network Interface • Enhancements in Java web start and plug in
  • 12. © Oxford University Press 2013. All rights reserved. Java 7 New Features • String in switch…case Statement • Unicode 6.0.0 Support • Binary Literals and Numeric Literals (with Underscores) • Automatic Resource Management • Improved Exception Handling • nio 2.0 (Non-blocking I/O)—New File System API
  • 13. © Oxford University Press 2013. All rights reserved. Java 7 features (contd.) • Fork and Join for parallel processing • Supporting Dynamism using invokedynamic to let JVM resolve type info at runtime • No need of Diamond Operator <> on right side of the expression • Swing Enhancements • Java FX 2.2.3 provides the new GUI toolkit for creating rich cross-platform user interfaces
  • 15. © Oxford University Press 2013. All rights reserved. Differences between C++ and Java • Multiple Inheritance not allowed – Multi level inheritance is enforced, which makes the design clearer. Multiple inheritance among classes is not supported in java. Interfaces are used for supporting multiple inheritance • Common parent – All classes are single-rooted. The class Object is the parent of all the classes in java. • Packages – The concept of packages is used, i.e. a large, hierarchical namespace is provided. This prevents naming ambiguities in libraries. • In-source documentation – In-source code documentation comments are provided. Documentation keywords are provided for e.g.: @author, @version e.t.c. • All code inside class – All code resides inside a class. Global data declaration outside the class is not allowed. However, static data within classes is supported.
  • 16. © Oxford University Press 2013. All rights reserved. Differences between C++ and Java • Operator overloading – Operator overloading is not supported in java but there are few operator which are already overloaded by java for e.g. +. Programmers do not have the option of overloading operators. • Explicit boolean type – boolean is an explicit type, different from int. Only two boolean literals are provided i.e. true and false. These cannot be compared with integers 0 and 1 as used in some other languages. • Array length accessible – All array objects in java have a length variable associated with them to determine the length of the array.
  • 17. © Oxford University Press 2013. All rights reserved. Differences between C++ and Java • goto – Instead of goto, break and continue are supported. • Pointers – There are no pointers in java. • null pointers reasonably caught – Null pointers are caught by a NullPointerException. • Memory management – Explicit destructor is not needed. The use of garbage collection prevents memory leaks and referencing freed memory. • Automatic variable initialization – Variables are automatically initialized except local variables. • Runtime container bounds checks – The bounds of containers (arrays, strings, etc.) are checked at runtime and an IndexOutOfBoundsException is thrown if necessary.
  • 18. © Oxford University Press 2013. All rights reserved. Differences between C++ and Java • All definitions are well defined – Methods and fields carry explicitly one of the access modifiers. • Sizes of the integer types defined – The sizes of the integer type’s byte, short, int and long are defined to be 1, 2, 4 and 8 bytes. • Unicode provided – Unicode represents character in most of the languages for e.g. Japanese, Latin e.t.c. • String class – An explicit predefined String class is provided along with StringBuffer and new StringBuilder class.
  • 19. © Oxford University Press 2013. All rights reserved. Differences between C++ and Java • Extended utility class libraries: package java.util – Supported among others: Enumeration (an Iterator interface), Hashtable, Vector. • Multithreading support with synchronization – Java supports Multithreading with synchronization among them. • Default access specifier added – By default, in java all variables, methods and classes have default privileges which are different from private access specifier. Private is the default access specifier in C++.
  • 20. © Oxford University Press 2013. All rights reserved. JVM and JRE • JVM is a part of JRE Java Runtime Environment Operating Systems (Windows, Unix, etc.) Hardware (Intel, Motorola, Alpha, etc.)
  • 21. Program Structure • A Java Application consists of a collection of classes. • A class is a template containing methods and variables.
  • 22. © Oxford University Press 2013. All rights reserved. First Java Program /* Call this file “Example.java”.*/ class Example { //your program starts execution with a call to //main() public static void main(String args[ ]){ System.out.println(“This is a simple Java program”); } }
  • 23. © Oxford University Press 2013. All rights reserved. Executing Java Programs • Entering the source code: text editor like notepad or any IDE • Saving the source code: – Select File | Save As from the notepad menu. – In the ‘File name’ field, type “Example.java” within the double quotes – In the ‘Save as type’ field select All Files (*.*). – Click enter to save the file. • Compiling & running the source – type cmd at the run prompt – move to the folder that contains the saved Example.java file – compile the program using javac, – C:javaeg>javac Example.java
  • 24. © Oxford University Press 2013. All rights reserved. Executing Java Programs • Compilation creates a file called Example.class • This class contains bytecode which is interpreted by JVM. • To execute the program type the following command at the dos prompt: – C:javaeg>java Example • The output of the program is shown below: – This is a simple Java program
  • 25. © Oxford University Press 2013. All rights reserved. Why save as Example.java? • The name of the .class file will match exactly with the name of the source file. • That is why it is a good idea to give the Java source files the same name as that of the class they contain. • Java is case-sensitive. • So example and Example are two different class names.
  • 26. © Oxford University Press 2013. All rights reserved. Your Turn • Let us revise the concepts – What is platform independence? – What is the relation between JVM and JRE? – Differences between C++ and Java? – Why the source file is named after the class name in java?
  • 27. © Oxford University Press 2013. All rights reserved. Installation of Java • Download the JDK installer • Run the JDK installer. • Update PATH Environment variables. • Test the installation – run javac and java on command prompt
  • 29. © Oxford University Press 2013. All rights reserved. Installed Directory Structure • src.zip file contains all the core class binaries, and is used by JDK in this form. • include directory contains a set of C and C++ header files for interacting with C and C++. • lib directory contains non-core classes like dt.jar and tools.jar used by tools and utilities in JDK. • bin The bin directory contains the binary executables for Java. For example, Java Compiler (Java), Java Interpreter (Java) , rmicompiler, (rmic) etc. • jre is the root directory for the Java runtime environment. • db contains java database
  • 30. © Oxford University Press 2013. All rights reserved. Exploring the JDK
  • 31. © Oxford University Press 2013. All rights reserved. Exploring the JDK JDK=JRE + JAVA API
  • 32. Tools in JDK • Basic Tools in Java
  • 33. © Oxford University Press 2013. All rights reserved. IDE • tools specifically designed for writing Java code. • tools offer a GUI environment to compile and debug your Javaprogram easily from the editor environment, as well as browse through your classes etc. • Popular IDE’s – Eclipse – Netbeans – Kawa – JCreator
  • 34. © Oxford University Press 2013. All rights reserved. Summary • Java is an object-oriented language. • Java is designed to be platform Independent, so it can run on multiple platforms. • Every Java program consists of one or more classes. • A class is nothing but a template for creating objects. • In Java, code reside inside a class. • Java bytecode executes on a special type of microprocessor. • As, there was not a hardware implementation of this microprocessor available when Java was first released, the complete processor architecture was emulated by a software known as virtual machine. (popularly known as JVM)