SlideShare una empresa de Scribd logo
1 de 35
Descargar para leer sin conexión
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..!

Más contenido relacionado

La actualidad más candente

Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection frameworkankitgarg_er
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections frameworkRiccardo Cardin
 
Standard Template Library
Standard Template LibraryStandard Template Library
Standard Template LibraryGauravPatil318
 
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 SteroidsFranç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 JavaKhasim Cise
 
Java10 Collections and Information
Java10 Collections and InformationJava10 Collections and Information
Java10 Collections and InformationSoftNutx
 
Java Collections API
Java Collections APIJava Collections API
Java Collections APIAlex Miller
 
Collections Api - Java
Collections Api - JavaCollections Api - Java
Collections Api - JavaDrishti 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 structuresagorolabs
 
Stl (standard template library)
Stl (standard template library)Stl (standard template library)
Stl (standard template library)Hemant Jain
 
Lecture11 standard template-library
Lecture11 standard template-libraryLecture11 standard template-library
Lecture11 standard template-libraryHariz Mustafa
 
Stl Containers
Stl ContainersStl Containers
Stl Containersppd1961
 
Java collections
Java collectionsJava collections
Java collectionsAmar Kutwal
 

La actualidad más candente (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
 

Destacado

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 StructureFernando Gil
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to javaSteve 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 constructorsJan Niño Acierto
 
Core java concepts
Core java  conceptsCore java  concepts
Core java conceptsRam132
 
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!
 

Destacado (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 a Java class 5

Similar a 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
 

Más de 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 | EdurekaEdureka!
 
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 | EdurekaEdureka!
 
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 | EdurekaEdureka!
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaEdureka!
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaEdureka!
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaEdureka!
 
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 | EdurekaEdureka!
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaEdureka!
 
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| EdurekaEdureka!
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaEdureka!
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | EdurekaEdureka!
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEdureka!
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEdureka!
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaEdureka!
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaEdureka!
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaEdureka!
 
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 | EdurekaEdureka!
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaEdureka!
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | EdurekaEdureka!
 

Más de 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
 

Último

Vani Magazine - Quarterly Magazine of Seshadripuram Educational Trust
Vani Magazine - Quarterly Magazine of Seshadripuram Educational TrustVani Magazine - Quarterly Magazine of Seshadripuram Educational Trust
Vani Magazine - Quarterly Magazine of Seshadripuram Educational TrustSavipriya Raghavendra
 
Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.EnglishCEIPdeSigeiro
 
How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17Celine George
 
Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.raviapr7
 
Protein Structure - threading Protein modelling pptx
Protein Structure - threading Protein modelling pptxProtein Structure - threading Protein modelling pptx
Protein Structure - threading Protein modelling pptxvidhisharma994099
 
SOLIDE WASTE in Cameroon,,,,,,,,,,,,,,,,,,,,,,,,,,,.pptx
SOLIDE WASTE in Cameroon,,,,,,,,,,,,,,,,,,,,,,,,,,,.pptxSOLIDE WASTE in Cameroon,,,,,,,,,,,,,,,,,,,,,,,,,,,.pptx
SOLIDE WASTE in Cameroon,,,,,,,,,,,,,,,,,,,,,,,,,,,.pptxSyedNadeemGillANi
 
Prescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptxPrescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptxraviapr7
 
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptxSandy Millin
 
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptxClinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptxraviapr7
 
CapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptxCapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptxCapitolTechU
 
Riddhi Kevadiya. WILLIAM SHAKESPEARE....
Riddhi Kevadiya. WILLIAM SHAKESPEARE....Riddhi Kevadiya. WILLIAM SHAKESPEARE....
Riddhi Kevadiya. WILLIAM SHAKESPEARE....Riddhi Kevadiya
 
Education and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxEducation and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxraviapr7
 
Unveiling the Intricacies of Leishmania donovani: Structure, Life Cycle, Path...
Unveiling the Intricacies of Leishmania donovani: Structure, Life Cycle, Path...Unveiling the Intricacies of Leishmania donovani: Structure, Life Cycle, Path...
Unveiling the Intricacies of Leishmania donovani: Structure, Life Cycle, Path...Dr. Asif Anas
 
How to Create a Toggle Button in Odoo 17
How to Create a Toggle Button in Odoo 17How to Create a Toggle Button in Odoo 17
How to Create a Toggle Button in Odoo 17Celine George
 
KARNAADA.pptx made by - saransh dwivedi ( SD ) - SHALAKYA TANTRA - ENT - 4...
KARNAADA.pptx  made by -  saransh dwivedi ( SD ) -  SHALAKYA TANTRA - ENT - 4...KARNAADA.pptx  made by -  saransh dwivedi ( SD ) -  SHALAKYA TANTRA - ENT - 4...
KARNAADA.pptx made by - saransh dwivedi ( SD ) - SHALAKYA TANTRA - ENT - 4...M56BOOKSTORE PRODUCT/SERVICE
 
Diploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfDiploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfMohonDas
 
In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxAditiChauhan701637
 

Último (20)

Vani Magazine - Quarterly Magazine of Seshadripuram Educational Trust
Vani Magazine - Quarterly Magazine of Seshadripuram Educational TrustVani Magazine - Quarterly Magazine of Seshadripuram Educational Trust
Vani Magazine - Quarterly Magazine of Seshadripuram Educational Trust
 
Personal Resilience in Project Management 2 - TV Edit 1a.pdf
Personal Resilience in Project Management 2 - TV Edit 1a.pdfPersonal Resilience in Project Management 2 - TV Edit 1a.pdf
Personal Resilience in Project Management 2 - TV Edit 1a.pdf
 
Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.
 
How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17
 
Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.
 
Protein Structure - threading Protein modelling pptx
Protein Structure - threading Protein modelling pptxProtein Structure - threading Protein modelling pptx
Protein Structure - threading Protein modelling pptx
 
SOLIDE WASTE in Cameroon,,,,,,,,,,,,,,,,,,,,,,,,,,,.pptx
SOLIDE WASTE in Cameroon,,,,,,,,,,,,,,,,,,,,,,,,,,,.pptxSOLIDE WASTE in Cameroon,,,,,,,,,,,,,,,,,,,,,,,,,,,.pptx
SOLIDE WASTE in Cameroon,,,,,,,,,,,,,,,,,,,,,,,,,,,.pptx
 
Prescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptxPrescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptx
 
March 2024 Directors Meeting, Division of Student Affairs and Academic Support
March 2024 Directors Meeting, Division of Student Affairs and Academic SupportMarch 2024 Directors Meeting, Division of Student Affairs and Academic Support
March 2024 Directors Meeting, Division of Student Affairs and Academic Support
 
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
 
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptxClinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptx
 
CapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptxCapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptx
 
Riddhi Kevadiya. WILLIAM SHAKESPEARE....
Riddhi Kevadiya. WILLIAM SHAKESPEARE....Riddhi Kevadiya. WILLIAM SHAKESPEARE....
Riddhi Kevadiya. WILLIAM SHAKESPEARE....
 
Education and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxEducation and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptx
 
Unveiling the Intricacies of Leishmania donovani: Structure, Life Cycle, Path...
Unveiling the Intricacies of Leishmania donovani: Structure, Life Cycle, Path...Unveiling the Intricacies of Leishmania donovani: Structure, Life Cycle, Path...
Unveiling the Intricacies of Leishmania donovani: Structure, Life Cycle, Path...
 
How to Create a Toggle Button in Odoo 17
How to Create a Toggle Button in Odoo 17How to Create a Toggle Button in Odoo 17
How to Create a Toggle Button in Odoo 17
 
KARNAADA.pptx made by - saransh dwivedi ( SD ) - SHALAKYA TANTRA - ENT - 4...
KARNAADA.pptx  made by -  saransh dwivedi ( SD ) -  SHALAKYA TANTRA - ENT - 4...KARNAADA.pptx  made by -  saransh dwivedi ( SD ) -  SHALAKYA TANTRA - ENT - 4...
KARNAADA.pptx made by - saransh dwivedi ( SD ) - SHALAKYA TANTRA - ENT - 4...
 
Diploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfDiploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdf
 
Finals of Kant get Marx 2.0 : a general politics quiz
Finals of Kant get Marx 2.0 : a general politics quizFinals of Kant get Marx 2.0 : a general politics quiz
Finals of Kant get Marx 2.0 : a general politics quiz
 
In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.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); }

Notas del editor

  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.