SlideShare a Scribd company logo
1 of 56
Basics of Java Programming
Prepared By: Minal Maniar,
Asst. Professor, CSPIT, CHARUSAT
Outline
• Evolution of programming Languages
• Popular Programming Languages
• History of Java
• Modules of Java
• Applications of Java
Evolution of Programming Languages
Popular Programming Languages in 2018
Java – History & Introduction
• James Gosling and team at Sun Microsystems , 1995
• Oak - The predecessor of Java
• Created for consumer electronics
• HotJava
• The first Java-enabled Web browser
• JDK Evolutions
• Java is “C++ -- ++”
3 Modules of Java
• J2SE : Java Standard Edition
• 1 –tier or 1 layer
• VB.NET, D2K, PB, Fox Pro – Platform dependent (alternatives)
• J2EE : Java Enterprise Edition
• J2ME : Java Micro Edition
Why you choose Java?
• Simple and Powerful
• Object Oriented
• Portable
• Architecture Neutral
• Distributed
• Multi-threaded
• Robust, Secure/Safe
• Interpreted
• High Performance
• Dynamic programming language/platform
Java Buzz Words!!!!
Applications of Java
Running a Java Program
Compile & Run Java Program
• How to Compile?
• How to Run?
Hello.java Hello.class
Just In Time
Compiler
Hello.class
JVM OS
JDK & JRE
• Java Development Kit contains
tools needed to develop Java
Programs.
• Javadoc
• Javac.exe
• Java.exe
• Applet viewer etc.
• https://docs.oracle.com/javase/
8/docs/api/
• Java Runtime Environment
• Used to run Java program
• It contains JVM and Java Package
classes – Java Library
• JVM interprets the bytecode into
machine code depending upon
the underlying operating system
and hardware combination.
First Java Program : Welcome.java
Use Pascal Notation
to declare a class
Naming Conventions : camelCase &
PascalCase(Upper CamelCase)
• CompareDigit
• MyFirstProgram
• FirstProgramDemo
• calculateInterest()
• int firstNumber = 11;
• iPhone, eBay, FedEx,
DreamWorks
Questions…
• What are features of Java?
• What is Bytecode?
• Is Java Platform independent? Justify your answer.
• Is JVM Platform independent? Justify your answer.
• Is JVM Hardware or Software?
• Explain JDK, JRE and JVM.
• Explain public static void main(String args[]).
Java Basics
Outline
• How do we create code?
• Variables and data types
• Arrays & String Handling
• The Object class
A Car Represented in Code
• Attributes: Describing the Car class
• License Plate number
• Average Miles per gallon
• Paint color
• Operations: Interacting with Car class
• Check the tail lights
• Change the paint
Three Independent Cars
CAR A
• License plate:
“GJ1B21890
• Average MPG:
25.5
• Paint Color: Blue
CAR B
• License plate:
“GJ02C2170
• Average MPG:
20.5
• Paint Color:
Black
CAR C
• License plate:
“GJ03D5710
• Average MPG:
23.5
• Paint Color:
White
Program to introduce variables
• Variable is name of reserved area allocated in memory.
• It is a name of memory location.
• Define a Car class with variable
Heap Space vs Stack – Memory Allocation in Java
Heap Space vs Stack – Memory Allocation in Java
Types of Variable
• There are three types of variables in java:
Types of Variables
Instance variable
Local Variable
Static variable
Static variable initialization
Java Primitive Data Types
Default values of Primitive Data Types
Data Type Default Value Default size
boolean false 1 bit
char 'u0000' 2 byte
byte 0 1 byte
short 0 2 byte
int 0 4 byte
long 0L 8 byte
float 0.0f 4 byte
double 0.0d 8 byte
• Program of counter without static variable
Arrays
• Set of homogeneous elements
• There are two types of array.
• Single Dimensional Array
• Multidimensional Array
• Syntax to Declare single dimensional Array in java
• dataType[] arr; (or)
• dataType []arr; (or)
• dataType arr[];
Array Declaration- One Dimensional
1. int a[]=new int[3];//declaration and instantiation
a[0]=10;//initialization
a[1]=20;
a[2]=30;
2. int a[]={10,20,30};//declaration, instantiation and initialization
Array Declaration- Multi Dimensional
dataType[][] arrayRefVar; (or)
dataType [][]arrayRefVar; (or)
dataType arrayRefVar[][]; (or)
dataType []arrayRefVar[];
int [][]f;
float[][] f1;
double f2[][];
boolean []b[];
Which of the following statements are valid?
int[][] r = new int[2];
int[] x = new int[];
int[][] y = new int[3][];
int[][] z = {{1, 2}};
int[][] m = {{1, 2}, {2, 3}};
int[][] n = {{1, 2}, {2, 3}, };
Ragged Arrays or Jagged Arrays
• Each row in a two-dimensional array is itself an array. Thus, the rows
can have different lengths. (varying no of columns in each row)
• An array of this kind is known as a ragged array.
Ragged Arrays or Jagged Arrays
• If you If you don’t know the values in a ragged array in advance, but
do know the sizes—say, the same as before—you can create a ragged
array using the following syntax:
• triangleArray[0].length = 5
• triangleArray[1].length = 4
• triangleArray[2].length = 3
• triangleArray[3].length = 2
• triangleArray[4].length = 1
What is the output of the following code?
Output
The Arrays class
Explore following methods of Array class
• Arrays.toString()
• Arrays.deepToString()
• Arrays.sort()
• Arrays.fill()
String Handling
The String Type
• A string is a sequence of characters.
• The java String is immutable.
• Whenever we change any string,
a new instance is created.
• For mutable string,
you can use
StringBuffer & StringBuilder classes.
Two ways to create String object:
String Literal
• String s1="Welcome";
• String s2="Welcome";//will not create new instance
By new
keyword
• String s=new String("Welcome");
//creates two objects and one reference variable
Java uses the concept of string literal, that is
why string objects are immutable in java.
String compare by equals() method
Output
String compare by == operator
Output
Methods of String Class
StringBuffer class
class creates strings of flexible length that can be
modified in terms of both length and content.
• Available in java.lang package
• Thread-safe
Output
16
20
21
Reserves room for 16 characters
without reallocation
Sets initial contents of StringBuffer and
allocates room for 16 characters
Explicitly sets size of buffer
String Concatenation test -String: 16ms
Output
String Concatenation test StringBuffer: 16ms
Output
StringBuffer Methods
• length() and capacity()
• ensureCapacity()
• charAt() & setCharAt()
• getChars()
• Insert() & reverse()
• delete() & deleteAll()
• replace()
• substring()
• append()
• indexOf()
• lastIndexOf()
• trimToSize()
• subsequence()
The StringBuilder class
• StringBuilder is a relatively recent addition to Java’s string handling
capabilities.
• StringBuilder is similar to StringBuffer except for one important
difference: it is not synchronized, which means that it is not thread-
safe.
• The advantage of StringBuilder is faster performance.
• However, in cases in which a mutable string will be accessed by
multiple threads, and no external synchronization is employed, you
must use StringBuffer rather than StringBuilder.
StringTokenizer class
• The processing of text often consists of
parsing a formatted input string.
• Parsing is the division of text into a set of
discrete parts, or tokens, which in a certain
sequence can convey a semantic meaning.
• The StringTokenizer class provides the first
step in this parsing process, often called the
lexer (lexical analyzer) or scanner.
• StringTokenizer implements the
Enumeration interface. Therefore, given an
input string, you can enumerate the
individual tokens contained in it using
StringTokenizer.
• To use StringTokenizer, you specify an input
string and a string that contains delimiters.
• Delimiters are characters that separate
tokens.
Delimiter: space (“ “)
StringTokenizer Example
Output
Exercise : Count no of words and lines in given string.
The Object Class
• To use StringTokenizer, you specify an input string and a string that
contains delimiters.
• Delimiters are characters that separate tokens.
The Object Class
• There is one special class, Object, defined by Java. All other classes
are subclasses of Object.
• That is, Object is a superclass of all other classes. This means that a
reference variable of type Object can refer to an object of any other
class. Also, since arrays are implemented as classes, a variable of type
Object can also refer to any array.
• Object defines the following methods, which means that they are
available in every object.
Methods of Object class
References
• http://www.geeksforgeeks.org
• http://beginnersbook.com
• Introduction to Java Programming, Comprehensive Version (10th
Edition), Y. Daniel Liang
• https://www.Lynda.com
• http://www.javatpoint.com

