INPUT-OUTPUT FUNCTIONS(SCANNER CLASS) - JAVA PROGRAMMING

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello friends welcome back to our channel into decision let's have a look on the input and output statements in java programming so as we know that input statement is used to read the input from the keyboard at the runtime and output statement is used to print the output on the display screen so in C language we use the input function as a scanf and the output function is primitive right so here in java we have to use a few methods in order to read the input from this keyboard and write the output on the display screen we have to call some methods so in Java everything will be written in class so everything will be treated as a class and objects so here what is it class a class is a template or a blueprint which the object will follows so every class consists of the properties as well as actions the properties and actions so these properties we call them as variables and these actions we call them as methods so each and every class consists of the variables as well as methods so in order to access these variables or methods this caste cannot access directly these variables and methods so in order to access these variables and methods which are written in cash compulsory we have to create an instance for this class and instance for this class that we call as object so an object must be created so our objectives and instance it's a reference to the particular class and through this object we have to access these variables and methods so just like our structure members the structure and members so we know that the structure consists of a template so let it be a struct student right so here is the tag name struct student consists of some name character some name of 20 and int age close so this is the structure and in order to access these variables we have to use the structure variable and through the structure variable only these numbers will be exist let it be if you declare some s1 as a structure variable so this structure variable consists of both the members and if you want to access these members this must be done only by means of the structure variable so we have the exercise s1 turning and yes or not each all right this is a possible and if you want trying to print directly the name and age this is not possible because these are the members of the structure and this can be accessed only by means of stretch available but using this dot operator the same thing is repeated in Java programming so class consists of variables and methods so here we are using only variables but here in additional we're having methods also in order to access these methods also we have to create an object and through the object we have to access the variables and manners for example the same thing as student so here directly we can have a string datatype so string name right and let it be display some display method is there so if you want to access this thing we have to create an object for the student and through the student let it be object is created with the s1 is an object so s1 dot name will print the name and s1 dot display will call the display method so a means of object only we have to call this variables or methods similarly here also the input and output functions the input and output functions also called with the class name see here the iostream there are three main I was strange first wise system dot in so remember here yes is a capital S is a capital system dot out system dot yellow there are three I was chains so stream is nothing but a bytes of data so system not in system not in is used to read the data from keyboard read the data from keyboard system not out like system not out so system dot out is used to display the data on screen system dot grr that means it displays the error messages display the error messages right so here this is in this class so system wrote in system wrote and system dot yeah so all these items are available in java dot land package gamma dot lang package so here in c programming we are including some header files before using the predefined functions right like printf and scanf these are the standard input and output functions so in order to implement this printf and scanf we have including the standard input/output dot h that was have a fun similarly here also every class will be available in the packages so we have to import those packages before using those gases in our program so here the standard input and output streams i will stretch all these i/o streams are available in land package lang package so how do we input there is a statement in both which is a keyword right we have seen this keyword input space i don't know me java dot dot star so if you mention here star that implies each and every class would use belongs to this land package will be exists or simply we can write the class name so that will in that particular class itself we have to use in the program if you through this star every class can be used in our program so by default java will import this java dot lambda star so explicitly we the user need not include this Java doc lang top star right now so remember this thing system protein system around and system not ever see coming to the output statement so first let us see the output statement so system dot out dot there are different functions available to display the output on the screen the first one is output dot feed so it doesn't have a newline character so everything will be printed in a single line in a single line for example if you write system dot out dot print welcome and immediately if you write system dot out dot print Java the output will be in a single line welcome and even though you are writing the next time it will print in a single line so this is the output for these two statements so it doesn't include the newline character so everything will be displayed on a single line so if you want to print in the next time we have to add yell el in the printer so system dot out dot print Ln println myths and line right so the output will be printed in multiple lights right multiple lines so if you include here el and drink L n so whenever you're ready Ln the text will be displayed on the next line so here will be printed and you print system dot out dot println then the text will be displayed on the next line so here you can find only print so a single text so that will be printed and next to text we are printing using println function so the data will be written the next line right so these two are the main things and there is one more thing that is print F system bar out dot print F so this is almost similar to the syntax which we are using in C language similar to C language so here we have to use a reference for a percentage D for individual percentage here for float percentage D in for double right so everything all these type specifies must be included if you use this system dot out dot println so these specials are not required if you use this system dot out dot print and system dot out dot print it so if you use these two functions this specific sort multiply if you use the system dot out dot print F this access specifiers should be included so hope you understand the output function so everything is same right so next let us see the input function input function so here input function input function means in order to read the output in order to read the data from the keyboard every one time itself okay so for this we will use scanner class or bufferedreader class so in the bufferedreader with the help of inputstreamreader and finally there so there are two methods to free the input at the one time so what is by using the scanner class and the one by using the bufferedreader class right so this can of gas is used to read the data from keyboard and by using this bufferedreader we can bring the input from the keyboard or from a file and it should be existing file so already some existing file right so files concept in our C language so we can read the data of some existing file or from the keyboard but here scanner class should be used to read the data from keyboard itself so this is available in util package this is available in I will package so in order to implement this scanner class this must be I mean the UDK package should be included import Java dot util dot scanner so as we have seen the link naming conventions in the previous session that we have to follow some particular rules so every class will be star we'll be starting with the capital letter so in this scanner and the bufferedreader all these are the classes so first letter of this verse will be captain so this should be remembered right so Java dot util dot scanner so by using this statement this camel cash has been imported to our program or simply without reading this camera you can write this time so whatever the Kansas available in this util package everything we can use in the program so anything you can write similarly if you use this bufferedreader so here so here freely first character of the word should be cattle Adan we have seen in the naming conventions right so for for readin be capital in our capital so if you want to implement this buffer reader we have to import this eyeball package so for that input Java dot IO dot stuck right on simply we can write I would not preferred winter so first in this session let us see this scan of camps in the next session we will see this buffer data right now coming to the scanner class scanner gasp so as I have said just now so a cast consists of variables and methods in order to implement that variables or methods in more and more in case of accessing those methods of the particular class that can be done only by means of an object created for the particular class so that means if you want to access some methods in from of the scanner class we have to create an object and from that object to that object itself we have to access the methods so what are the methods available in scanner dress so next next method is used to read string read string next it is used to read integer similarly next float read float value next W is used to read a double value right so these are the few methods available in scanner class so in order to access these methods first one object should be created for the scanner class and too much object by using the dot operator we have to use these methods let it be yes see is the object created for the scanner yes see so I will tell you how to create an object for a class so what is the syntax to create an object for a class so let me be first SC is an object created from the scanner glass yes see so in order to access these methods one of the state with the object dot the method yes seedot next we'll redo this thing when here yes seedot next similarly y SC not next IND yes seedot next fruit yes seedot next double right so here what is the SC it is an instance of scanner pairs instance of a scanner class that means we can simply say object object for scanner class so before accessing these methods we have to create an object and through the object we have to access the methods now how to create an object creation of an object for a class so for this class name followed by object name is equal to new keyword for or by constructed constructor so this is the syntax to create an object so a constructor is just like a method which is having the name equal to our class name so just I am day telling the definition so in the next two sessions I will tell you the in depth about the constructors so what is a constructor and how many types of constructors are there so we will discuss in the next sessions right so now just note on the syntax the class name followed by object name and you and the constructor so what's the importance of constructor names here new is used to create an object and constructor is used to initialize the object so new keyword is used to create an object constructor is used to initialize the object so constructor will always have the name similar to the class name so whatever the classroom we are using the constructor will also have the same name so this we will create an object for this camera so follow this syntax class name that is scanner so we know that class I'm always conscious of a capital letters first letter there is a scanner yes captain object name so we have created SCA object so SC is equal to new and here the constructor constructor so as I said the constructor is to initialize the object and the name of a constructor must be equal to the class name you scan them right new scanner so this is the syntax to create an object for the class right now we're from where we have to read the input so the input should be read from keyboard so in order to read the input from the keyboard we have an i/o stream called system dot system not in is used to read the data from the keyboard so we have to pass this system not in I was team to the as a parameter for this constructor so scanner system dot e right system dot in so here the S is also a capital letter as s system is a class name so S is a capital letter right so this is the syntax to read an input from the keyboard so by using this SC object we have to access the next to reality three distinct nextint to hear the integer next front to read the float value next example to read the double value and so as we know that variables should be declared before their use it in the program okay now when I see the program simple from them and yes wind up today and next session I will tell you the bufferedreader so let it be int J comma B how to read two integers or simply here we can use some string name in a fruit b CC so in order to read these one read the input from the keyboard we have to use the scanner class so first to create an object scanner object there can be anything I have given some SC as the scanner object so you can write any object name so let it be I hope I will as a object is equal to new some object it can be anything object name this is an object name new constructor so the name must be equal to the scanner and we have to read the input from the keyboard we have to use system dot in I was string as a parameter to the constructor now by using this I will have to read their values so name is equal to I go dot next so this is this is this will be the input next J is equal to I for dot next int b is equalto i forgot next float i go dot next so in many conventions we all see the rules to be followed for the method so if it is a method the first character of the first word should be smaller and every first character from the next words it should be a capital letter so that's why next int is a method the N is a small order and I use a capital letter similarly n is a small and F is a capital letter n is a smaller and is it capital inter right so here this is the simple statement to read the data from the keyboard so here we need not declare the variables one at one place and we can be I mean in in our C program for how to disable available then only we care we have to use them variables in our program but here by using the program using the variables itself we can declare the variables directly we can remove this part and directly and the type of initialization here itself we can declare the variable string name is equal to eta is equal to float B is equal to CC is equal to so at the time of usage itself we can declare a variable that is one more thing available in our Java programming so hope you understood this input function scanner class by using the scanner class so in this session we have seen the i/o streams system dot in system product and system dot grr and the output function that is system dot out there are different methods print println pre-death and similarly the would function by using the scanner class and the bufferedreader class so in this session we have seen the scanner class so every class will be consist of variables and methods in order to access those variables and methods compulsory way how to create an object and through that object itself we have to read the I mean we have to access the variables or methods so in the scanner class we have seen the different methods in order to access those methods first we have to create an object for the scanner class and then through that object we have to access the methods so in order to read an integer in order to read a string in order to read a float in order to free the double so hope you understood this one this session right so let us stop here in the next session we will see the bufferedreader cash so how to read an input by using the bufferedreader class so that can be made by using that bufferedreader we can read the data from the keyboard or an existing file so we will see that both the cases reading the data from the keyboard and the d reading the data from the file existing file right so if you really understood my sessions like my sessions and if you are having any doubts feel free to post your norms in the comment section so that I will definitely try to clarify all your doubts and share my sessions with your friends and don't forget to subscribe to our channel thanks for watching thank you very much
Info
Channel: Sundeep Saradhi Kanthety
Views: 138,375
Rating: undefined out of 5
Keywords: sundeep, saradhi, kanthety, java programming, java basics, java fundamentals, beginners, programming fundamentals, java introduction, object oriented, oops, oop concepts, abstraction, inheritance, polymorphism, encapsulation, class, object, java compiler, program execution, platform independent, portable, method overriding, strong typed, javac, class file, scanner class, nextint, nextfloat, nextdouble, print, println, printf, system class, iostream, util, io package, inputstream, outputstream
Id: VAfJ1H8_k3M
Channel Id: undefined
Length: 29min 11sec (1751 seconds)
Published: Sat Dec 22 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.