SlideShare a Scribd company logo
Input And Output
Input and Output

• Input is the data what we give to the program.
• Output is the data what we receive from the
  program in the form of result.
• Stream represents flow of data i.e. sequence of
  data.
• To give input we use InputStream and to
  receive output we use OutputStream.
How input is read from Keyboard?


              connected to                  send data to
  System.in                  InputStream
                                                             BufferedReader
                                Reader




 It represents               It reads data from       It reads data from
 keyboard. To read           keyboard and             InputStreamReader and
 data from keyboard          send that data to        stores data in buffer. It has
 it should be                                         got methods so that data
 connected to                BufferedReader.          can be easily accessed.
 InputStreamReader
Reading Input from console

• Input can be given either from file or keyword.

• Input can be read from console in 3 ways.
      BufferedReader
      StringTokenizer
      Scanner
BufferedReader


BufferedReader bufferedreader = new
       BufferedReader(new InputStreamReader(System.in));

int age = bufferedreader.read();
                                                Methods
String name = bufferedreader.readLine();

                                               int read()
                                           String readLine()
StringTokenizer

•It can be used to accept multiple inputs from console in a single
line where as BufferedReader accepts only one input from a line.
•It uses delimiter(space, comma) to make the input into tokens.

BufferedReader bufferedreader = new BufferedReader(new
                              InputStreamReader(System.in));
       String input = bufferedreader.readLine();

StringTokenizer tokenizer = new StringTokenizer(input, ”,”);
       String name = tokenizer.nextToken();
                                                    delimiter
       int age=tokenizer.nextToken();
Scanner

• It accepts multiple inputs from file or keyboard and divides
  into tokens.