More Related Content

What's hot

Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsEmiel Paasschens
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java ProgrammingMath-Circle
 
Functional Programming In Jdk8
Functional Programming In Jdk8 Functional Programming In Jdk8
Functional Programming In Jdk8 Bansilal Haudakari
 
Let's start with Java- Basic Concepts
Let's start with Java- Basic ConceptsLet's start with Java- Basic Concepts
Let's start with Java- Basic ConceptsAashish Jain
 
java 8 new features
java 8 new features java 8 new features
java 8 new features Rohit Verma
 
Playing with Java Classes and Bytecode
Playing with Java Classes and BytecodePlaying with Java Classes and Bytecode
Playing with Java Classes and BytecodeYoav Avrahami
 
Placement and variable 03 (js)
Placement and variable 03 (js)Placement and variable 03 (js)
Placement and variable 03 (js)AbhishekMondal42
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_reviewEdureka!
 
Introduction to JavaScript Programming
Introduction to JavaScript ProgrammingIntroduction to JavaScript Programming
Introduction to JavaScript ProgrammingRaveendra R
 
Java Tutorial Lab 1
Java Tutorial Lab 1Java Tutorial Lab 1
Java Tutorial Lab 1Berk Soysal
 

What's hot (20)

Core java
Core javaCore java
Core java
 
Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java Programming
 
