Android Application Development Tutorial for Beginners – #10 | 2017 | Java Basic Structure & Methods [w/ subs]

00:00:10 – Hey what's going on guys? welcome back to another brand new Android studio
00:00:13 – tutorial and today I will show you how to create a new method in Android studio
00:00:18 – inside the java that is main activity so let's go to the Android studio and we
00:00:23 – have nothing to do with the activity underscore main door XML so let's move
00:00:27 – on to the main activity towards Ella and we already have discussed about the
00:00:32 – basic structure of the main activity we have the package name import and the
00:00:38 – public class so today we are going to learn about how to create a new method
00:00:41 – inside the main activity public class so you can see before creating a method we
00:00:48 – have to learn about some some of the things that use it to create a new
00:00:52 – method so first of all a metal require access material so you can see here
00:00:57 – these public class main activity which is actually a kind of parent method so
00:01:02 – here you can see public then its class then main activity so the public is
00:01:09 – going to be the access specifier so there are three different kind of access
00:01:13 – specifiers in Java one is public the second one is private and the third one
00:01:17 – is protected so the public is going to be available for many other activities
00:01:22 – not only for the main activity anything that you have written inside the public
00:01:27 – is going to be available to all other activities and if you declare down
00:01:31 – access specifier as private and the method is only going to be available
00:01:37 – inside that inside that particular class and if you declare the access with fire
00:01:44 – as protected then that method will be going to available inside that class but
00:01:50 – it's not going to be available outside that class for now let's go and create a
00:01:54 – new method so here is another method created with the name one create now if
00:01:59 – you want to create a method how to declare it under the main activity which
00:02:04 – is going to be the parent class so we have to type the new method here so
00:02:09 – first you have to give the access to fire I'm going to give it as
00:02:13 – private and the second thing is going to be void it because it returned nothing
00:02:18 – so we have to use the void which actually means empty or no and after the
00:02:24 – void we have to declare the name for the material which is going to be same as we
00:02:29 – have done in case of the variable I just want to name the metal as my application
00:02:38 – okay you can give anything as you want it doesn't matter just like the variable
00:02:44 – or we can simply give it as get something okay so this is not going to
00:02:51 – be a keyword or something like that you can give it as any name and after that
00:02:56 – we have to open the bracket then we have to add the curly braces and inside that
00:03:03 – you can type anything and they call this special method from outside this method
00:03:08 – I just wanted for example I just want to show at all when the when this get
00:03:14 – something method is called so I'm typing a toast and we are going to type we have
00:03:21 – we are going to show my set that is okay so here you can see I have created a
00:03:26 – method that is get something and when the user call this method get something
00:03:32 – it will show a toast with this message so now we have the basic structure of
00:03:37 – creating a method now let's go and call this from somewhere else so I'm going to
00:03:42 – main activity and the in order to call this method we need something else or we
00:03:48 – can't actually call the matter when the application is just opened so if you
00:03:53 – want the code if you want to call this method when the application is just open
00:03:56 – then you can add something under the setcontentview so the one credit is
00:04:01 – going to be called when the app is chartered so I just want to call that
00:04:05 – get something over here so just type get something okay now you can see how call
00:04:14 – this thread from the one create method so what happen when we are running this
00:04:20 – on a live device is that there will be a toss with the same message
00:04:23 – as we have type it over here oh so if you want you can also give it from the
00:04:29 – button and then inside that one click listener you can give that get something
00:04:35 – like that you can create as many as much as you want so the reason why we are
00:04:40 – creating a method is just to decrease the complication inside the programming
00:04:46 – so you can probably just call it each items as many as times you want without
00:04:52 – without creating the toast again and again and again you can simply call this
00:04:56 – method and then make the things work you can also reduce the number of lines
00:05:01 – you're writing in programming to creating a specific method for that so I
00:05:07 – hope you guys enjoyed watching this tutorial and if you like this video
00:05:10 – definitely give it a big thumbs up and if you haven't subscribed to my channel
00:05:14 – then do it now,
00:05:15 – Thanks for watching,
00:05:16 – I Hope To See You in My Next Video 🙂
00:05:18 – //Peace Out\

Video Url: