Advanced Java Hands-On Training. New Format! | Oleg Kotov | Skillshare

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Advanced Java Hands-On Training. New Format!

teacher avatar Oleg Kotov

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

3 Lessons (39m)
    • 1. Why you should take this Traning

    • 2. Put Your Hands Into HOT Water

    • 3. Trying to solve BadBoy problem

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class

​​Hi my name is Oleg Kotov

Today you will learn Advanced Java topic.

You will learn how to write TCP/HTTP Servers on Java.

This Hands-On Training created specifically for Java Developers or people who already know Java and want to learn interesting advanced stuff.

We will do live coding here. You can open your IDE and do it with me or follow my code.

I'll give you this first part for free as a bribe.

If you're Java guy like me, you'll definitely like it and will buy the second part. More interesting and more advanced.

This Advanced Hands-On Java Training will save you weeks of learning hours it you will try to understand everything from documentation or books or whatever.

One last thing before we start...

I just want you to know that this is the test and it is limited.

Watch this as fast as you can. It is very compact, just about 80 minutes total Hands-On Training + Bonus.

Start now, as I said this is a test and you can just miss very good opportunity to learn something really interesting and advanced.

Meet Your Teacher

Teacher Profile Image

Oleg Kotov


Oleg Kotov - Professional Java Developer, Java Performance Consultant.

More than 10 of experience in Java development. Architecture, design, analysis, development, team management, teaching, interviewing and hiring.

Contacts: [email protected]