Functional Programming In Jdk8
Functional Programming In Jdk8 Functional Programming In Jdk8
Functional Programming In Jdk8
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
Let's start with Java- Basic Concepts
Let's start with Java- Basic ConceptsLet's start with Java- Basic Concepts
Let's start with Java- Basic Concepts
 
JAVA BASICS
JAVA BASICSJAVA BASICS
JAVA BASICS
 
java 8 new features
java 8 new features java 8 new features
java 8 new features
 
Basics of Java
Basics of JavaBasics of Java
Basics of Java
 
Chapter 2 java
Chapter 2 javaChapter 2 java
Chapter 2 java
 
Playing with Java Classes and Bytecode
Playing with Java Classes and BytecodePlaying with Java Classes and Bytecode
Playing with Java Classes and Bytecode
 
Placement and variable 03 (js)
Placement and variable 03 (js)Placement and variable 03 (js)
Placement and variable 03 (js)
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
 
Introduction to JavaScript Programming
Introduction to JavaScript ProgrammingIntroduction to JavaScript Programming
Introduction to JavaScript Programming
 
Java Tutorial Lab 1
Java Tutorial Lab 1Java Tutorial Lab 1
Java Tutorial Lab 1
 
Of Lambdas and LINQ
Of Lambdas and LINQOf Lambdas and LINQ
Of Lambdas and LINQ
 
Core Java Tutorial
Core Java TutorialCore Java Tutorial
Core Java Tutorial
 
Core java
Core javaCore java
Core java
 

Similar to Basics of Java Programming

Similar to Basics of Java Programming (20)

Learning core java
Learning core javaLearning core java
Learning core java
 
Unit 1
Unit 1Unit 1
Unit 1
 
COMPUTER PROGRAMMING LANGUAGE.pptx
COMPUTER PROGRAMMING LANGUAGE.pptxCOMPUTER PROGRAMMING LANGUAGE.pptx
COMPUTER PROGRAMMING LANGUAGE.pptx
 
intro_java (1).pptx
intro_java (1).pptxintro_java (1).pptx
intro_java (1).pptx
 
Java programing language unit 1 introduction
Java programing language unit 1 introductionJava programing language unit 1 introduction
Java programing language unit 1 introduction
 
Java Fx
Java FxJava Fx
Java Fx
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 
ppt_on_java.pptx
ppt_on_java.pptxppt_on_java.pptx
ppt_on_java.pptx
 
Java platform
Java platformJava platform
Java platform
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
 
JAVA BYTE CODE
JAVA BYTE CODEJAVA BYTE CODE
JAVA BYTE CODE
 
Java
JavaJava
Java
 
Developer’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageDeveloper’s viewpoint on swift programming language
Developer’s viewpoint on swift programming language
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Java introduction
Java introductionJava introduction
Java introduction
 
Lecture2_Datatypes_Variables.ppt
Lecture2_Datatypes_Variables.pptLecture2_Datatypes_Variables.ppt
Lecture2_Datatypes_Variables.ppt
 
C# language
C# languageC# language
C# language
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Programming in java basics
Programming in java  basicsProgramming in java  basics
Programming in java basics
 
Java OOP Concepts 1st Slide
Java OOP Concepts 1st SlideJava OOP Concepts 1st Slide
Java OOP Concepts 1st Slide
 

More from Minal Maniar

More from Minal Maniar (13)

Exception handling
Exception handlingException handling
Exception handling
 
Java servlet technology
Java servlet technologyJava servlet technology
Java servlet technology
 
Multi t hreading_14_10
Multi t hreading_14_10Multi t hreading_14_10
Multi t hreading_14_10
 
Io
IoIo
Io
 
Object oriented thinking
Object oriented thinkingObject oriented thinking
Object oriented thinking
 
