Transcripts
1. Introduction to class: Hi, I'm Maddie. I have been programming for
more than three years now. This course is designed for intermediate to
have knowledge of Java syntax and know how to
write basic Java programs. And who really want
to learn how to build Java projects to
improve their knowledge. In this course, I
am going to build Java projects from the
scratch on how to go from not knowing anything
about the basic concepts to building the projects forward
and few small concepts. Don't worry, I will be
revising in this course, I think now it is a great
time for you to learn Java because nowadays most companies are looking for candidates, have a good understanding
of Java and have basics and have built some Java projects during
their learning phase. Using the knowledge of Java, you can learn and build
even more good products which can be used by millions of people all around the world. Now, I think that's
pretty amazing. What will you learn
in this course? So this is a current
song course, which means you will
learn by doing it. First, I will show
you how to set up your development
machine on Windows PC. Then we will dive headfirst into Java fundamentals which are required for project per post. So you have a full
understanding of the Java programming language which we will be using
to build projects. We will create
several projects such as email administration
and many more. And I will make sure to update this course
with a new projects. One of the great things
about this course is that you don't need any
prior experience at all. Really, all you need is just
a computer and discourse. I believe that anyone can
learn how to build projects. My goal in this course is to teach you all the
skills that you need to become a good at
building basic Java projects. All right, So let's get started.
2. Introduction to Project and setup - Email Administration System: In this project, Java
inbuilt administration, we're going to learn very
Java project focused on object oriented design in
the real world application. So this is e-mail
Administration project where all the details
like creating mail, firstName and lastName, then giving the
company department, like pileated to that
company department than creating some system
generated password. As I link to that
particular e-mail, we are going to create your
email Administration project. In this project,
we're going to use some basic concepts of Java object code
into design on Java, then abstraction of Java. How we can secure
our password and everything like
abstract that password. Also, we're going
to learn how we can execute or create
some files in Java. It's like file handling in Java. So after creating
all the details like email, the
passwords, FirstName, LastName, we're going to store that particular data or
information in a text file. So let's see how we can
proceed with this project. So first we are
going to learn or we're going to see
our project aim. So consider, you are an IT support administrator
or something like that. Is your post or
warfare going to do is your task is creating e-mail occurs for the new
hires or the new employees. You need firstName and
lastName only from the user, or we can say for
the new employees. So using that, you are
going to be e-mail, new email with another details. So steps of our development for this project is first,
this project setup. Hope we're going to set up
all the things in this. Secondly, basic fundamental
concepts in Java. We're going to use
for Java basically here, I'm accessing data. Methods are all the abstractions
of classes in Java. Here we are going to see basic concepts like
building objects, classes and methods
for file handling. In Java. Basically, we are
going to create one text file, TXT file. And we're going to store
all the data in it, and we're going to retrieve
that information also briefly creating execution
file of jar, like while. In this project we are going to create multiple
classes, so Java files. But after that, we are compiling it into the single
execution jar file. So this is our basic project or steps of development
we're going to use here. So our application requirements, so we can see how we can
proceed with our requirements. First, we're going
to need one JDK. I'm going to explain what
is meant by JDK in Java. And second is Id. Id, basically integrated development
environment for Java. So there are multiple
IDs in this field. We're going to see how we can use that for
our application. First is our basic thing is generating an email
with a syntax like firstName, lastName,
department.company.com. So here, first name, last name and department
is given from the user. Let's say the department, I'm considering here, sales
development according here. If none is given from
the new employee than that blank will
be there in the email. Generate random strings
for the password. It's our third aim
of our application. Application should have
some certain methods to change the password, then set the mailbox capacity, basically the Min capacity and defined alternate
e-mail address. This is also going
from the user only, or we can say new hire only. It should have some GET
methods to display the name, email and the mailbox capacity when we are going to track
that email address also. And it should have some
by handling methods. Or we can say file
handling methods to store some data
in the TXT file. So it will store data
and retrieve data also. So this is our
application requirements. And here we will
require two tools, JDK, basically Java
Development Kit and IDE, Integrated
Development Environment. So first, we need to need an ID. There are few famous IDEs like Eclipse or IntelliJ, ID, etc. In this Java
development project, I'm going to use intelligent ID. So we are going to use integer id has already for
the Java development. So in this project, we're going to build our
whole project using this ID. For the JDK, we're
going to use Java SE, which lets you deploy and develop Java applications
on desktops and servers. When I was recording this video, the latest version is
it in generation JDK? When you are watching, there might be a higher version. Make sure you download the
latest stable version, which is available at the
time of watching this video. To download IntelliJ GID visit our official website and
go to the downloads page. There are two
versions of this id, ultimate and community version. If you have a student email ID, you could request for a community version which will be very helpful
in the future. If you don't have, then you can download ultimate version, which is free to download for everyone donor as per your operating systems
and install it. And for Java SE, you need to search for the JDK download on
your browser and open website and go to the download section based on your operating system
and install it. Once you have installed it, it's id will automatically
detect the part of the JDK. So these are about
all your tools required to build this project. So first, let's see what
is meant by JRE, JVM, JDK. So just we don't honor
the JDK, the Java. It is a C version, Standard Edition
version generation, which is basically the JDK, JDK contents Jerry and JVM. Jvm is a smallest
part of the JDK. Jvm is the Java Virtual Machine. As the name suggests, it does not physically exist. It's not physically
exist on system. It's virtual machine, but its maiden name is
for the main function is it promotes the
runtime environment in which Java byte
code executes. So what is meant by bytecode is basically
you are creating some Java syntax or it's higher-level language
you are writing. But machine knows the
lower level language, 1010, machine-level language. It basically converts
that bytecode and executed that bytecode. It also runs programs in other languages,
but compiling Java. So basically, if you created
some other languages, I mean by Kirklin or other
support by the JVM also. So what is the main
function of JVM? Easier to notice the core, it verifies the code, it executed the core and provides the runtime
environment. Second part is JRE Java
Runtime Environment. Jre download random
environment is a software package that
provides Java class libraries, java Virtual Machines, and
other components that are required to require to
run Java applications. Jre is a superset of JVM, as you can see in the diagram. So Java runtime environment, if you need to run
Java programs, but not deploy, but
not develop them. Jerry's, what do you need? You can download jeering from the Java Runtime Environment. Donald speech. It is a set of tools, libraries, and some JAR files,
Java archive files. It is used in Java
application programs that we're going to create. An introvert is
implementation of the JVM. It physically existing JDK as its runtime environment is just a set of programs
protocols in the JDK. It contains JRE,
JVM, Java compiler, Java questions
basically different versions or the related files and everything
you'd contents. Let see what is the
structure of that. Jdk is the superclass, or we can say all the union
classes of Jerry and JVM. Jvm is a smallest part, then Java and the time
environment contents, Some settler, some
set of libraries, Jarvis, some other files also. It contains, it contains
a JVM, as I said, this clear GRE and this is development tools
contains Java files, Java compiler files,
Java files and GRE, JVM, and all mixture is Jenny k. So just to be downloaded JDK, it contains a JVM
Jerry and everything, even execute our
Java file and it will do our desired output, what we're going
to proceed with. So this is the basic consists
of JIRA, JVM, and JDK. We will see how we can
set up our environment or our project for our application, even
administration application. Once you install our ID, ID, you can see this
welcome screen. Before that, I already
installed in my system. So before that you should set some configurations like
phone, text, everything. So once this is done, you can see the screen. So here I'm going to create a new project here, new project. It will take them some time
to create a new project. Once your project is cricket, I'm going to create here. Once the screen is loaded, you have to specify a JDK, or we can say it's decayed. So it will automatically
detect your SDKs. Here, I'm using I'm
using version of JDK. So I am choosing this. No need to install any additional libraries
like Groovy or Kirklin here. No need to specify some
user-defined libraries also, just click the Next. Don't check this. It will
create some default templates. We don't want to create some
default templates here. Great, Next, before that, do the project name,
the project location. Like I have given. For this, I'm going to specify the project name as
email application. You can specify your name, your own name,
also, project name. I'm going to specify
email application. Click the Finish button. It will take some time to
create indexing and everything. But once it is loaded, it will show the screen also wait for creating
a new project. It will take time. Wherefore it showing the
loading here you can see. So wait for that scanning
and indexing everything. It will automatically
create all the folders, let it to a project. So now we're done
with our setup. So we specify the JDK and then we created
our new project. Now, you can see this is a project email application and you can see all the
related files here. That is Door ID, that is then SRC. Src folder is the main folder we're going to create here
all the applications in this. Then this is the IML file and all the different
libraries and everything. So here, this is only Java
files we're going to use. So this is not at
all required to see. This is makefile
we're going to use. So we're done with our setup. Now, we will see how we can
proceed with the project. So what does this setup is done? And all the things are
index should I unloaded? Now, what you are
going to do is click this SLC, right-click here. It will take time to load. So just right-click here. It will give all the
options related to this. Click on New. You can
see every option, what we can make in this. So what we needed, we needed to create
some Java files. So we need to create Java class. But before that,
what I'm going to do is I'm creating
these Java classes. We are going to proceed
with some packages. What is a package in Java is I'm going to store that specific
classes in some files. So this is a very basic project. In further projects,
we are going to create some large
projects in that part. We need to create some
different packages, like in the industry also, once for the small, small requirements, we can
create small, small packages. So once package is
done, specify the name. You can see the package here. So I given the name as email
up here for that package, it will create some simple
folders for the classes. Now, Jews this email up,
right-click on that. And here I'm going
to create a class. For this, we need to
create two classes. So what is the requirement
of creating two classes? You will ask me, in one class, we're going to create
a main method, which is basically executing the methods in another
Java file or class. We are going to create all, we're going to specify
all of our methods. So first, let's see
that method part, or we can see what we're going
to specify in that part. Let's see that part. First, I'm going to create
a Java class and in this specified name for the specified name for
this Java class as e-mail. I'm going to do as email. Once it is done, it
will load the class. So you can see it will load this class for us with
some default structure. Let us see what is
this structure first, you can hide this
part also here. I'm going to leave
this and let's see what is this
vesicular structures. This is a package name, email app we created under this, and this is our class. So we're done with
the primary setup of this public class male. This is a class syntax for
that we will, in this folder, we're going to see how we can proceed with what
is meant by class, methods, everything, and how we can proceed
without project this. See you guys in the next video.
3. Creating classes and methods - Part 1: So we have seen this is
setup of our project. So we just created one
package known as email. And we created a class which is basically publicly
specified class. Now I will explain what is
a blueprint of a project. Then I will explain
some basics of class, methods and objects, etc. So let us see what is the
blueprint of a project. So project blueprint
is considered. This is the this is
a package, package, the medulla, this is email
class and method I created. So this is the
project blueprint. Back is email, our
email blast method, which I created before, an id which are short. So now this is done. These things are done
basically in future. What we're going to do
as we move in a project, we will create one main class. We will load all the
methods, this using objects. We will execute these methods
inside this main plus. This is our main
project blueprint. So let us see what is basically
Java classes methods. So Java class, Let's see, gosh thing about plants. Everything in Java is associated with
classes and objects, with our classes and not do it. You cannot create any poor or we can say any
method in Java. So it contains
attributes and methods. Attributes are basically
what we can see is pluses. Last attribute is grave some
environment for method. So for example, in
real life example, you can consider
God is an object. Car as attributes such as color. The color and methods are such like Dr. break and
something like that. So basically V, what we can, we can create car as a class. Digital attributes are red
color then model numbers, etc. And methods. Car can stop dry, you can break, etc. So glass is like an
object constructor. We can see it
creates the object, or we can construct the object, or it can be blueprint
for creating objects. Classes also hold some
user-defined attributes to pass values or
input from user. So we can view the user defined attributes
also inside the classes. Now, what is meant
by objects in Java? So objects are basically
associated with the classes. But what is the simplest form? We can say that to use a class
object is used basically. So if you define some class and you
want to use the class, you have to define
the objects as glass. Glass is already created. We have to only just create the object for
that particular class. We created already that object. We can easily create
their objects. But first-class than we
can create the object. So this is all about the class. Now, let us see what we're
going to do in a project. So before going any further, I will proceed with board
or a project. Let us see. So inside this, I
created this class. So I need to create
some methods, but before that we need
to invoke some libraries. So for the libraries, I'm going to put import
Java, util dot star. I will explain what
is this meaning. I'm going to use this, but I'm not currently
using this library. But ID is showing this. You are not using this
library currently. But what is
significance of this? This is very important library, java.util dot star,
meaning it is in a util. I'm using all the
things that we can say. It is very basic library inside Java and others
like same library. I'm going to use these
import java dot, dot star. It is basically input output library invoking
taking user inputs. It will be helpful library. So as this is done,
our first thing, I'm going to explain here how to take
user inputs in Java. You can do a scanner, which is the default method. We can say our default
matter for data inputs. I'm going to use this. I'm going to invoke
insert class only because I'm going to
specify it's public. So what I can do
is public scanner. Public is access
specifier, public scanner. As you invoke scanner, you can see now the java
dot util, it started. So the Scanner class is belongs to this
library, java.util. By default, I will say
equals new scanner. This is the syntax, basically syntax to invoke
scanner inside the brackets, you need to write system dot in, which is basically the method. So this is done for now. Now, I'm going to set
up some variables here. So for this, I will explain, I will have some comment
for explanation purposes. Now setting variables, I'm going to set
some variables here. But for the security
issue, we can say, I've weren't going to create
some abstract thing here. But I'm going to do is I'm
going to private here. This is a publicly given. I'm going to use your
private access modifier. So let us consider
this product string. I'm going to specify for the string fname,
basically firstName, severely private
access modifier, private string, last name. Similarly, like
this, I'm going to create some similar like
department then for email, then for the password. Now, consider this. I'm going to specify all these
things in a string method only light string
as a variable only. Now I'm going to specify
its Min capacity, which is integer capacities 500. I'm considering by default
founder NB than poverty. Private string. Again, I'll connect me basically
string underscore email. So we're done with this. We're done with, with this. Now remember, these are the
global, all we can say. These are strings can be accessible throughout
this class. So in the class, I can create as much as
I want four methods. So I can use this
trough, this class, as you can see,
this class Enter, I can use gourd this class. So we're done with
creating some variables. And I am setting this to the private to not to
do access directly. Basically, once it is done, no one can access it as it is. Provide this as if it's
orchestrated whereas probate. So we'll let us see with some constructor method what is meant by methods in general. Okay, So Java class,
we have seen. So as I told you, I will tell you some
more about glass. Glass is basically a
blueprint we have seen. So glass is something
like it stores the functions or methods
in one block of code. Basically, consider an
example, sketch of a house. Is it less than it contains all the details about the
prototype of the house, house doors, windows, etc. Now, how's is an
object of that class? Sketch of hose. Basically, I created
this sketch off. Now, how's is an object? So what we want V I can
do is plus contains all the properties
of that object related syntax to declare it. And I told you last class
we created in there. I'm going to specify access
specifier before that. Consider that if you are not given if you're not given
any access specifier, that by default it will be
different access specifier, which is basically
public only in Java. But if you can specify public,
private and protected, protected means fully
protected line, you have to invoke if small, what we can say are two methods
for privacy and security. So as I told you object, we are going to create objects. I'm not created here any object, but we're going to create an object for that
part goes only. So it's basically user
to call glass or Mexico. That class object is also called as an instance of a class is we
thought our object, we cannot call class. Always. Remember that to call the class, we have to use the object. So for that example,
previous example, as I told you,
sketch of the house, glass sketch of a house. Doors and windows
has some methods, or we can say
functions inside this. So this is the main method. If you know that in the Java public
static void domain is a different method to
execute any program in Java. Without this, you cannot
start the program, or we, or you cannot
execute the program. For that sketch of the house. I created this object OBJ. You can see more videos like this and
execute that object. We are going to see in further details
about Java objects. So for now, Java methods, now why we need mentors. So I will show an ID. Basically, if I want
to print something in IT might default
method is System.out. You can see the edit here, basically, System.out and error. It is not invertible
inside any plus y. The thing is it's only
defined with that method. So first, create a method, create a class inside that. Create some methods that you can invoke it in art mentor
as simple as that. So methods are declared
within the classes. It contains whole core
of particular functions, methods, contents, return,
value, and access specifier. There are the object classes. They are the object classes. As object classes are created, we can easily access
methods using that object. Main method is default method, as I told you to learn
or build our project. Anything main method, always remember public
static, environment. And it's always
returns the strings. You cannot change to integers
or something like that. You can print integers, but you cannot return integers
in certain main methods. Packages or Java. As I told you, I'm
against telling you. I always do that. It's just for
creating a for-loop. I'm storing all the
classes inside it. Now there are two methods. User-defined methods are
shattered library methods. User-defined methods
are like I created. I'm going to create
some methods here. Similarly like that, you can also create some
user-defined methods. Basically, it shows that it's
usually defined methods. There are some standard
library method that I created, scan or system. All those types of standard
library methods that I mentioned built in
methods and Java. So if you want to check number, even, then you can create
some even our functions. There's user-defined, but I have specified some library
methods like random system. These are system
defined methods. So now let's move
on to our code. Now let's see how, how to, how we can proceed
with building or object. We created all the things here. Now I want to create
one constructed. Know what constructor will loop. It will print what
I want basically, first thing, second thing, it will give me the
output as well as creating itself is like a
privacy thing inside the Java. I'm going to invoke all. I'm going to run
only constructor. So it will not use this private string or
something like that. It will take value from that, but you cannot change its value. Or we can say third party
cannot change this value. Private access modifier value. Just I'm going to create it. So constructed, I'm going
to specify that here. First name, last
name, and everything. That's it. I'm going to tell like only for that only like first-time, last time, That's it. You can do it to some
other names also. But be careful about the name. Now, consider, I'm going to
create this as a public. Always remember class and
constructor has the same name. So I'm going to do the
constructor attributes, same names I'm giving you
were inside the constructor. You have to use the same name. After that, you need to
specify something like this. Like this F and this F name
are totally different.
4. Creating classes and methods - Part 2 : So in previous video or in
the previous project steps, what we did is we
created one class, E-mail Plus, we created one Scanner class which
is publicly available. Always remember this
scanner class is global. I will write here also global. Global. You can use
this scanner on, in this our project. Then these are, these strings are also
globally available. You can use this inside
this email class and we're going to use in
inside this class also. So all these are
about creating class. We created, we already
created this class. Now we're created
one constructor to receive the
firstName and lastName. Now, what is the significance
of constructor is, I'm putting here only
these parameters. I'm putting here. It's not like abstracted
or something. You are using that
class and you are not secure and anyone can
change that part, like your first name or your last name,
they can change it. So significance of this
is creating constructor, insular issue of firstName and lastName and protect
that from original one, which is private String, firstName and the last name. So let's move further. Now in this constructor, what I'm going to do, I'm going to assign
this F name, this F9. To do this, what
we're going to use, this keyword, this dot F
name is equal to fname. Similarly, for this also like
this lastname email name, basically this L name, basically this dot
l m is equal to Lm. So what happened is
you can see these are, these are all equal now. So it is not just
forwarding the value, it's copying that value
from here to here. When we're going to
run this program, I'm going to print
out system dot out, dot, print LN. Insert this. I'm going to bring like new
employee plus this dot name. Plus I'm going to
give some small gap here in between and
then this dot L name. So we are done with constructed. Now inside this, we're going to develop more in
this constructor. So I am leaving some space here. Now we're going to
create some methods. So from the PowerPoint template, we already know we
now want to create some email, generic
email password. For that, we need to
create some methods. So let's start with
creating some methods here. So let's begin with some department asking the
department and then password. Okay, let's start
with generating email, generate main method. Now, remember, this
should be private, so I'm creating private. It's not like you have to
always create it private. You can create it public also. But to achieve abstraction, I'm going to use private. It's going to return string. So string, generate email. This is the syntax of
creating the methods. Now what it will return, it will return email. This format is this dark F9. So if you are putting, if you are putting firstName and capital and email is
always in small letter. To convert these to all small
letters are lowercases. There is a system
default method, or we can say user library. To lowercase. You can see two lowercase. You can put two lowercase here. So what it will do if you
put all the capitals, even if you are putting
all the capitals, it will create a
small case letters. Similarly, we need
to put a dot here. Plus again this real
name dot, two lowercase. Now, we want to
pause here and add, add the symbol than
this door department, DPT dot to lowercase. This syntax, as I told you
about all these syntax here, plus.company.com, this
is simple remaining. So what it will do, it will take FirstName, LastName from the user. Even put with a department, it's just generating the mill. Now, we will move further. So what we need is we
created the first method. We're going to move in a second method,
asking for department. Asking for department. Again, private private
string department. Certainly. I'm putting in now I need to put some
user interaction with, I'm not going to
assign directly. For that administrator,
it will ask Which department
do you want to go? So I will put here first system, dot out dot print
LN department goals than what it would be print. It will print department
course basically. But likewise, this one
for sales, remember, slashing will be called in
the next line, next line, or the new line, or
for the new line, I am putting slashing
for development. Third department, I'm going to pull these for the
accounting department. And last time
putting 0 for none. Nothing I'm going to mention here anything I'm
putting here none. So now what I want
to create some loop, or what we can say, choosing part here, that 123. So you can go through
the two main guesses, light switch gaze or something. But I'm going to use,
Here's which case. You can use if-else also, but using switch gears
is more efficient here. So I will create one flag here. Let me tell you why
I'm going to use flag. Because I want to execute
it again and again. Like if I am not going to
execute it again and again, it will generate
only first time. All we can say if you're
entering first employ, it will ask, I will. I want to cook for
multiple employees. So I want to create some new. I'm going to use
your do-while loop. I'm going to use do-while
loop is very important here. I want to execute
at least one time, and the do-while loop will
execute at least one time. For other loops, like
for loop while loop, for-each loop or an
answer for loop in Java, there is no condition. There is not any condition. It can move for one. But do-while loop, we will
run at least one time. So I will do here first. If you know the syntax do, then I will put
here a system dot. I'm going to ask
like system dot out, dot, print LN and just
enter department code. So this is very simple
part department code. After that, I will create
one variable choice. Now I'm, what I'm
going to do is next. You will understand
what is this. Yes. Yes. Is the
standard bar scanner, public scanner part. So I'm going to use this
to take user input. Now switch, switch toys, I will put then guess one. You feel now case
one, redundancies. If it's putting the
ideal condition, you have to bake it, but there is not any
significance for this. You have to put a
break statement here. But I'm going to
just returning this. So it will return
only in one time. It will not again and again start looping inside
this, which case? Just returning. We don't
need any brake line here. Guess three written accounting. And if is 0 returns none, 0 returns none. That's it. We're done with this. But like we're
missing something. Like we did want to exit that loop and we want to
create some default condition. So we are done with our logic, but we're not done
with our perfect cool. Let me complete that one. But also before I
will print here, system dot out, dot print
LN, invalid choice. Please choose it again. Now, we're done with
this no switch case. Now, I will end do while loop. So this is a do part here. So I will put Wiley Here flag. So what we do as flag
is always false, not means always true. It will return none. That's it. So what it will do, it will execute at least
one time written none. So now we're done
with this part. As you can see, what we did here. Let me summarize this. So what we did is we
created one constructor, public image String, firstName, lastName, put some parameters. We invoke it with
this name. Fname. So what we are doing, we are going to
assign this fname, Buddhist name, this last
name, but his last name. And I'm going to
print this here. So now constructor
part is not done. We are going to create and invoke some other
methods also there. But it's initial condition
for the constructor. Now, I started with our method. I created first private
string generator main method. So what it will do, it will do generating the male
according towards syntax. So this written, this door, fname dot two
lowercase into dark. Like this, dark,
these are the lines. What is the significance? This dot F9 to this F name
here, dark to lowercase. It will convert all the
strings into the lowercase. So no need to worry about
the uppercase and lowercase. Then dot, then again, this for the last name, and this for department, this for the company.com. So it will generate that
mean according to that. After that, I want
to say department, but setting the department
is all about the process from user or we can
say administrator. So I will put here
1230 for the auctions. Since the allotment
accounting respectively. Then I will create one Boolean
flag to execute that loop. I'm going to use a do while loop because it will at
least be run one time. Again, the department
core four twice I'm giving I'm using the
switch case method here. Switch case conditions you can use if else conditions also, but it will be goo much time to execute that to reduce
the time complexity here, I use choice, guess one, return series for
the development and accordingly to that
default condition, exiting the do-while loop with the flag and retaining all. So I created two methods here, generating a male and
insert department. So now we're done with this. So I will explain what is the significance
of this part also. So this will assign. Now, you understood that part. So let's try with so let's
try it. What is this part? So let me show you what
is the significance. So this is the reference variable that returns
the current object. It gives text and
behavior of the object. Global variables and class
variables are all the same. You want to invoke it the
same, it will assign it, and we just do, the
global variable is different and
plasma is also same. For that purpose, we
just use this word. If this is not in here, it will return null value. If local variable and instance
variables are different, there is no need to use if
both difference are different. Like globalist, different
variables, different, but you want to assign it to, is equal to, equal to. You can do names
should be different. So awarding using
different names, I use this keyword and
this is very efficient. Also, this can be used to invoke current
class constructor. What I did in this part. We invoke the constructor. So we will move further with
another methods also here. So let us see what are the other methods
we're going to see. We will see in next video, guys, that's it for now.
5. Random password generation method: So in the previous part, what we learned
is about creating constructor, creating
two methods. We created already two methods, generating male and
said department. Now let us see what we
are going to do further. For this, I'm going to explain how we can create
random password here. So generate random passwords method. Then again, I'm considering
here string only. So pyruvate string, generate
underscore password. Now what I'm going to do, I'm going to put here some
parameters, integer length. Because I want to specify
the length of the password. Then I will create
one exerting method. Here. It is random. So if you know there
is one in java.util, there is a class called random, which I already removed it, but it will be very helpful to create some random
things inside Java. You can print any random
number using this, or you can generate any
random string here. So first, I'm going
to put here a string, capital characters, because we want to create some set of
capital characters here. Right? Alphabet from a
to Z in all uppercases, or in capital form. Like a, B, C, D, like that. So once you are done with this, so that's it, are done
with the capital letters. Now. Similarly, small
letters are lowercases. So I am placing here Control D, just Control D to put
copy that part and change the variable name
from capital letters. Capital characters,
whose moral character? I am going to type here, all small characters
from a to Z. So we are done with
writing small characters. Now, we need to also
include numbers, because there are numbers
also in the passwords. So create a string with a
variable limb as numbers. Type the numbers from 0 to nine. Once you are done with
this lesson within the double-quotes to
make it as a string. Now, some symbols. So what I'm going to do, I'm creating some set, as you can see, the strings, like these other strings only, but for the symbol is
capital characters, characters, small
character serves symbol. I'm considering all the symbols
like exclamation, mark, hashtag than dollar,
dollar symbol per symbol. Now, we will create a
string for symbols also. So what I'm going to do, what I'm doing, I'm
creating some search, as you can see, of the strings. Like these are the
strings only births per symbol is capital letters, characters, small
character sets. The symbols. I'm considering
all the symbols like exclamation mark or the hashtag
symbol, percent symbol. And again, question
mark, question mark. Then I create a string value. Value is basically just what is, what we can say is it's like we're going to mix all
the capital letters, small letters, numbers,
symbols together, and one strong
password, the user. What we'll be
considering here is all capital characters
plus small characters, last numbers plus symbols. So we are done with what
is the syntax like. It will include capitals, small characters,
numbers, symbols. These are the system
default passwords. This is for system
default passwords. Now let's move it further. How we can generate some random. So first, create a
string for password. Because first-time it is null. Then it will append
some password here, then use for loop integer
I is the instant variable. Again, to loop it. Next condition is I
less than the length I plus plus simple disease. The conditions for the
for loop now use this password variable we
just created a bot. Password is equal to,
equal to password. What it will do, it will put that value
characters at index. Then are. We have to remember what
is the R which we have initialized previously is
for that random method. Any random thing from
that, all the search, and we'll put inside
these random dot. Next thing. Next thing, because for this, I will choose next
thing than inside this next values dot length because it will stop
at the length part. Also. Simply write a
line to return password. So what it will do, the significance of this is this will take this from
this all serves. No password will be assigned
with password plus r at the values, character,
character, character. On random mixing. It will choose random from this also the random position of that password that it
will create the password. So now I'm not giving
the fixer land for this, but for that purpose, it will choose the
land automatically. Here, we will see how we can set the length of the
password in the next part. So this is for generating
random password method. Now, we will learn how to create the specific change
password method. For clean core purpose, I am writing comments as
change password method. So it will be very easy for anyone to understand
the coding part. Change password method. I want to set its access
modifier to public. Now, you may be thinking that
why it has to be public. We have previously
made other methods as pyruvate and why this
method has to be public. Why? Basically change password
method is for the user who wants to change the
password is not for the system. Users will change the
password whenever they want. So we need to create
it as a public, so any public user can
access it and change it. Again, I am going to
use some strings here, but it should be public
for the user significance. So let's try it public
access modifier and set the name of the method
as underscore password. Let void, return type. It means it does not
return anything. Just prayed. I want to
create some loop here. The thing is before like
set password, you know, do you want to choose change your password and
press Y or yen? Then similarly, like that, I want to create
here some condition for that Boolean fly
is equal to false. Similarly, we have created
for that department method. We are creating similarly
for this also do loop. Let's see, do-while loop. Then let's write the core
system dot out, dot, print, LN. Insert this method. Do you want to change
your password? Exclamation mark,
white slash yen. So you'd will be
displayed to the user. Wait for the user input. Either yes or no. Now, we need to store the user stories or
no in some character. So for that, what we can do
is initialize the character. Again, I'm creating
character here. Remember, like we already
created suitcase, those are for the State
Department method. So they both are
different because scope of it within the
department method. You should not be
confused at this part. Now, I'm creating
for the character. Character choice is equal to, yes, don't know what it will do. If you use is putting S
or something like that, then it will return some error. To avoid that error, what I can do, just choose
the first character. So what I can do is yes
dot next character at 0, index 0 to index, you know, all you know about that
array starts from zeros. Similarly, cat starts or
string starts from 0. Then let's use a for loop. If choice is equal
to, equal to y, I can say if choice is equal to, equal to small y, or condition, I just put our
condition here, small white. What it will do is
once flag is true, it will stop that part
also do while loop. So I'm going to just putting
flat is equal to two. Now, we will ask
the user to enter the current password using
system dot out dot print LN. So it will ask user for their current password
on a console. So this is one of
what we can say is the most biggest part of
our project. Set password. Then string, I'm going to create some temporary variable
to assign that entering that part and
putting Next for the user. Again, we will use if loops. If it's equal to that password, equals this dot password, what will it will be as good as it will ask
about new password, system dot out, dot print
LN, enter the password. Once this is, what it
can do is this password, it will just append
this dark dot. Next, we'll append to that part and it will tell the user
that password as tenured, successfully reaching
their password, successfully password changer. If password is wrong, if your password is, this else part is wrong. So what it will do, it should print on the console
as incorrect password. Write system dot out, dot print LN inside
the brackets, incorrect password within
the double-quotes. Now, if, what if I
choose is not this? For that purpose, I'm going
to create another thing else-if you know that
elseif is another Florida, even like that, I
will create here also. Wait for a minute. Choice. E is equal to, equal to
capital N is equal to, equal to small n.
Inside living right? Flag equals to true. It will on the console as a password change
your cancer option. You didn't system dot
out dot print LN. That's it. Now, I will
create some defaulting here, like system dot out, dot, print, LN, invalid choice or something. And after this, I will end up while loop with
similar condition, like not equal to flag. And that's it. Now we are done with our third
password method. This is the very biggest part. As you know, in this, what I did is I created here
password method, public, void, set, password, boolean
flag is equal to false. Do while loop. I first put that. Do you want to change
your password or no? Then I will enter from the user. I will ask for the
user to press Y or N. If user presses right, it will change the password. But before that, it will ask
for the current password. If that password, current
password does not fit, the current password matches
with the old password, like you haven't heard before. It will proceed with
the new password. If not, it will
print on the console as incurred as incorrect. And if you are
pressing bar or yen, then it will, that option
will be cancelled. Orders if you are putting
some different like why other than while
Arianne or something, it will ask for enter
a valid choice. And then I'm exerting that
Lou exiting the loop. Similarly for that,
I'm going to create some SEC mailbox
capacity than for alternate male that
display the information of the user than storing
the file and every method. So that suits me, see the other methods
in the next part.
6. Set methods of project: So all of you already know that we created three methods here. Change password
method, set Department method of generating
random password method. Now what I'm going to do is I'm just going to say
that male capacity. Now, remember in
this first also, I told you by default, which is 500 MB. But if the user wants to
extend that mailbox capacity, I am asking for the mailbox
capacity here method. So after this part, I will create some set
mailbox capacity method. So I am writing command as
mailbox capacity methods to understand for everyone to not to get confused
in the future. I recommend you to do the same. Then. Now we're making it
as public as I told you, why should it be public? Because user wants to access that path and return
type is void. Write it as meld score CAP as the method name. That since there is no need
to put any arguments here, because it's not right now needed if there is any
need in the future. So now let's write
system dot dog. Inside this, within the
double-quotes, right? Correct. Capacity. Even print
the current capacity. Easy, we're doing this dot mil capacity. I am considering this is the first in m b naught in D beats. So I know this is very less, but I want to clearly simplify
this in MBB only system, dot out, dot, print LN. There is no need to ask for what is your first
capacity or something. I just want to create
or assign that. So enter new capacity. New mailbox capacity, right? This within the
double-quotes and this male capacity
is equal to yes. Next, it is integer only. No need to put
anything here next. And it feels like
system dot out, dot, print LN within the
double-quotes, right? Mailbox capacity
successfully changed it. When you write this, it will
be displayed on the console. This is all about inserting
the mailbox availability. It is very easy printing
first current capacity than enter the new
mailbox capacity and from the user and
just assign it to the new mailbox capacity
is set by user. Asked her whether
you use it to set. Similarly for that,
we will create another method for
alternate male. We will make the access
specifier as public body. Let's eat return type void, which means it does
not return anything. Let's give a name for
this alternate email. Email method. I am writing commit as male method to understand for everyone not to get
confused in the future. I recommend you to do the same. After writing these
comments. Right? It along with me. System dot out, dot, print, LN within the double-quotes, alternate mail or email. Then in the next line
and write this dot. You know that we created
already, created that part. Now this dot is equal to S dot. Next, this is very
simple method here. You don't need to worry
about this next line. And right now we've user
on the console that alternate mail or e-mail is
said using system dot out, dot, print, LN at that. See, now, this is all about creating or
generating something. But I want to create another, another method to display something because we
are just generating. But there is nothing I'm
going to display here. How can I display the user
information or something that could display
user information? I will create another method. So I am writing
comment as display user information
methods to understand for everyone and to not to
get confused in the future. I recommend you to do the same. Now, we're making it as
public as I told you. Why should it be public? Because user wants to access that part and written type
of foods let it be wide. Write the method
name as Get info. It's very simple. Just needed to create
the info of the user. Nothing other than that. To print something
on the console. System dot print LN. We're just using printing
statements here. Only. Insert the brackets right
along with me as new. Within the double-quotes. This F name, you some space between two of them for that user empty quotes. Then write this
dark yellow limb. Similarly, in the next slide, write system dot out, dot print LN within the
double-quotes, right? Department next to that
plus symbol, right? This BPD, which
means department. Similarly in the next
line for the e-mail, we can write system dot
out, dot, print LN. We did this double cords, right? Email, symbol. Write this email,
which means e-mail. Basically displaying all
the user information. Then if you want
to put password, you can put the password. But here where the ideal
condition you should print any password here
or you should not display any password for
the security reasons. But for a significant
convenience of this project, I want to check it will
be running or not. So I'm going to put here only. So this is for the testing
purpose for our application. This is not password. Then again, write system
dot out, dot print, LN, mailbox capacity,
male capacity. Let's also write NB, also within the double-quotes, like I am already mentioned. I'm writing it in M B only. Then again, system dot out, dot print LN double codes, right, as ultimate email. After that, add a plus symbol, write this email, which
means Amun, and that's it. Now, we are done
with these matters. So let's cross check. But before that, remember, via remaining with some other
methods, also store files. This. But before that, I will explain the
constructor part here. We already created
what constructor here. And before that creating
construct the water, it is set mailbox capacity
and then set password method. I alternate e-mail
method or display user information
method. And that's it. We're done. Then we want to
call the methods. So calling that method is
very simple, I can say. So. Now I will go to this constructor part
here. As you can see. Now, I'm putting here
is the calling method. So now calling method
is very, very simple. This door department
to department, department is equal to
this dot set Department. I created the Department
for the random password. I will come back to here for the department that
pulls random password. This password equals password, which I created. What I require here is passing arguments as what I told you. I am not mentioning length
then because I want to put inside this
awarding their part. I just put land here only. Length will be always not very ideal condition
to put all this land. But for the simple
condition as the aid. Or you can choose as
much as you want, or you can do from six to 15, or something like that. Now, I want to
combine these like denigrating men. That method. This dot generate,
underscore image, I have commenting it out. This is for generation. We're done with this part. But this is just, there is no method. You cannot run this
like this only because you can see there is no main method
we created here. Vr meeting with a main method. So this is all about
the email part. In the next part, what
I'm going to show you, how we can create a main method. We're going to invoke it. That main method, including how we can
use these all part. I'm going to show
you how you can create and store
that specific file, dot dx d Phi. So see you guys in the videos.
7. Creating main method to Run program: In the previous part, what we did is we
created one class with some scanner method
Robert strings, firstName, lastName, department, e-mail or the e-mail
generation application, or if we can say email
administration application inside this Ve created one
constructor name as email. We created some methods or generic mail asking departments and then generate
random passwords as you are seeing on the screen. This is very important
matter like how we are using random plus
here, if you remember, I have already mentioned in a previous class videos that
in java dot util dot star, Java library random class
exists user-defined, but it's a system defined, or we can say Java defined. Then set password. Here. This is also very important. And I can say for this very lengthy part
of this, our project. So logic of the slides, how we wrote our logic
is from the user. So it will ask for the password. For the current password
actually, password matches. It will tell the user to change your old password to
the new password. But if your current password
does not match or is wrong, which is already
stored in the system. It will throw some
error saying that your current password
entered is wrong and you are not the authorized person to
change the password and you will be thrown out of the password change look
for security reasons. So let's see how we
can use this part, like how we can run this part. Before that, we're not
running this part, but if you want
to run this part, you need to create
a main method. If you don't know
what is main method is basically lied to
execute any core. First the control goes
over to the main method. The main method does not exist, then your code will not run. If you'd axes, then the core will start running
from the main method. In order to run the
code or any program, you need to include
a main method within the same package or within
the same Java class. So what is using object
oriented programming? You can see the
score is for email, I can just simply add main
method at the bottom here. And I can invoke this. But this is not a
very good practice as this code is already
really lengthy. As you can see, now, what I can do or what
you can think of, I can create another class
within the same package in that I can create one
object for this email, it will be very
helpful to execute, also aren't very
helpful to understand, including this, I can use
that methods again and again. So this is very
significant method in Java, but
object-oriented design. Now, how we can create
one another class is very simple as we created
that email class now. Similarly like that, just
go to this e-mail package, email app package,
right-click here. It will give the options. Wait for a minute,
Right-click here, this part, this should
give you all the options. It will take time
to load everything. Just right-click here, as
you can see, a new option. I want to create Java class. Yeah, Java class. I'm giving the
name as email app. As you can see, both are
under the same package and our app is created or
our class is created. This is the package email
app and our app is created. So before proceeding
with some code, I will import very important
method import Java util. As you can see, this is very important library we already done
with this library. Now in this, I am going
to create a main method, which is basically public
static, void main. Whenever I'm ready, whenever
IT sees the main method, it will run the program. Again, I am going to
create a standard ASC, or you can say as similar to that scanner in the email class, inside the brackets
we write System.in. Yeah. Then after this, what I will do, I will ask for the user
to enter their name. For that used system, dot out dot print LN. Within the double-quotes, write the string, enter first name. Then in the next line, write string name is
equal to S dot next. So you can use the
next line also here. Or you can use next year also. I am going to use next only nor the next
line or something. Then again, system
dot out dot print LN. And within the double-quotes,
write the string. Enter, last name, last name. In the next line right here. Is equal to S dot. Next. That's it. We're done with this. Now I want to create
some new employee. I want to generate
new employees. So we already created
this male, this e-mail. Now I want to invoke it in
this class that e-mailed us. How can I do this? I will first write command here for understanding
purpose only, like here, only user
info like this. Writing one more command here, double slash, creating
object for email class. Now use the Java
lastname, email, where we wrote the
code and the first now via writing as
user-defined functions. So write it as e-mail, that e-mail Part one. Or I can say object one. I am going to equate it to here, like the M1 is equal to email. That's it. But remember before that, what I'm putting here
is problem is this this constructor,
firstName and lastName. That's why I'm asking the user to put their
first name and last name. So I will pass two
arguments here. Underscore name. Yes, underscore name. Now, there is no
error in this part, so it will generate new
firstName and lastName. But before that,
if you remember, we created too many
methods for generating new password and then ordinate
male mailbox, the opacity. And we are going to
go further also to see how we can proceed with
this and the next line, what I will, I will
write it twice. I'm assigning it to minus one. Now, I want to invoke
it again and again. For this, I will use
a do-while loop. Similarly like that, we created
already system dot out, dot, print LN. Within the double-quotes. Write the string as slash
n means in the next line, and then write star, star, star or
something like this. End it with one more slash
n, like this, right? Enter you would choice. Now, we will display options for the user in point-wise
on a console. For that ended with a slash and we thought
the space right, one dot Show Info. It will be displayed as a first option on the
console of the user. And again, slash n, right, with our space light
to dark password. This will be displayed as the option to on the
console of the user. Similarly do this for
the third option, also write slash n without
the space three dots. Change. Mailbox, the opacity
for the fourth option, slashing for mel, I want to create one
exit method also. So let it be as a fifth
option, five for exit. Now, insert this do-while
loop in the next line, I am going to ask the user these five choices which
we just created above. So for that right choice
is equal to S dot next in. This is a integer
bar next door next. Now we will switch gears. So follow along with me
inside the bracket by twice, open the flower
brackets or an insert. These are all the
cases like this. Guess one, as we know, Case one is showing the info. So as you know, we created this variable. Now what I can do is
just EN1 dark objects. We know the hour, we have the getting for that, but we know we have one method called get info we
already created. So I am just using that method. After this, don't forget to
put the break statement. Otherwise it will
show the error. Then we will move
to the next case, that is case two. Case two is password for that EN1 dark set
password password method. And after this, don't forget
to put the break statement. The next case, that
is case three, gets three VM1 dot
mail capacity. And again, don't forget to
put the break statement. We'll move on to the next case. That is case four. Yes, four. What is this case for? Setting these guesses for
setting alginate mill? So what are alternate
male after this? Don't forget to put
the break statement. Lastly, this time it is nothing but just
what exiting bytes. So what I can do is guess
five is display a message on the console using
system dot out, dot. Ellen, inside the brackets, right is within
the double-quotes. Thank you for using
our application. And after this, I can
write a break statement. Should be a one default
condition here. Also, as you can see, it is a very good
practice to create a default condition
for that system. Dot out, dot, print LN inside
the brackets, the right, this within the double-quotes
as invalid choice, enter proper choice. Again. Before that, I will
put here slashing to this invalid twice
exclamation mark. So we are done with this. Now, I want to exit this
part for exiting right? While the condition as toys, not equal to five for exiting the right
while inside the brackets, pass the condition as
toys not equal to phi, phi enter five as my toys. For example, it will
exit that loop. So we're done with this part. So we can run this part. But thing is remaining without creating file
and storing into that pile and executing one executable file and
creating one executable file. So I'm going to show you
what I'm going to run this part in a simple
scenario running. You can go to this also, this all over the
run option which is at the top of the page. As you can see, simple way. That is, you can see here the green arrow to run the part. So it will ask me to
run the email app dot. It will run this email up. And as you can see, configuration, it will automatically detect
the configuration. It will set the configuration. Now in this part, you can see all the
billing processes here. This is the output
and everything. So it is, our
application is building. So it will take some
time to compile then configuration
than directories and checking all everything. So as you can see in this run configuration or app
is successfully deployed, or I can say running. So this is very simpler. You can enhance it. So as you can see, this is the Run Configuration. Our app is
successfully deployed, or I can say it running. So this is very simple. You can Anansi to more something like web app or
something like that. But this is just the
back-end of aura. I will enter my first name here, James and the last name as B. James to be only
new employees. James be no, What
is your department? I am setting it to
the sales department. So enter one as option. Now, I want to show is info. Enter one as the option. And as you can see, is info is James B dot company. As I told you, James, the name is James B. Password. Is this,
as you can see, some combination and you can see the size of
the mill capacities, 500 MB, the printing
and email here. So in a further part, I will show you how you
can modify this also. This is just, I'm sure about
how we can run our code. Just I will stop
this process here. So let us see how we
can move further. I just created one
simple scenario here. So I just created one
simple scenario here. Let us add some this also because there is some
mistakes here also. Then new employee also. Let us add some this also
because there is some mistakes. Year also e-mail sad,
then new employee. Also. There is one mistake that there is no gap between to this. So this will help. So now let's run
the method again. So as you can see, this is very back-end. This is very primary. But here what we
understood that, how we can create
object oriented design, how we can collect system
before methods using random. Now enter FirstName,
LastName as James B, or anything you want. Now, it's asking for
these four options. So now let's choose Accounting Department
here so that enter three. Now, for this
recording department, you can see all the
informations of James B person which is generated now we are
given via options. So let us see how we can
use and password here. So for that enter to as the
change password option, they are asking if we want
to change the password. So SV2, we do want to
change the password. So let's enter vibe. Now, it is checking if I'm authorized person to
change the password. For that, we need to enter the old password or
the current password. Now, the system is very smart. It hasn't been already stored
your current password, so it will check if your password matches
the current password. Currently, I'm copy-pasting
this part only because I want I don't want
to waste my time on that. So if the current password so if the current password or the old password is correct, then only it allows
you to change the password or
else it will throw you out of the loop now as we have entered the current
password correctly. So now it is allowing me
to change new password. That is telling me to
enter a new password. So I will enter 123 paths
as my new password. Once you have done
with this, it will, as you can see, this message says password as
senior successfully. Now, if you want to check if the new password has
been updated or not, Let's check by displaying the info for that enter
one as your option. You can see 123 paths
is my new password. And the password has been
updated in the system. Now, if you want to set an alternate male for
the Jim's be person, you can set alternate male
by entering option for. Now. As you can see, it's asking me to enter
new alternate Mill. Let's put alternate male
as be at gmail.com. If I'm putting that, you can see alternate
male is set. You can set everything. Let's change the
mill capacity also. I am, I am putting
here as thousand MB. Know the mill capacity is changer again from 502 thousand. You can see 1 thousand MB here. So we created this. So this is the back-end
part of a project. So in the next video, let us see the final
execution of our project.
8. Final execution of project: So in the previous video, we learned how we can create a main method and
how we can run. And further, I'm going
to explain how we can store this information
into one file. So let us see. First, I'm commenting it out for understanding
purpose only. So double slash storing file. I am going to hear specify
access modifier as public. And let's eat return type
BY and give the name of the method as store
file, store file method. This is just a method. Now I'm going to use
your file right here. For that I already used are imported this library, java.io. This is very important library
for FileWriter method. So before FileWriter method, you should draw the
user-defined exception. For that purpose, I'm going
to use your try-catch block. It's very simple, user-defined
exception matters, or we can say it is
not very user-defined. We can say it is one of the most user error
handling methods. To use try catch block. You need to follow the syntax. In the try block, you need to write
error lines of code. And in the catch block, you need to write what
exception you need to display on the console
to understand for the user. So in the catch block, right along with me within
the bracket, right, exception e, I open the flower brackets and write system dot
out, dot, print LN. E inside the brackets. Here is nothing but
error handling. So let us see inside this try block how we can
create FileWriter. So right along with me as file writer and name
a variable as in. In is equal to new file writer. Open and close the brackets. Here, you have to specify
basically location of the file. Or you can say that input. If you're not giving their part, you can just put Pi limb here. But it will create
in a system default. But in my case, I'm going to use here desktop location file, which I already created. So basically go to our desktop, create a new text file. Once you have created a new file, right-click on it. Go to the properties and floppy, the location of the file
as shown in the video. Basically in the ID. As I am bringing the
video at the end of it, make sure to give the file name, which you have specified. In my case, I have mentioned or name the file as for dot TXT. So I am writing it as
input.txt at the end. Always remember you should
give the full path of the input.txt while you are
giving the different bile, whether you are going
to use the same violin, same project, or you
are going to create, or you can just load
that file name. After that, I want to put that part introduced
in Dar, right? What I am going to write
here that is inside the brackets is firstName string within
the double-quotes, plus this dot F name, firstname. Similarly, I am putting your
FirstName here than in dog. I am not going to
write it again. I'm going to append it. So I am going to
append it here like this in dot append
inside the brackets, the right, the string as lastName within
the double-quotes. Okay, you can put your slashing now, right, plus this dot name, last name, again in Dart. Append. Similarly,
I am going to put everything here now
or email everything. So similarly like this, like that, you can
put everything right. E-mail within the double-quotes
plus this door e-mail, that is for email. Then in the next line, again, we will write
for the password. So write it as dark indoor append inside the brackets slash and password. Ideally, you should not
store any password, but I'm considering
this as our database. So next, right, plus
this dot password. Then in the next line, again, we will write for men capacity. So we write it as in dot append inside the brackets
slashing the opacity. So next, write as plus this
dark milk the opacity. Then in the next slide, again, we will write for
alternate male. Write it as in dot append inside the brackets slashing
alternate male. Next, write plus this dot underscore email. Now I'm going to close this. Always remember, this is the best practice to close
everything for that. Write it as in dog loose. I am just printing system
dot out, dot, print LN. Inside the brackets,
write it as datastore. This will be displayed
when the user enters five as the
option, and that's it. Now, this code we wrote just
now is for storing only. We need to create or
reading part also. So I am writing comments
like reading file method. Now I am making
access modifier as public and let the
return type be wide. Now, let the name of the method
be read underscore file. Similarly, you are going to use try-catch block here also
for exception handling. In gas law, pass
the arguments as exception e. Inside
the catch block. Write system dot out, dot, print LN inside
the brackets, pass ie. Now inside the try block, you are going to handle it by including airlines of the code. Here, I'm going to use
FileReader method, which is part of the
java dot IO library. You can use input
stream also here, these are very efficient thing
here, the output stream, input stream, this will
serialize it and de-serialize z. These are very
helpful burden due to time constraints and also there is no need to
put everything here. I'm just going to use this right along with me as FileReader. F1 is equal to new FileReader. So filename, as we
mentioned previously, I am going to copy this part and just paste it inside the brackets
as shown in the video. And then just, I am creating an integer because it will look through the
data center and diet. So it is very difficult
to understand, but it is very helpful
for small, small parts. In the next line,
right, while loop. Inside this, right, I
equal to your F1 dot read. There is some default
thing that what is their part not
equal to minus one, which is basically not
know what it will do. It will print system dot out, dot, print LN on the console. What it will print bird. Inside it. It will print the
character string because it will access that in what we can say in the integer part, but I want to print
it as a character. So it will ask for character. Once this is done, I'm going to close it by
writing F1 dot close here, connection is closed
and this part is done. And this part is done. If you want, you can put
here one system dot out, dot print LN just
to give the gap. Just to give the gap. Now, we're done with this, but we haven't created anything
in that e-mail main part. Okay. So as you know for this, I want, I will extend that part
so as 15 is exerted. But now I am changing that
fifth part to store data file, to store data in file. Now, the sixth option is for
displaying data from file. And lastly, not the
seventh part is for exit. Similarly, we are going to
change this in this part also. So for the fifth
part is as it is, but I'm going to change this statement toward
to store the data. For that, write as E
m1 dot store file. Our next line break statement is already present,
so I'm leaving it. So moving on to the next case, that is case six, ES6. Write it as E m1 dot underscore
file. The next line. Break statement again. And for the last case, that is case seven, it is for exit. So we have to display a
message on the console using system dot
out, dot print LN. Inside this, right, the
message as, the message as. Thank you for using
our application. Then again are the
break statement. Now we are going to
end this condition also in while loop
inside the brackets, change the condition from five to seven because
seven is the exit part. So now we're done with
our project part. Let us run this part and
I will explain you how to create some JAR file here
with a Java archive file. So let's run this part. Click on Run. So it will
ask for the FirstName. We will give us James and
enter the last name as the B. So as you can see, new employee name is James B. Now let us pass one, but the sales department
pass one and press Enter. Now, as you can see, each time this
password is different and it is not
taking numbers now. You can see it is just putting some random variables and
everything and one number. Now, as we are there to
more options recently, it's showing here also. Now, let us choose the option to store data into the file, that is option five. So we will pass five
and press Enter. As you can see, it is
stored into the file. Now, let's choose the option
to display data from file, that is options six. So we will pass six
and press Enter. You can see now this
is printing this data. Now you will
understand why this is printing like this
all in a new line. So this means we have made a small mistakes and we need
to change something here. We will understand what we read mistake here as this is done. But before that, in the
choice, wait a minute. In the store file, I am printing this
sprint challenge statement, which is empty. This is the reason
for such output. So you can remove this part and also just to
remove the slash n. Also like this because it will print
output on a new line. So it is very difficult
to understand. So always, never give the slash. And in this part now I
will run it again and I will show you this is all
about our application. So it will ask for
the FirstName and we will get dams and enter
the last name as B. So as you can see, the employee name is James B. Now, let's pass one for
the sales department. Now, as we added two
more options recently, it is showing here. Now, let's choose the option
to store data into the file, that is option five. So we will pass by
and press Enter. As you can see, it is
stored into the file. Now, let's choose the option to display data from the file, that is options six. So we will pass six
and press Enter. You can see our
data is displayed. Now let us see, wait a minute, again, we have made
one small mistake. So here, instead of print LN, just write it as print. And also use slash N
here to avoid that. To avoid that lashing, lashing, a slashing
and slashing. Now, we are done with this. Now. Let us run it again. Now we debug our problem. As you can see, it's
printing character by character because of
the print LN statement. Now I am going with
a print statement, so it will ask for
the FirstName. We will give it as James and
enter the last name as B. So as you can see, the employee name
is James V. Now, let us now let us pass one
for the sales department. Now, as we added two more options recently,
it's showing here. Now, let's choose the option
to store data into the file, that is option five. So we've been passed
five and press Enter. As you can see, it is
stored into the file. Now, let us choose the option to display data from the file, that is option six. So we will pass six
and press Enter. So as you can see, it is displaying
the data capacity and everything very properly. So now we're done
with our project, but let us see how we can create one single file or we can
say some single JAR file. For executing this part. We are already done
with our project. As I told you, we are
going to create one single executing file
with our projects. So for that purpose, Corporate this file
option at the top, click on the project structure. Click on the project structure. For this purpose, go to this
file option at the very top. As you can see, click on the project structure bar
as shown in the video, one new window opens, as you can see in the video. Now, by default, project
section will be selected. Now, we need to go to the
artifacts section here. So click on the artifacts. Once you have liquid artifact
or the top, as you can see, there is a plus
symbol, which means r, which means our click
on Add button here. Now you will be shown
few options to select. For this, we will select data, which is the first
option. Click on John. Again. It will show
you like this. Now, we want to create
with dependencies. For that, click on the
last option that is from modules with dependencies. Now, it will open a new
small window like this. As you can see on the screen. Name is email
application by default. You don't have to change it. Now. Below it, there is a main class. By default, it will be empty. So here we need to tell IDE that to select
the main class, which means where we have
written public static void. We have written it in the new Java class and we have given the name as email app. Now, email app
contains main method from which the code runs or
the cord starts turning. So we need to browse it and tell the id the location of it. For that, click on browse. What new window will
be opened like this? It will automatically detect the main method Java class file. Here, as you can see, detector here,
that is email app, but if it does not
detected automatically, you can click on Project here and click on
external symbol here. As you can see,
our project files, make sure to select the file where main
method is written. If you'll follow me, we have written main
method in email app file. We are going to select
it and click on, Okay. Once it is okay,
click again, okay. Now all these settings
are system default. Do not try to change
anything here. Then click Apply. And lastly, click on OK. So Now the artifact is loaded, but we want to build it. So go to the Build here and click on this Build
Artifacts option. It will give you options
here like Bill Ward, clean or eat something. So we need to build. It will take time to build. So click on the Build.
So it will take time. As you can see, the
dialog box here. Bottom, it is building
this and it is doing so. It will take some time to build. As per our project requirements. Our project requirements
are very less in this. So now you can see in
the out and artifacts, you can see this email
application dot jars. So if you want to run this part, you have to read
the configuration. So go to this tab here. I did configuration
part here at the top. You will see this dialog box. Click Add New button here. Then there is a
huge list for this. So go to there down
here, insert this. You can have to identify
this data application. Data application. Click on Enter. You can give the name and then the name as email
app local machine, you have to do the
jar path here. So in this jar path is
always in our artifacts and this you can see jar but
click Enter, click on Apply. Now, you can run
this email up pad. As you can see, this is
printing this everything. So our JAR file is
running properly. Now we know we're
running with a JAR file. Let us see how we can run
in command prompt itself. So I'm going to pause this part. I'll stop this part. And I will show you how we can do this in the
command prompt. Let's first open the
command prompt here, Java slash jar, and then
that name of your jar file. So you can see this is running. I'm again putting this James B. Then as development says, info, as you can see,
info is printing. Similarly like that. You can create one application. This is very basic application
we're going to use. But you can move
further that any part, like you can create
a Java effects or GUI for this hour at anything. So this was all about our
project java email application. I hope you have learned
many things from this.