• It has methods to different types of input( int, float, string,
  long, double, byte) where tokenizer does not have.

  Scanner scanner = new Scanner(System.in);
      int rollno = scanner.nextInt();`
      String name = scanner.next();
Writing output to console

• The output can be written to console in 2 ways:
 print(String)-
      System.out.print(“hello”);
 write(int)-
     int input=‘i’;
     System.out.write(input);
     System.out.write(‘/n’);
I/O Streams
                                   I/O Streams

                                                 Unicode Character Oriented
         Byte Oriented Streams
                                                          Streams

 InputStream          OutputStream                Reader              Writer


                                                 InputStream       OutputStream
FileInputStream     FileOutputStream
                                                    Reader            Writer
DataInputStream     DataOutputStream



   May be buffered or unbuffered                  FileReader          FileWriter
Array List
ArrayList class

• The ArrayList class is a concrete implementation of
  the List interface.
• Allows duplicate elements.
• A list can grow or shrink dynamically
• On the other hand array is fixed once it is created.

   – If your application does not require insertion or deletion
     of elements, the most efficient data structure is the
     array
ArrayList class

                          Java.util.ArrayList       size: 5


                                             elementData


                      0      1     2     3      4     …       …




  Ravi        Rajiv              Megha              Sunny         Atif
Methods in ArrayList

• boolean add(Object e)                     • Iterator iterator()
• void add(int index, Object                • ListIterator listIterator()
  element)
• boolean addAll(Collection c)
                                            • int indexOf()
• Object get(int index)                     • int lastIndexOf()
• Object set(int index,Object
  element)                                  • int index(Object element)
                                            • int size()
• Object remove(int index)                  • void clear()

                             Java Programming: OOP                          13
ArrayList - Insertion
 // Create an arraylist
 ArrayList arraylist = new ArrayList();

 // Adding elements
 arraylist.add("Rose");
 arraylist.add("Lilly");
 arraylist.add("Jasmine");
 arraylist.add("Rose");

 //removes element at index 2
 arraylist.remove(2);
How to trace the elements of ArrayList?


   •   For-each loop
   •   Iterator
   •   ListIterator
   •   Enumeration




                       Java Programming: OOP   15
For-each loop


   • It’s action similar to for loop. It traces through all
     the elements of array or arraylist.
   • No need to mention size of Arraylist.
   •      for ( String s : arraylist_name)

   Keyword         type of data     name of arraylist
                stored in arraylist
                         Java Programming: OOP                16
Iterator

  • Iterator is an interface                   Iterator Methods
    that is used to traverse
    through the elements
    of collection.                             • boolean hasNext()
  • It traverses only in                       • element next()
    forward direction with                     • void remove ()
    the help of methods.

                       Java Programming: OOP                      17
Displaying Items using Iterator


 Iterator iterator = arraylist.iterator();

 while (iterator.hasNext()) {
    Object object = iterator.next();
    System.out.print(object + " ");
 }


                        Java Programming: OOP
ListIterator

  • ListIterator is an                    ListIterator Methods
    interface that traverses                   • boolean hasNext()
    through the elements
                                               • element next()
    of the collection.
                                               • void remove ()
  • It traverses in both
    forward and reverse                        • boolean
    direction.                                   hasPrevious()
                                               • element previous()
                       Java Programming: OOP                      19
Displaying Items using ListIterator


// To modify objects we use ListIterator
ListIterator listiterator =
arraylist.listIterator();

  while (listiterator.hasNext()) {
     Object object = listiterator.next();
     listiterator.set("(" + object + ")");
  }
                        Java Programming: OOP
Enumeration

  • Enumeration is an
    interface whose action                   Enumeration Methods
    is similar to iterator.                   • boolean
  • But the difference is                       hasMoreElement()
    that it have no method                    • element
    for deleting an element                     nextElement()
    of arraylist.

                     Java Programming: OOP                    21
Displaying Items using Enumeration


 Enumeration enumeration =
 Collections.enumeration(arraylist);

 while (enumeration.hasMoreElements()) {
    Object object = enumeration.nextElement();
    System.out.print(object + " ");
 }

                      Java Programming: OOP
HashMaps
HashMap Class
• The HashMap is a class which is used to perform operations such as
  inserting, deleting, and locating elements in a Map .
• The Map is an interface maps keys to the elements.
• Maps are unsorted and unordered.
• Map allows one null key and multiple null values
•       HashMap < K, V >

                  key value associated with key
• key act as indexes and can be any objects.
Methods in HashMap
• Object put(Object key, Object value)

• Enumeration keys()
• Enumeration elements()
• Object get(Object keys)

• boolean containsKey(Object key)
• boolean containsValue(Object key)

• Object remove(Object key)
• int size()
• String toString()

                              Java Programming: OOP   25
HashMap Class
                Key    Value


                 0     Ravi

                 1     Rajiv
                 2    Megha
                 3    Sunny
HashMap          4      …..
                  .    ………..
                 ..
                      ……….…….
                 …
                100     Atif
HashMap - Insertion

// Create a hash map
HashMap hashmap = new HashMap();

// Putting elements
hashmap.put("Ankita", 9634.58);
hashmap.put("Vishal", 1283.48);
hashmap.put("Gurinder", 1478.10);
hashmap.put("Krishna", 199.11);
HashMap - Display
// Get an iterator
Iterator iterator = hashmap.entrySet().iterator();

// Display elements
while (iterator.hasNext()) {
    Map.Entry entry = (Map.Entry) iterator.next();
    System.out.print(entry.getKey() + ": ");
    System.out.println(entry.getValue());
}
Hashtable
Hashtable Class

• Hashtable is a class which is used to perform operations such as
  inserting, deleting, and locating elements similar to HashMap .
• Similar to HashMap it also have key and value.
• It does not allow null keys and null values.
• The only difference between them is Hashtable
  is synchronized where as HashMap is not by default.
Methods in Hashtable
• Object put(Object key, Object value)

• Enumeration keys()
• Enumeration elements()
• Object get(Object keys)

• boolean containsKey(Object key)
• boolean containsValue(Object key)

• Object remove(Object key)
• int size()
• String toString()

                              Java Programming: OOP   31
Hashtable - Insertion

// Create a hash map
Hashtable hashtable = new Hashtable();

// Putting elements
hashtable.put("Ankita", 9634.58);
hashtable.put("Vishal", 1283.48);
hashtable.put("Gurinder", 1478.10);
hashtable.put("Krishna", 199.11);
Hashtable - Display
 // Using Enumeration
 Enumeration enumeration = hashtable.keys();

 // Display elements
 while (enumeration.hasMoreElements()) {
      String key = enumeration.nextElement().toString();

     String value = hashtable.get(key).toString();

     System.out.println(key + ":"+value);
 }
•Q& A..?
Thanks..!

More Related Content

What's hot

Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection framework
ankitgarg_er
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
Riccardo Cardin
 
Standard Template Library
Standard Template LibraryStandard Template Library
Standard Template Library
GauravPatil318
 
An Introduction to Part of C++ STL
An Introduction to Part of C++ STLAn Introduction to Part of C++ STL
An Introduction to Part of C++ STL
乐群 陈
 
Scala Collections : Java 8 on Steroids
Scala Collections : Java 8 on SteroidsScala Collections : Java 8 on Steroids
Scala Collections : Java 8 on Steroids
François Garillot
 
standard template library(STL) in C++
standard template library(STL) in C++standard template library(STL) in C++
standard template library(STL) in C++
•sreejith •sree
 
Collections in Java
Collections in JavaCollections in Java
Collections in Java
Khasim Cise
 
Java collection
Java collectionJava collection
Java collection
Arati Gadgil
 
Java10 Collections and Information
Java10 Collections and InformationJava10 Collections and Information
Java10 Collections and Information
SoftNutx
 
Java Collections API
Java Collections APIJava Collections API
Java Collections API
Alex Miller
 
Collections Api - Java
Collections Api - JavaCollections Api - Java
Collections Api - Java
Drishti Bhalla
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structures
agorolabs
 
Stl (standard template library)
Stl (standard template library)Stl (standard template library)
Stl (standard template library)Hemant Jain
 
07 java collection
07 java collection07 java collection
07 java collection
Abhishek Khune
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
Sony India Software Center
 
Lecture11 standard template-library
Lecture11 standard template-libraryLecture11 standard template-library
Lecture11 standard template-libraryHariz Mustafa
 
Stl Containers
Stl ContainersStl Containers
Stl Containers
ppd1961
 
Java collections
Java collectionsJava collections
Java collectionsAmar Kutwal
 

What's hot (20)

Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection framework
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
 
Standard Template Library
Standard Template LibraryStandard Template Library
Standard Template Library
 
An Introduction to Part of C++ STL
An Introduction to Part of C++ STLAn Introduction to Part of C++ STL
An Introduction to Part of C++ STL
 
Scala Collections : Java 8 on Steroids
Scala Collections : Java 8 on SteroidsScala Collections : Java 8 on Steroids
Scala Collections : Java 8 on Steroids
 
standard template library(STL) in C++
standard template library(STL) in C++standard template library(STL) in C++
standard template library(STL) in C++
 
Collections in Java
Collections in JavaCollections in Java
Collections in Java
 
Java collection
Java collectionJava collection
Java collection
 
Java10 Collections and Information
Java10 Collections and InformationJava10 Collections and Information
Java10 Collections and Information
 
Md08 collection api
Md08 collection apiMd08 collection api
Md08 collection api
 
Java Collections API
Java Collections APIJava Collections API
Java Collections API
 
Collections Api - Java
Collections Api - JavaCollections Api - Java
Collections Api - Java
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structures
 
Stl (standard template library)
Stl (standard template library)Stl (standard template library)
Stl (standard template library)
 
07 java collection
07 java collection07 java collection
07 java collection
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
 
Lecture11 standard template-library
Lecture11 standard template-libraryLecture11 standard template-library
Lecture11 standard template-library
 
Collections
CollectionsCollections
Collections
 
Stl Containers
Stl ContainersStl Containers
Stl Containers
 
Java collections
Java collectionsJava collections
Java collections
 

Viewers also liked

OCA JAVA - 1 Packages and Class Structure
 OCA JAVA - 1 Packages and Class Structure OCA JAVA - 1 Packages and Class Structure
OCA JAVA - 1 Packages and Class Structure
Fernando Gil
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
Steve Fort
 
Java class 8
Java class 8Java class 8
Java class 8Edureka!
 
Java class 1
Java class 1Java class 1
Java class 1Edureka!
 
Java class 7
Java class 7Java class 7
Java class 7Edureka!
 
Java class 4
Java class 4Java class 4
Java class 4Edureka!
 
Java class 6
Java class 6Java class 6
Java class 6Edureka!
 
Java class 3
Java class 3Java class 3
Java class 3Edureka!
 
Java lec class, objects and constructors
Java lec class, objects and constructorsJava lec class, objects and constructors
Java lec class, objects and constructors
Jan Niño Acierto
 
Java lec constructors
Java lec constructorsJava lec constructors
Java lec constructors
Jan Niño Acierto
 
Java constructors
Java constructorsJava constructors
Java constructors
QUONTRASOLUTIONS
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
Ram132
 
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
Edureka!
 

Viewers also liked (15)

OCA JAVA - 1 Packages and Class Structure
 OCA JAVA - 1 Packages and Class Structure OCA JAVA - 1 Packages and Class Structure
OCA JAVA - 1 Packages and Class Structure
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Java class 8
Java class 8Java class 8
Java class 8
 
Java class 1
Java class 1Java class 1
Java class 1
 
Java class 7
Java class 7Java class 7
Java class 7
 
Java class 4
Java class 4Java class 4
Java class 4
 
Java
Java Java
Java
 
Java class 6
Java class 6Java class 6
Java class 6
 
Java class 3
Java class 3Java class 3
Java class 3
 
Java lec class, objects and constructors
Java lec class, objects and constructorsJava lec class, objects and constructors
Java lec class, objects and constructors
 
Java lec constructors
Java lec constructorsJava lec constructors
Java lec constructors
 
Java constructors
Java constructorsJava constructors
Java constructors
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
 
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
 
Core java slides
Core java slidesCore java slides
Core java slides
 

Similar to Java class 5

STRINGS IN JAVA
STRINGS IN JAVASTRINGS IN JAVA
ACP-arrays.pptx
ACP-arrays.pptxACP-arrays.pptx
ACP-arrays.pptx
MuhammadSubtain9
 
Programming with Python - Week 3
Programming with Python - Week 3Programming with Python - Week 3
Programming with Python - Week 3
Ahmet Bulut
 
Collections and generics
Collections and genericsCollections and generics
Collections and generics
Muthukumaran Subramanian
 
Collections
CollectionsCollections
Collections
Manav Prasad
 
02basics
02basics02basics
02basics
Waheed Warraich
 
List and iterator
List and iteratorList and iterator
List and iterator
James Wong
 
List and iterator
List and iteratorList and iterator
List and iterator
Young Alista
 
List and iterator
List and iteratorList and iterator
List and iterator
Fraboni Ec
 
List and iterator
List and iteratorList and iterator
List and iterator
Tony Nguyen
 
List and iterator
List and iteratorList and iterator
List and iterator
Harry Potter
 
List and iterator
List and iteratorList and iterator
List and iterator
Luis Goldster
 
Collections
CollectionsCollections
Collections
Rajkattamuri
 
Collections Training
Collections TrainingCollections Training
Collections Training
Ramindu Deshapriya
 
Advanced c#
Advanced c#Advanced c#
Advanced c#
AkashThakrar
 
Collections - Lists & sets
Collections - Lists & setsCollections - Lists & sets
Collections - Lists & sets
RatnaJava
 
Arrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | EdurekaArrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | Edureka
Edureka!
 
Python programming
Python programmingPython programming
Python programming
sirikeshava
 
Collections
CollectionsCollections
Collections
bsurya1989
 
Collections in java
Collections in javaCollections in java
Collections in javakejpretkopet
 

Similar to Java class 5 (20)

STRINGS IN JAVA
STRINGS IN JAVASTRINGS IN JAVA
STRINGS IN JAVA
 
ACP-arrays.pptx
ACP-arrays.pptxACP-arrays.pptx
ACP-arrays.pptx
 
Programming with Python - Week 3
Programming with Python - Week 3Programming with Python - Week 3
Programming with Python - Week 3
 
Collections and generics
Collections and genericsCollections and generics
Collections and generics
 
Collections
CollectionsCollections
Collections
 
02basics
02basics02basics
02basics
 
List and iterator
List and iteratorList and iterator
List and iterator
 
List and iterator
List and iteratorList and iterator
List and iterator
 
List and iterator
List and iteratorList and iterator
List and iterator
 
List and iterator
List and iteratorList and iterator
List and iterator
 
List and iterator
List and iteratorList and iterator
List and iterator
 
List and iterator
List and iteratorList and iterator
List and iterator
 
Collections
CollectionsCollections
Collections
 
Collections Training
Collections TrainingCollections Training
Collections Training
 
Advanced c#
Advanced c#Advanced c#
Advanced c#
 
Collections - Lists & sets
Collections - Lists & setsCollections - Lists & sets
Collections - Lists & sets
 
Arrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | EdurekaArrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | Edureka
 
Python programming
Python programmingPython programming
Python programming
 
Collections
CollectionsCollections
Collections
 
Collections in java
Collections in javaCollections in java
Collections in java
 

More from Edureka!

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | Edureka
Edureka!
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
Edureka!
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
Edureka!
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | Edureka
Edureka!
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | Edureka
Edureka!
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | Edureka
Edureka!
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| Edureka
Edureka!
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
Edureka!
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
Edureka!
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
Edureka!
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
Edureka!
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
Edureka!
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | Edureka
Edureka!
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka
Edureka!
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
Edureka!
 

More from Edureka! (20)

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | Edureka
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | Edureka
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | Edureka
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | Edureka
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| Edureka
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | Edureka
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
 

Recently uploaded

Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 

Java class 5

  • 2. Input and Output • Input is the data what we give to the program. • Output is the data what we receive from the program in the form of result. • Stream represents flow of data i.e. sequence of data. • To give input we use InputStream and to receive output we use OutputStream.
  • 3. How input is read from Keyboard? connected to send data to System.in InputStream BufferedReader Reader It represents It reads data from It reads data from keyboard. To read keyboard and InputStreamReader and data from keyboard send that data to stores data in buffer. It has it should be got methods so that data connected to BufferedReader. can be easily accessed. InputStreamReader
  • 4. Reading Input from console • Input can be given either from file or keyword. • Input can be read from console in 3 ways. BufferedReader StringTokenizer Scanner
  • 5. BufferedReader BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in)); int age = bufferedreader.read(); Methods String name = bufferedreader.readLine(); int read() String readLine()
  • 6. StringTokenizer •It can be used to accept multiple inputs from console in a single line where as BufferedReader accepts only one input from a line. •It uses delimiter(space, comma) to make the input into tokens. BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in)); String input = bufferedreader.readLine(); StringTokenizer tokenizer = new StringTokenizer(input, ”,”); String name = tokenizer.nextToken(); delimiter int age=tokenizer.nextToken();
  • 7. Scanner • It accepts multiple inputs from file or keyboard and divides into tokens. • It has methods to different types of input( int, float, string, long, double, byte) where tokenizer does not have. Scanner scanner = new Scanner(System.in); int rollno = scanner.nextInt();` String name = scanner.next();
  • 8. Writing output to console • The output can be written to console in 2 ways:  print(String)- System.out.print(“hello”);  write(int)- int input=‘i’; System.out.write(input); System.out.write(‘/n’);
  • 9. I/O Streams I/O Streams Unicode Character Oriented Byte Oriented Streams Streams InputStream OutputStream Reader Writer InputStream OutputStream FileInputStream FileOutputStream Reader Writer DataInputStream DataOutputStream May be buffered or unbuffered FileReader FileWriter
  • 11. ArrayList class • The ArrayList class is a concrete implementation of the List interface. • Allows duplicate elements. • A list can grow or shrink dynamically • On the other hand array is fixed once it is created. – If your application does not require insertion or deletion of elements, the most efficient data structure is the array
  • 12. ArrayList class Java.util.ArrayList size: 5 elementData 0 1 2 3 4 … … Ravi Rajiv Megha Sunny Atif
  • 13. Methods in ArrayList • boolean add(Object e) • Iterator iterator() • void add(int index, Object • ListIterator listIterator() element) • boolean addAll(Collection c) • int indexOf() • Object get(int index) • int lastIndexOf() • Object set(int index,Object element) • int index(Object element) • int size() • Object remove(int index) • void clear() Java Programming: OOP 13
  • 14. ArrayList - Insertion // Create an arraylist ArrayList arraylist = new ArrayList(); // Adding elements arraylist.add("Rose"); arraylist.add("Lilly"); arraylist.add("Jasmine"); arraylist.add("Rose"); //removes element at index 2 arraylist.remove(2);
  • 15. How to trace the elements of ArrayList? • For-each loop • Iterator • ListIterator • Enumeration Java Programming: OOP 15
  • 16. For-each loop • It’s action similar to for loop. It traces through all the elements of array or arraylist. • No need to mention size of Arraylist. • for ( String s : arraylist_name) Keyword type of data name of arraylist stored in arraylist Java Programming: OOP 16
  • 17. Iterator • Iterator is an interface Iterator Methods that is used to traverse through the elements of collection. • boolean hasNext() • It traverses only in • element next() forward direction with • void remove () the help of methods. Java Programming: OOP 17
  • 18. Displaying Items using Iterator Iterator iterator = arraylist.iterator(); while (iterator.hasNext()) { Object object = iterator.next(); System.out.print(object + " "); } Java Programming: OOP
  • 19. ListIterator • ListIterator is an ListIterator Methods interface that traverses • boolean hasNext() through the elements • element next() of the collection. • void remove () • It traverses in both forward and reverse • boolean direction. hasPrevious() • element previous() Java Programming: OOP 19
  • 20. Displaying Items using ListIterator // To modify objects we use ListIterator ListIterator listiterator = arraylist.listIterator(); while (listiterator.hasNext()) { Object object = listiterator.next(); listiterator.set("(" + object + ")"); } Java Programming: OOP
  • 21. Enumeration • Enumeration is an interface whose action Enumeration Methods is similar to iterator. • boolean • But the difference is hasMoreElement() that it have no method • element for deleting an element nextElement() of arraylist. Java Programming: OOP 21
  • 22. Displaying Items using Enumeration Enumeration enumeration = Collections.enumeration(arraylist); while (enumeration.hasMoreElements()) { Object object = enumeration.nextElement(); System.out.print(object + " "); } Java Programming: OOP
  • 24. HashMap Class • The HashMap is a class which is used to perform operations such as inserting, deleting, and locating elements in a Map . • The Map is an interface maps keys to the elements. • Maps are unsorted and unordered. • Map allows one null key and multiple null values • HashMap < K, V > key value associated with key • key act as indexes and can be any objects.
  • 25. Methods in HashMap • Object put(Object key, Object value) • Enumeration keys() • Enumeration elements() • Object get(Object keys) • boolean containsKey(Object key) • boolean containsValue(Object key) • Object remove(Object key) • int size() • String toString() Java Programming: OOP 25
  • 26. HashMap Class Key Value 0 Ravi 1 Rajiv 2 Megha 3 Sunny HashMap 4 ….. . ……….. .. ……….……. … 100 Atif
  • 27. HashMap - Insertion // Create a hash map HashMap hashmap = new HashMap(); // Putting elements hashmap.put("Ankita", 9634.58); hashmap.put("Vishal", 1283.48); hashmap.put("Gurinder", 1478.10); hashmap.put("Krishna", 199.11);
  • 28. HashMap - Display // Get an iterator Iterator iterator = hashmap.entrySet().iterator(); // Display elements while (iterator.hasNext()) { Map.Entry entry = (Map.Entry) iterator.next(); System.out.print(entry.getKey() + ": "); System.out.println(entry.getValue()); }
  • 30. Hashtable Class • Hashtable is a class which is used to perform operations such as inserting, deleting, and locating elements similar to HashMap . • Similar to HashMap it also have key and value. • It does not allow null keys and null values. • The only difference between them is Hashtable is synchronized where as HashMap is not by default.
  • 31. Methods in Hashtable • Object put(Object key, Object value) • Enumeration keys() • Enumeration elements() • Object get(Object keys) • boolean containsKey(Object key) • boolean containsValue(Object key) • Object remove(Object key) • int size() • String toString() Java Programming: OOP 31
  • 32. Hashtable - Insertion // Create a hash map Hashtable hashtable = new Hashtable(); // Putting elements hashtable.put("Ankita", 9634.58); hashtable.put("Vishal", 1283.48); hashtable.put("Gurinder", 1478.10); hashtable.put("Krishna", 199.11);
  • 33. Hashtable - Display // Using Enumeration Enumeration enumeration = hashtable.keys(); // Display elements while (enumeration.hasMoreElements()) { String key = enumeration.nextElement().toString(); String value = hashtable.get(key).toString(); System.out.println(key + ":"+value); }

Editor's Notes

  1. Demo
  2. Demo
  3. Demo
  4. Demo
  5. Demo
  6. Demo
  7. Demo
  8. Demo
  9. Demo
  10. Often, you will want to cycle through the elements in a collection. For example, you might want to display each element.The easiest way to do this is to employ an iterator, which is an object that implements either the Iterator or the ListIterator interface.Iterator enables you to cycle through a collection, obtaining or removing elements. ListIterator extends Iterator to allow bidirectional traversal of a list, and the modification of elements.
  11. Often, you will want to cycle through the elements in a collection. For example, you might want to display each element.The easiest way to do this is to employ an iterator, which is an object that implements either the Iterator or the ListIterator interface.Iterator enables you to cycle through a collection, obtaining or removing elements. ListIterator extends Iterator to allow bidirectional traversal of a list, and the modification of elements.
  12. Often, you will want to cycle through the elements in a collection. For example, you might want to display each element.The easiest way to do this is to employ an iterator, which is an object that implements either the Iterator or the ListIterator interface.Iterator enables you to cycle through a collection, obtaining or removing elements. ListIterator extends Iterator to allow bidirectional traversal of a list, and the modification of elements.