2 class use case
2 class use case2 class use case
2 class use case
 
Oop java
Oop javaOop java
Oop java
 
1 modeling concepts
1 modeling concepts1 modeling concepts
1 modeling concepts
 
5 collection framework
5 collection framework5 collection framework
5 collection framework
 
4 sdlc
4 sdlc4 sdlc
4 sdlc
 
3 interaction and_state_modeling
3 interaction and_state_modeling3 interaction and_state_modeling
3 interaction and_state_modeling
 
modeling concepts
modeling conceptsmodeling concepts
modeling concepts
 
modeling concepts
modeling conceptsmodeling concepts
modeling concepts
 

Recently uploaded

chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 

Recently uploaded (20)

chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 

Basics of Java Programming

  • 1. Basics of Java Programming Prepared By: Minal Maniar, Asst. Professor, CSPIT, CHARUSAT
  • 2. Outline • Evolution of programming Languages • Popular Programming Languages • History of Java • Modules of Java • Applications of Java
  • 5. Java – History & Introduction • James Gosling and team at Sun Microsystems , 1995 • Oak - The predecessor of Java • Created for consumer electronics • HotJava • The first Java-enabled Web browser • JDK Evolutions • Java is “C++ -- ++”
  • 6. 3 Modules of Java • J2SE : Java Standard Edition • 1 –tier or 1 layer • VB.NET, D2K, PB, Fox Pro – Platform dependent (alternatives) • J2EE : Java Enterprise Edition • J2ME : Java Micro Edition
  • 7. Why you choose Java? • Simple and Powerful • Object Oriented • Portable • Architecture Neutral • Distributed • Multi-threaded • Robust, Secure/Safe • Interpreted • High Performance • Dynamic programming language/platform Java Buzz Words!!!!
  • 9. Running a Java Program
  • 10. Compile & Run Java Program • How to Compile? • How to Run? Hello.java Hello.class Just In Time Compiler Hello.class JVM OS
  • 11. JDK & JRE • Java Development Kit contains tools needed to develop Java Programs. • Javadoc • Javac.exe • Java.exe • Applet viewer etc. • https://docs.oracle.com/javase/ 8/docs/api/ • Java Runtime Environment • Used to run Java program • It contains JVM and Java Package classes – Java Library • JVM interprets the bytecode into machine code depending upon the underlying operating system and hardware combination.
  • 12.
  • 13. First Java Program : Welcome.java Use Pascal Notation to declare a class
  • 14. Naming Conventions : camelCase & PascalCase(Upper CamelCase) • CompareDigit • MyFirstProgram • FirstProgramDemo • calculateInterest() • int firstNumber = 11; • iPhone, eBay, FedEx, DreamWorks
  • 15. Questions… • What are features of Java? • What is Bytecode? • Is Java Platform independent? Justify your answer. • Is JVM Platform independent? Justify your answer. • Is JVM Hardware or Software? • Explain JDK, JRE and JVM. • Explain public static void main(String args[]).
  • 17. Outline • How do we create code? • Variables and data types • Arrays & String Handling • The Object class
  • 18.
  • 19. A Car Represented in Code • Attributes: Describing the Car class • License Plate number • Average Miles per gallon • Paint color • Operations: Interacting with Car class • Check the tail lights • Change the paint
  • 20. Three Independent Cars CAR A • License plate: “GJ1B21890 • Average MPG: 25.5 • Paint Color: Blue CAR B • License plate: “GJ02C2170 • Average MPG: 20.5 • Paint Color: Black CAR C • License plate: “GJ03D5710 • Average MPG: 23.5 • Paint Color: White
  • 21. Program to introduce variables • Variable is name of reserved area allocated in memory. • It is a name of memory location. • Define a Car class with variable
  • 22. Heap Space vs Stack – Memory Allocation in Java
  • 23. Heap Space vs Stack – Memory Allocation in Java
  • 24. Types of Variable • There are three types of variables in java:
  • 25. Types of Variables Instance variable Local Variable Static variable
  • 27.
  • 29. Default values of Primitive Data Types Data Type Default Value Default size boolean false 1 bit char 'u0000' 2 byte byte 0 1 byte short 0 2 byte int 0 4 byte long 0L 8 byte float 0.0f 4 byte double 0.0d 8 byte
  • 30. • Program of counter without static variable
  • 31. Arrays • Set of homogeneous elements • There are two types of array. • Single Dimensional Array • Multidimensional Array • Syntax to Declare single dimensional Array in java • dataType[] arr; (or) • dataType []arr; (or) • dataType arr[];
  • 32. Array Declaration- One Dimensional 1. int a[]=new int[3];//declaration and instantiation a[0]=10;//initialization a[1]=20; a[2]=30; 2. int a[]={10,20,30};//declaration, instantiation and initialization
  • 33. Array Declaration- Multi Dimensional dataType[][] arrayRefVar; (or) dataType [][]arrayRefVar; (or) dataType arrayRefVar[][]; (or) dataType []arrayRefVar[]; int [][]f; float[][] f1; double f2[][]; boolean []b[];
  • 34. Which of the following statements are valid? int[][] r = new int[2]; int[] x = new int[]; int[][] y = new int[3][]; int[][] z = {{1, 2}}; int[][] m = {{1, 2}, {2, 3}}; int[][] n = {{1, 2}, {2, 3}, };
  • 35. Ragged Arrays or Jagged Arrays • Each row in a two-dimensional array is itself an array. Thus, the rows can have different lengths. (varying no of columns in each row) • An array of this kind is known as a ragged array.
  • 36. Ragged Arrays or Jagged Arrays • If you If you don’t know the values in a ragged array in advance, but do know the sizes—say, the same as before—you can create a ragged array using the following syntax: • triangleArray[0].length = 5 • triangleArray[1].length = 4 • triangleArray[2].length = 3 • triangleArray[3].length = 2 • triangleArray[4].length = 1
  • 37. What is the output of the following code? Output
  • 38. The Arrays class Explore following methods of Array class • Arrays.toString() • Arrays.deepToString() • Arrays.sort() • Arrays.fill()
  • 40. The String Type • A string is a sequence of characters. • The java String is immutable. • Whenever we change any string, a new instance is created. • For mutable string, you can use StringBuffer & StringBuilder classes.
  • 41. Two ways to create String object: String Literal • String s1="Welcome"; • String s2="Welcome";//will not create new instance By new keyword • String s=new String("Welcome"); //creates two objects and one reference variable
  • 42. Java uses the concept of string literal, that is why string objects are immutable in java.
  • 43. String compare by equals() method Output
  • 44. String compare by == operator Output
  • 46. StringBuffer class class creates strings of flexible length that can be modified in terms of both length and content. • Available in java.lang package • Thread-safe Output 16 20 21 Reserves room for 16 characters without reallocation Sets initial contents of StringBuffer and allocates room for 16 characters Explicitly sets size of buffer
  • 47. String Concatenation test -String: 16ms Output
  • 48. String Concatenation test StringBuffer: 16ms Output
  • 49. StringBuffer Methods • length() and capacity() • ensureCapacity() • charAt() & setCharAt() • getChars() • Insert() & reverse() • delete() & deleteAll() • replace() • substring() • append() • indexOf() • lastIndexOf() • trimToSize() • subsequence()
  • 50. The StringBuilder class • StringBuilder is a relatively recent addition to Java’s string handling capabilities. • StringBuilder is similar to StringBuffer except for one important difference: it is not synchronized, which means that it is not thread- safe. • The advantage of StringBuilder is faster performance. • However, in cases in which a mutable string will be accessed by multiple threads, and no external synchronization is employed, you must use StringBuffer rather than StringBuilder.
  • 51. StringTokenizer class • The processing of text often consists of parsing a formatted input string. • Parsing is the division of text into a set of discrete parts, or tokens, which in a certain sequence can convey a semantic meaning. • The StringTokenizer class provides the first step in this parsing process, often called the lexer (lexical analyzer) or scanner. • StringTokenizer implements the Enumeration interface. Therefore, given an input string, you can enumerate the individual tokens contained in it using StringTokenizer. • To use StringTokenizer, you specify an input string and a string that contains delimiters. • Delimiters are characters that separate tokens. Delimiter: space (“ “)
  • 52. StringTokenizer Example Output Exercise : Count no of words and lines in given string.
  • 53. The Object Class • To use StringTokenizer, you specify an input string and a string that contains delimiters. • Delimiters are characters that separate tokens.
  • 54. The Object Class • There is one special class, Object, defined by Java. All other classes are subclasses of Object. • That is, Object is a superclass of all other classes. This means that a reference variable of type Object can refer to an object of any other class. Also, since arrays are implemented as classes, a variable of type Object can also refer to any array. • Object defines the following methods, which means that they are available in every object.
  • 56. References • http://www.geeksforgeeks.org • http://beginnersbook.com • Introduction to Java Programming, Comprehensive Version (10th Edition), Y. Daniel Liang • https://www.Lynda.com • http://www.javatpoint.com