See full profile

Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. Why you should take this Traning: Hi. My name is Elliot. Got off. Today you will learn advanced Java topic. How to write disip e http Servers on Java. This cans on training created specifically for Java developers for people who already know Java and won't learn interest in advanced stuff. We will do live according here. No slides, nothing just caught. You can do it with me or follow my court. I'll give you this first part for free as a bribe. If your job a guy like me, you definitely like it and will, by the second part more interesting and more advanced. This advanced hands on Java training will save you weeks off learning hours If you will try to understand everything from dogs or books or wherever we will start quoting a second. I just want you to know that this is a test and it is limited. What is this? As fast as you can. It is very compact. Just about 18 minutes. Total hands on job training plus bonus Start. Now, as I said, this is a test and you can just miss very good opportunity to learn really, really interesting An advanced topic that every Java developer should understand. Okay, let's start 2. Put Your Hands Into HOT Water: Let's start with a simple settler. I just want to make sure you and me on the same place. And you understand all the court, every single line off that If you don't ever write any socket or server or something like this, I just want toe make sure you understand everything. What is going on? So we start with a simple server and then step by step, we created proper one Sarah Well, which works where a good handle. A lot of clients work with Java Nyo It called non blocking io and works very well for every situation. Almost every situation you have you can do it with me. Just open your I d and do the same thing. Um, you can put powers here or something to look at the cordon. Copy it. Um, in your computer, it works where? Well, as well. It's depends on what you like or you performed. Just look or toe work with me. Let's start, um, simple server. We will do everything in a single class. We will not follow any part Turns here or exceptions handling or anything like that would just focus on specific socket concurrency server job on Io buffer or anything like this. Is this why we do straws exception here, Just ignore everything. If we need to stop then Ah, soak it. Set of socket suck It called its server New server socket 80. This mince you. Ah, create the server. Ah, put it on 80 80 and just listening while you were listening. Eso get soak it server. Except, um this line I said let's create a socket new socket for specific connection and wait. Does this except method is blocking. We will stop here on line 40 and wait until someone connect to this toe. The server, it's blocking. Uh, sorry. Block out. Um, you never know. We'll have the client here. Uh, then would go handle and puts of it. Handle It will be. You meet it called it handle. And we'll do try. Try catch Any Iot exception would have we wrap it with you Unchecked Io exception on Chek Dalio exception It's reps Any Iot exception. It's from Java eight Maybe you don't know this but now you know you can You can use it if you want Just put anything on the run Time and EEO exception So pleasures do input stream. Stream him, Suck it. Get input stream output, stream out a circuit, get output then we do next. We already have the streams in out. Just read from in and right throughout. In data while data it kills in read. Read one bite. Ah, and don't. It goes to minus one minus one. Is this a flag? Universal flag for Java. I owe this means with stop years connection closed maybe. Or something Infuriate file. You have the end of file minus one. Just means that you don't have this stream anymore. It's closed door. Don't have any bites in eight or something. We just basically should close the stream here if we don't have minus one. So we're ready. We I should ride this bite, which is traded here in data. And then we will write this same date. Same data to output, but all right, se same bite, but I want to transform it. Theron's for it before we're right to make sure we have it. We We understand that we get this by translate it and send it back. It's very simple, but let's create this transform function here. It will be int. And here is a trick. Look, you like it That I think, uh, character is later weather data data said it too. Data, uh, let's start this and Ah, try to figure out what what happened right now before a state will start. I just want to put one more safe here. We have two sockets to input streams, output stream and input stream. And from Java seven, maybe. You know, maybe not weak and use. We can use this. Tribals, resources, syntax. Ah, Teoh automatically close the streams when we're done. Let's do like this would be a very good we opens this streams here and we don't care about call to closet or something. When we're done with done job will close it. Ah, automatically after us. Don't start to server. That start works. Fine. Let's let's create. Once the one was in here, I want to put s out to see if What if someone connected? If someone connected, we will see is a system out. Let's start open, Tell needs and, uh, they'll net local host Haiti 18 and let's see high. Hello. You get it? It works. Fine. Sit. It's just converts Upper upper case letters to lower case. If we bought something like this here, it will does the same thing. Ah, how we do it will put 32 here. We just shift this data to 32 said it too is a number off bought off charters in asking between upper letters and lower letter lower case letters. So we get one socket here it works. Several is good, But when we do next, that's create one more client here and connect we have like this. He is anybody Any bodies there? No. Uh, let's stop. Let's stop this one quit and then would have off ever sent here. That's now it works. See what doesn't mean that it is a simple, single threaded server, Just a single threat. And we can't process to clients the same time because we were busy here. His busy was there and handle just in this wild loop working. I'll try transform and isn't like this. If we don't have this, we just block until we're it. And then we continue. Continue. Continue just waiting. So let's fix it. Let's great! That's threaded server full. It's pulled to this handle in an new threat and try to fix this thing I copied. And best it, guys, I do it life like don't record it. Ever since I have a recording here and do it live, maybe we have ah, little bit off Miss Clicks or something like this. Just do it with Mitt will work very well. I try to do it with no errors. First time it will work. Let's start Simpson. Simple three that cerebral and fix it right. That's great. No, you Oh so you thread here, start and pull this handle. We also should toe around herbal, right? It will walk work like this if we create reasonable but here idea already asked us. Teoh, create The Lambda reported like this the place with Lambda and we have Islam. The expressions in job eight Let's use it What this means. This means you create ah, thread and Sam around this court Over here. That's it. We should put this Syntex Fine Fences, syntax lives is just run Handle in a new threat. So let's start. Should work should fix our several. Right? Let's see. Oh ah, we already have a server here. Let's stop a trivial swan and start when you sing a simple threaded server. We started, then connect. Ah, I bought first here, works, works. And second, Second Oh, also works fun. Yes. You see it. Now who? Look, who's that? Looks like that. We already fix the problem. But if we have someone called Bed Boy Bad boy. What? What? Bed buoyed us. Um, you Great. So cat, uh, sockets. You created five thousands off them. A lot like 5000 circuits. That's sorry. Let's put import here. And Sam, um, what he did, he opened new socket local Horst 80 80. He connects here. Let's put so I o exception. We don't care about exceptions here. We don't use any patterns. I just want toe. Remember that we just put everything simple keepers and simple to make sure you understand the court and everything in one place. You understand the idea, but, ah, send You will create Sarah Where? What you need. Like if you if you know what how it works. You smart enough to do exception friendly and right. It's not for junior Jiao, its advanced. And that's why I don't think we need to discuss an exceptions here or new filer. So you just have the ideas, how it works and how to do it properly. Like servers that works. Let's great since South and will do Sorry it sleep one If you guys don't know what it was This problem program does, I will tell you. It's like maybe you'll never work with Ah concurrency. Maybe Maybe you look at that, but don't really work with that. Like were heavily or something. Um I just explained what every line of the score does. We create the sockets like 5000 off them and then connect the local host 80 80 doorways server open 5000 connections and then sleep. If we don't put the sleep here, just ah, we will stop. This program is the main main ants. And we just, uh, finished Nothing. Nothing will happen that maybe it happened, but we don't need it. We want to open and wait. This is ah were scenario. Here we have a server. Let's let's see, it works right now. Yes, it works. Ah, the 2nd 1 works. Fine. Let's start a bad boy. A bad boy here. Ah, unknown host exception already also regards cyp But wrong. One word here When we start, we will see that here our connection likes 700 of them. 809. Everything looks looks very nice. It works. Um oh, they have We have fixed the problem, right? But maybe it's not actually true. Look at this, guys. We have a lot of suckers. Who? It's out off memory error here. What is going on? Look, we created so much threats here a lot off that a lot of these guys like to to thousands off these guys and we just run out off memory. We have kind the limit in Java. We we can create a 1,000,000 off threats. We just need to limit it to a specific amount because everything goes red waits. Ah, like, opened and wait for something else. We were open connection, right? We create and use red and it Ah, just it's memory, all kind of this stuff. We also have limits off this soccer limit off the socket socket is limited. We can't open. Ah, here exists. We can open like millions sockets here as well. We have a limited Jolla. I believe it's about 6000 sermon or so maybe 10. And it's should be configurable, I believe, But It depends on different things. Like windows, Selena looks or UNIX are. And it's in like this who held Lamento already. But ah, this is not the case. In many times the cases here it's out off memory error over there and how we can can fix city. In this case, we have this one works. Look, our program is not basically blocked completely. We have this working these guys but if we quit and try to connect their way don't have anything. Just his just doesn't work right now. So let's stop the server and well, stop it. It's okay sometimes it's it It doesn't even stop properly. We should ah, call kill here. But right now it's fine If you if you will see something like this You should Ah, you have this like, um ah head like like this Look for stars in No, don't right now. But you have ah, new bottom here. Like, um I know how it in English is Ah ah skillet or something over our head and you can kill it Just the process of you. If you see it, maybe let's let's try to fix this is this sink. Let's try to fix the same 3. Trying to solve BadBoy problem: Let's do an threat pool here. What threat pool means if you don't know, maybe threat pool. Let's say we limit number off threats to 100 for example. And use this 100 threads, um, to work in parallel. But if we have 101 then next one will wait until ah, we done job with the previous guys. And then we will have a free thread since threat Catch this new guy and process it. So what does it mean? We do? Onley 100. Let's corpus This, um single simple threaded and, um, that school. But it's cool. It's simple threat pool server. Uh, close. Close. This one here, lets stop everyone okay and should execute er service it. This from Joe Wa five, I think execute er's new fixed. I think you already know this stuff. We create a sink, 100 off threats here. Let's do it 100. And then, ah, we should call set ofhis submit. Ah, questions that we should said May said Mitterrand Herbal, look Ah, you're on the ball. Then it will work. We can also do a horrible here, but we don't need in a result. So we're just Kopassus Lambda. It will work also. Great Simple Korpi, Elves this sing Ah, this threat pull Create new threat for us. We don't need it. We call. Just submit and execute er service will create stress for us. Does this thing kind of better? Looks better and it is better. But it don't really fix our problem here. And now you will see why. Let's connect. Hi first 1st 1 Good. Ah, sorry. Ah, for hello? 2nd 1 here works. Okay, lets start the bed. Boy, That boy. Oh, sorry. Socket disclosed. Let's see. Looks guys. Hey, look, guys, this is what I told you about. We can't create any socket socket closed, right? Right Now look, we have a 4057 limit here. Let's put it to add to aging 2800. Just limit disguise. We don't We can't create a lot of sockets. Also. That's great. Ah Ah! 2800. That's it. It works. Look, we created every every single socket. We don't recreated here as well. We don't have any exceptions. Any out off memory and it works like this works, Works fine. Foreign. Uh, is this war X two still works and then we close. Let's let's close this one. Maybe you sink it like, um maybe you think it's different if I close this but keeps this? It doesn't really matter. We just need to close the connection. And here look, we have connected socket. Look here. Just connected. Let's Dio was the one more time. Ah, quit and then connect here. Here's a new circuit so we we have connection here we will stop. We stopped here. Ah, except is working. It's a it's fine, but what's going on here with? But we stop. We can't process this thing because we have a limited number of circuits. It doesn't work for us. Stop, stop, stop, stop doesn't work and then we stop stops this one too. But nothing happens because we have a bad boy with suck like 2800 off this sockets here and now, let's create one more sever to look at the next technology. It called simple threaded senator, but not server socket. We will use server socket channel. In this case, it's kind of a new I. Oh, it's called Javon New Iot, but it 12 years old, already knew I owe 12 years old Let's look at this Global Corp Is this simple cetera? I call it simple Server Channel, Channel seven. Let's close this one. This one and we should put channel here. It will look a little bit different Set of our circuit channel open. Then we server bind 80 80. But ah, the same idea Just different. Ah, a little bit. Ah, different Syntex. Ah, we should put in that socket address here. Bind A dated We have the same thing here and then we'll also should put channel are except it is blocking also blocking And never now Right now looking Never know Then we should change handle to put not socket toe both soccer channel And it is completely different. Completely different technology. We don't need this one anymore. It Ah this handle doesn't work for us Way will look at different technology It called bite buffer by the buffer It's ah specific array off bites If we look, uh, golden, let's let's create it. Allocate direct 80 This means I allocated direct memory 88 Each character's here If you look at the buffer is ah it have bite off area array off by its here We can also create the ray, but by batteries, Mawr, like, uh, comfortable class to use Race very basic about by buffer is specifically created for this type of sink. Let's do it the same. Let's do the same in data and put, uh, in date. Ah, he kills socket. Read. We read it in tow. Buffer exists. Um, it's your exception. We don't need an exception. Right? So we would just catch, uh, I owe exception and put new throw you unchecked io exception Here. This is enough for us. Um, Zen, We check if data, uh, it kills to We're just I think we just don't need it. May be not not Take yours minus one. Okay. If not, it goes minus one. No, let's do it. The other saying, guys, let's do it like this. It's life. So I should think a little bit on that. Where does the same thing, Like while? Data. Ah! Ah! Buffer Zen. We do it minus it. Kill Don't equal to minus one circuitry. It data don't ecos toe minus one. One more. Here we said read it always right. And, uh, now, let's look, let's look at this thing. Ah, What buffer does Butter here has two variables there. Limit. Now it's 80. It's going that how many bites you can put their maximum. We can put 80 here, and he has current position here. Let's look at specific specific case we put Hello, Maybe. Or, um let let's Botello hello there for Hello. It will be limit 80 and position five position. That's where we're positioned in the buffer right now. If we put 55 characters here Myriad 55 charters here. So we we have now we now we own position five right now. Then we should do something like this. We should prepare buffer toe read from it. Now we can read from Buffer. That's why we need to do something like this. Set position to zero and limit 25 This means when we start workers buffer, we start with this zero position, right? It's kind overseeing from our end. We have specific function for this buffer. It's called bathroom Flip by for flip. If if you look at this, it's called limit to position. Position to zero mark minus one is is That's it, Sand we do drones for but we transform buffer. Not we will not transforms the single like single character Because because we have a lot of this guy's on while I will create this transform in a minute. Let's look at this Here, guys. Ah, very interesting thing. One more One more. Very interesting Singles this buffer when we ah, right from buffer When we try to write buffer into output stream Like this Ah, socket, Right, Butter. Um it said, like please, Right. Uh oh, as much as much as you can know, this means you will not always right. All the buffer is there. Joel will Look how much? Ah, it depends on different things. How much thread you have? How much memory help all these things. But ah, all I try toe tell you there till you hear that you can have situation, will you? Right. But you have some data left over here. So we create something like this while but author has has remaining Zen, right? Write it here. Oh, right. Until Buffer has remained. And then when we done when we write everything we have, we can dio buffer compact butter compact means putting toe. Ah, live limit 80 and position zero. So prepare buffer for new Read says, That's it. And now we should create a transform, right. One new function Transform that Get a buffer. That's a buffer. That school the buffer. What we do here just but, uh, limit. And we put it What here? With a new menacing and said by affair poot e bite, buffer, get get e ends and transform It exists, Transform. We will, um, goes through every one off this bite every single bite and transform it with this function . So we get ah, fills bite here. First bite, for example. Zero transform it it put to the first position. Then the second served etcetera. So we just goes through every single bite and transform it. That's it, is it? This should work, guys. I think it it should works. Let's, um, like stood here. We don't we kind of don't need don't needs this sink. That's remove it. Okay, So here's accord. Let's right. Ah, that scores here doesn't work because of this threat. Clear. Then start. And it helps a settler set of her running. It's flying. Let's look if it works first one cool works 2nd 2nd 1 Oh, second one doesn't work and it is We kind of expected because we have single threaded silver. Right? Guys, look, when we when we stop here, we have this. This one works. Ah, just the last thing We were due for this video. Um let's let's look at this server set of a socket channel. It's the same thing as simple Sever, but was different technology called Java You I o new ill which is 12 years old already. Maybe so Tune s So it's new old I'll Let's see And that this single threat it now you definitely know more about Java server socket programming bite, buffer and bad boys. I opens this video for you as a bribe. Now it is time for you to write several which really works. It will be stable and will process any number off clients. It is truly advanced Java. No simple is tough anymore. Just through hard core programming, you will create three more servers first. Really, really bad one. But a lot of people keep to and service like this and it will be interesting for you to look at never do like this server. Example. Second good single threaded server. You will learn how to use selectors here and third riel multi threaded server that you can use in the rial world. In the second part, you will learn how to work with John on blocking Io and selectors. Just click that by button and continue with me. It is very, very interesting and it will save you a lot off time. I have worked very hard to understand that stuff and you will know everything in 40 minutes or so. You know this is a test and it is limited by a number off people and also a time Bisys advanced hands on job training and get additional bones just for people who bought this advanced hands on Java training. I created Facebook Group. You will have a place for people like you. Tow us questions and discuss this topic. So you know what to do by the second part? Watch do as questions and have fun. Thank you very much for watching family Court OSI in a few minutes