What's Cool in Java 8, and New in Java 9

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
for you guys this session is what is cool in Java 8 and new in Java 9 if we have time at the end I'll show you a couple of demos if not we'll make do with all of the content in the slide so standard disclaimer when I talk about what's in 9 these are our current plans such subject to change so it's not a promise it's just the current plans ok don't write a contract based on that about myself I'm a director of product management with the Java platform group with Oracle I've been in charge of the JDK since joining Oracle through the Senate position so I was one of those guys that join bulk in 2010 before that I worked at Sun Microsystems support management for in the Java team as well not directly with the JDK at the time and before that I worked a little bit in Florida I got an MBA from MIT and a systems engineering degree from University aneema in case my name didn't give it away it wasn't really from here so first the first part is Java 8 one of the biggest updates ever to a major language at the time the editor of dr. Dobbs this one is actually the one thing that I'm most proud of that was part of the team that came out with JDK 8 now that's the current version of the JDK and I'm going to give you a very rich content how many people here are developers good I'm in the right conference so how many people here are using Java 8 ok most seven six five four three two don't be ashamed there's one of you out there now okay so for those of you that are used in Java 7 or later these will be new for the guys that are using Java 8 I imagine you'll see the part of eight anybody here has tried JDK nine early access and why not you first we'll go through it so let me tell you a little bit about JDK 8 and there's a lot more than this but you know these are the most interesting parts of it land expressions default methods method references and a little overview of the day time API and then I'll just give you the eye chart X for all of the other features so that you can go and find more about it the first part anybody here programs with JavaScript or Ruby or Python ok so you're familiar with lambda expressions right the idea is that you can pass data I'm sorry you can pass behavior around as you can pass data so everybody's familiar with the concept of I have a variable I'm going to put a number in there number is data the idea of lambda expressions is I can do the same with behavior not just data but behavior now so as an example this is using the new enhanced for-loop right if I wanted to remove everybody in a collection that it's greater than 18 and looking for you know like only the people under 18 how would I remove it using this construct in the enhanced for-loop operator I do not have any method for calling it out so if I wanted to try this right this is I'm just going to show you a little bit how the lambda how lambdas change the way we design API so if I wanted to do this I would actually have to go and switch back to the long form that was available before JDK 5 where I use an iterator and that's because I need the iterators remove button so I just added a lot of boilerplate in order to be able to just remove some for my collection right there's a better way but until JDK 8 it was really hard to do this the right way ideally what we would like is for there to be some sort of interface that would allow me to pass on behavior and then for the designers of the collections to provide a virtual method called remove if ok and remove a footwork by passing in a collection and passing it the predicate so what am I going to do and it would magically go to the collection and remove everybody now we could have created this in JDK 7 but it would have been very painful to use because the only way for passing this behavior you know here's the collection people a bunch of people people and then I would have to have written all of this boilerplate to pass that functionality and that's a lot of code for something very simple so the reality is we didn't the person that wrote the collection API didn't feel that this was something that everybody was going to use and therefore the collection 80 I didn't have a remove if now everything in green here it's really boilerplate using lambdas you can rewrite this I guess right remove people then for every person here's the operation right gauge greater than 18 so if this is true and you're going to do it for everybody remove them from the collection right so now you can pass behavior right what am I going to do with each one of them as before I could pass data now this is not just about trying to make the code look smaller let's show a little bit of a more complicated example right anybody what does this code do just by looking at it quickly it finds amongst the people in my collection only from the male's the highest weight it will throw away the you know like the females right it takes a little bit of you know reading to get that right and if you notice I'm not just telling you what to do I'm telling you in which order to do it I'm telling the collection iterate one person at a time right get the gender get the way get the max now we can do this using lambdas something that looks a little bit more like the problem statement right get the list of people filter out everybody you know just filter the male and then map you have you heard the expression Map Reduce this is the map part right I've got a bunch of people I need to map it to something and I'm saying go and look at that wait in this case I could have looked at the age whatever right so that's the map part and then I'm going to reduce it and say at now instead of having a collection of people I'm going to have a collection of weights after the mapping I'm going to reduce it by saying just give me the max okay now it's prettier to look at but the truth is if this was all we were going to get out of lambda expressions it was a lot of work to be done in here we wouldn't have done it just for that what makes it more interesting is what happens if you want to rewrite this because this is still going sequentially one person at a time and do this sequentially what if you want to write this in parallel so that if you have a bunch of different processors you could have some processors handle half of the collection on the other processor JDK 7 we introduced something called the fork join framework which would pretty much allow you to do that you would get a problem you would say I'm going to chunk it into smaller pieces and I'm going to let each processor or you know handle part of it and what if I wanted to do this thing in parallel using the for game framework the fork joint framework that you're not supposed to read that it's just to show you the amount of boilerplate the stuff in red is actually how you solve the problem everything else is the forging framework now it's not always better to use parallelism you will pay some price for this so in many cases the question is should I do it or not well you know try it out measure the response and see which one is better how many people do you think are willing to write all of this and we'll get it right in order to discover that you know what it was easier to do it sequentially you know it's small enough of a collection nobody right now if you go back for a little example wouldn't it be great if the people in that D api's handled that for impart for you so let's convert this one into the parallel version done okay rather than streams I did parallel streams it may look by the way like this is traversing through the collection three times one for filtering one for mapping one producing this is much better than that you'll do it all in a single pass so it's only hitting the collection once it's very efficient so that's a little bit of what lambda expressions do for you we introduced these in JDK 8 and it has changed the way that we code quite a bit it also introduced a couple of interesting situations right so that was lambda expressions now default methods have you remember do you remember the API called Nile it's called new IO right and that's because we had an IO a new input output interface and then somebody came up with some improvements to it and we had then to create a new set of api's for that called new IO we had a bunch of collections now we want to add this new abilities like the remove f4h statement how would you feel if we tell you yeah here's a new set of collections collections - right because all the other collections they didn't have these new capabilities and you already code it for them and in in Java we wouldn't let you modify a collection by adding a new method right that would have been a problem I really didn't want to see another new collections API so we introduced another interesting concept called default methods you see here we say stream right collections that didn't have stream in JDK 7 so how can collections have stream now what if you've created your own collections and you didn't implement stream I'm not going to break your code here's what we did when you define the collection interface now you can pass a default method and the beauty of this is if you do implement the method right what you've implemented will be what is used but if somebody doesn't implement the method they get one for free this is like the public defender you know if you cannot afford an implementation one will be provided to you free of charge and this allowed us to create some methods on collections that already existed and therefore you can continue using your collections they magically get new methods you don't have to choose for new collections okay so that's major plus for a decade we did it of course in the API you can do it on your own code as well we also now allowed studying method in interfaces okay so static methods you can have zero or more static and another one that I like is the method references there's a bunch of lambda expressions that look like this I'm going to get a particular variable and I'm just going to call one method in the variable right so p-p get name we this is so common and when we were doing JDK 8 we didn't just create these new methods we went and we use them in the jdk libraries itself so before it even was Reese we had a major use case with you know hundreds and thousands of lines of code where we thought oh let's use this method and we discovered this was pretty common so there's a shorthand for it now if you see this little double column operator it's the same thing right it's just go and call to uppercase and that's Method references you will see that probably when you start looking into JDK 8 code now you know what it is right it's just shorthand for the second one so in summary lambdas are just functions these has allow us to create new api's and now we can use functional interfaces we've introduced default methods and method references now that's for the technical part for the practical part you know I work with NetBeans most I des have some sort of tool that will allow you to automatically convert your code so that it uses new land expressions where for example you were using anonymous inner classes so this is what it looks like in that means if you just here's an anonymous inner class and I'll say use lambda expression poof we'll convert it so if you're new to these what I would recommend is go to some code that you wrote and that you understand let the tool find some instances where it can convert what you wrote to lambda expressions and then look at it before next to the conversion and at least it took me I don't know three or four days of going through these before it click and I started writing lambdas myself directly rather than using any tools to help me and it's easier to do it with code that you are familiar with so that you are not wondering what is it doing and you just look into the syntax and how it changes so here's another one use member references so you see this one it looks a little bit like what I explained that little member reference and it turns it into get a real count so many tools allow even for batch refactoring so instead of just going one file at a time you can just go and say here's my project could you check the syntax and make sure that it's using everything in JDK format and it'll give you a little before-and-after for each one of them so that's pretty useful okay I recommend that you don't just blindly accept things understand them because that's the whole point you want to write these this way from now on okay so as I said a rich content that's it for lambdas now I'm going to talk about one of my other favorite expressions daytime API these are 3:10 I believe Stephen Colburn this is one of those api's that was not developed by Oracle anybody here heard of Java time right and before that Java had its own set of API now there's nothing wrong with the previous API but they don't let you assume anything so a couple of questions anybody knows whether we're using the Gregorian or the Julian calendar anybody okay I'm not gonna put you in a spot we're using the Gregorian calendar nowadays next question what's the difference between those two Gregorian and Julian anybody yeah in the Julian calendar the rule is every four years you get a leap year okay that's the old one the new one has a little rule that says except in the years that are divisible over 100 in which case they're only live years if they're also divisible over 400 and the final question who thinks a developer should know that before deciding which calendar to use because the previous API sort of assumed that you're going to have to answer all these questions right it also didn't let you get away with anything like ignoring time zones if you wanted to specify a time you would have to tell me a time zone it wouldn't accept anything by default and we humans actually are much more comfortable with a little leeway right and most of our problems don't need that level of detail so show the time and now this new date and time it's much more intuitive it's closer to the way we think about date and times so here we go we replace date calendar time zone and date format it's now fluent in mutable thread-safe and pretty easy to use if you've been using Java time this will look very familiar it's the same guy that did the both of them you can look him up and he'll explain why he thinks this is the next level of evolution so there's some tweaks that he didn't do any other time that he pulled out in here strong typing easy formatting and parsing and it's interoperable so if we were using calendar date you can just toggle back and forth units fields and chronologies he'll explain those and support some regional calendars it has a bunch of calendars built in if we have time I'll give you a little demo of you know a cool instance of that and it uses ISO 8601 and for those that don't care for the numbers that's the normal calendar that way but I use is nowadays so you have a range of types dates consisting of year month and day that's when don't care about time right like local date local time let's just the time and if you combine them together there's another type called local daytime which looks pretty much like you join those two together pretty convenient the time zones are handled separately okay and there's the instantaneous point in time instants which is the closest thing that we have to the previous java.util date now choose the correct date and time when designing an application okay local date stores in year month date most of these will use the Gregorian calendar the one that we know one use most of the time so things like birthdays start these holiday days when somebody asks you your birthday you usually follow up with where in the world where you born so that they can you know tell you happy birthday at 7 p.m. because that's when the times now you just care for the date right local tanning just the time there's no date in here so opening hours on the laptop wake me up at 6:30 which they every day ok and the local daytime you just glue them together you have instant the best thing for login time cutting and then you have time zones now the time zones as you will know the world divided into different time zones and it's not mathematical we change the rules on when you have daylight saving times and they even change within the same country based on rules made up by people on the spot they change year over year so if you can avoid them and work only with local times and safe like that Europe your life will be much simpler if you can store everything say in universal time and then convert them only to output or input much simpler try to do that we do have time zone information so if you need these you have four classes the song ID that's the one that has a little text that you're familiar with in the offset that tells you five - five hours we're here - eight or - seven depending on the time of the year and some rules that will tell you when to switch from one to another and Sunday time is the one where you keep all of this now calendar systems main classes use the ISO calendar system which matches the Gregorian one which is the one that we use nowadays not historically accurate I don't know if you know that you know we switched from the Julian calendar to the Gregorian and different countries did it at different times there was some offset so some dates don't actually exist if you look them up okay and there's other calendars also supported here app which is a lunar calendar and actually one of my favorite ones for a particular application that I'll show in a minute Japanese Mingo Thai Buddhist as far as I can tell the big difference between these last three is they're the same as ours only they have a different year and that's a gross oversimplification so somebody can you know cares to educate me later that's fine the hidden one is a lot more interesting my mind that's a lunar calendar okay and it only affects dates not times of course you have durations sometimes you don't want to specify a start and end you just want to say a duration so three minutes and I don't want to say starting now and any three minutes from now it's just three minutes you know without a beginning and end and you have well the duration is you can think of it as hours and minutes right it's pre exact then you have the period which is a little bit more complicated that's that's remember when I said that we people are very comfortable with a little bit of ambiguity with dates and times years month and day and my example of this one is if I tell you it's one month away how many days is that well depends right it could be 28 30 or 31 and we're okay with that so if you know if you're working at that level you can use a period if you want more granularity use the this one right so for those of you taking pictures this is the one that has everything so local date local time both of them together sewn day time at the times on the instant duration and period and as I promised that was a very average content we have a lot of changes in JDK 8 and you can go and find information about any of these changes and by the way this piece itself is a shorter list right now what I've shown you here you can find in a lot more detail if you want to go into the Java 8 launch event so I hate URLs because nobody remembers them so instead I'll tell you what to look for if you go into your search engine and type Java 8 launch you will find the expert that worked on those libraries on those api's on lamda explaining them in a lot more detail than I ever could so if you want to learn more these are the people to look into right Brian gets to our marks Steven Colver now that's the summary for my favorite features in JDK 8 now let's look a little bit into the future coming in JDK 9 there's over 90 jep's Java and has been proposals that are targeted and are actually ready in the early access builds of JDK 9 this is a public page just search for open JDK 9 you will find the schedule and down here the complete list now nobody that you know doesn't work on this has ever read the complete listing details so I'll just pick and choose some of them and I've categorized them into behind-the-scenes improvements new features new standards housekeeping and some stuff that it's gone no longer available in JDK 9 so behind the scenes these are the goodies that you get just by moving to JDK 9 you don't have to recompile your code you can just grab your classes compiled on JDK 8 run them on JDK 9 and you get some freebies write some performance improvements less memory etc so I'm not going to go into a lot of detail because the intention here is I'll just give you a glimpse if you want to know more and I failed to mention that one here is the little URL thingy just type the jet number here and you'll get a lot more detail okay so store in turn strings in CDs archive short of it is you can have a bunch of strings shared the same representation memory so it uses less memory saved a lot of memory from our tests in Oracle products that manage a lot of strings even better compacts strings we realized that we could do better than saving everything in in in four bits we could do 16 bits I'm sorry in 4 bytes we could do usually 16 bits and if needed we can go larger but the majority of strings take now about half as much space okay now this one I love it because it only took 20 years for Java doc to get a little search box so your documentation created with Java doc will now have that search capability by default and that's a pretty good search if I do say so myself even though you can search camelcase and we'll do a smart hit it will not just find everything alphabetically and put it in there but it's uncanny how the talk here is more likely than not the one that you want it okay so that's what you get for free we also have a bunch of improvement that these are new tools and capabilities that like most things right if you don't use them you don't get the value of it but they're available for you if you're now calling again to JDK 9 these are the ones that are most likely to be used by most developers there's a bunch of other smaller ones that are pretty obscure first one project Dixon and I'm going to go into a little bit more detail if anybody goes to any call any session about JDK 9 this is what you'll see right we've modularized that platform now most of the work was to modularize the jdk itself but of course you can use that to modularize your own applications and this makes managing large code bases much simpler okay there's another side story this is a partial you know this is just a zooming of the graph that explains the module so you have the base system depends you know then you have modules that depend on base it's actually here here's Mason ago I cannot even read it here so with this modularization allow us to create this other one of my favorite tools j-link the java linker so up to now the common deployment mode model is every Java program shares one GRE write so all programs run on the same runtime and that means that your GRE even though you may want it to run only just a very small program that doesn't use a lot of the classes that are available in the JRE that Jerry contains everything right it contains core bar encryption and if you want to do a little hello world why do you want to have all of those capabilities now it's a lot more common to have an application include its own runtime right this model of let's all share a runtime it comes from the time where 50 megabytes was a huge load and nobody wanted to carry another 50 megabytes right now how many of you have little applications on your phone that are measured in gigabytes so the idea of we must all share a runtime to save a few megabytes it's no longer the most current one with j-link we've introduced an optional intermediate step which is you normally we're compiling your code and then you were running it right jaelyn you can link it and you can also use it to create a customized runtime so we'll basically go and say what modules that your application need oh it only needs base login and this other module okay rather than having the whole thing in there let me create a special image just for you with those three modules and therefore you'll be smaller a lot faster you can include your own modules into this image so I can then give you here's a runtime and it has everything that you need to run your Java program and it's a half or a third of the size of a full GRE so if you're creating a bunch of containers and trying to create runtimes for a particular application as opposed to something that will run every conceivable Java program you really need to look into this okay enhance deprecation anybody what said why do we deprecated API we thought of something better than that one there was something wrong with the previous one we have to get it out of there or the style wasn't right we actually use deprecation for many things and it was very confusing because to me the important thing about the application is are you going to throw this API away because if you're going to remove it I want to know about it right there are other cases on which something new and better is available which means if I'm coding a new program I should use that but if I have an old program that works fine I don't need to go and refactor it right it's going to work fine since we were overloading the term deprecation to mean any of those it was very useful with JDK 9 we've added an annotation and the important one here is condemned equals true and the idea is to tell you we intend to remove this API in the next version so if you're using an API that has condemned equals true you know today that it is not likely going to work in the next version of the JDK ok even though the next version of the JDK hasn't even started you already know that now you can get a warning when you compile but we also provide you a tool that's the set up the red bullet at the second one it's called Jade upper scan you can run it on any code and will tell you whether it's using any deprecated API and you can pass it a parameter and say just show me the ones that are about to be removed so that's very useful you don't need to have the source code you can just run it on the microf who here has created small collections right it's even worse if you're trying to create something that's immutable because I don't know if you discover how to do it you have to first create it then populate it one at a time and then convert it to immutable that's a little bit too much molar plate for something that small with this one you can do it in a single go so most of them they have an overload so I think it's up to ten elements yes so you can do up to ten elements with these factory collections okay pretty nice J shell anybody knows this guy rebel other languages have had these tools for a while so if you want to explore an API right now what do you do you fire up NetBeans or tapes you create a little scaffolding right because if I want to know how an API works I'm going to need to create a method that uses that API right so I'm going to have to use one of those you know main that calls this little thing just to discover how the API works that's way too much trouble so IDs actually have integrated this tool into itself I said I use NetBeans there's an early access build of NetBeans that works with JDK 9 and if we finish quickly I'll show you a little example of how to use this rebel tool to play around you can just open a command line you can type it has code completion it's a little bit simplified you don't have to put the semicolon at the end of every statement you can export you can you know have a little Java interface come up and you can edit what you've used so it's pretty useful for exploratory code and once you understood how it works you can just go ahead and write the write API without having to play around with it something that I wish we had before move to release jar files so what happens when we come up with a great new idea in JDK 9 but you want your same code to work on JDK 9 & 8 & 7 you're pretty much stuck because you know what I cannot use this new API because what happens when somebody tries to run it on JDK 8 it's going to blow up in their face and therefore there are some things that don't get adopted as quickly as they could be because developers have this concern about I don't want to have to create a version for aid and a version for 9 I want a single version that works across both of them now here's how this looks like JDK 8 and if you're running this particular jar in JDK 8 or below these are the classes ABCD if you're running it in JDK 9 it's going to override a and it's going to use this one instead and B this one instead so these two classes a class and B class down here can use nine only API the a and B class is up here those are the ones that you write for eight and below and the idea is that as we move forward and you have this available you can have different classes and say this one is four eight nine and ten this one is roughly and you can have in a single jar a program that runs in different versions of Java okay some new standards these are things that we didn't invent they're just we're grabbing what's available elsewhere Unicode eight so you can see every version of Java adopts new versions of Unicode I beat you have a seven launched with unicode six so there's about 10,000 new symbols anybody care to guess what the vast majority of those are emoji cyclists alike but if you were dying to write Navajo in lower case you're going to need Unicode 8 because that's where it was introduced before that you were always screaming when you're writing in Navajo I had to look that up because you can write your your property files now you can use utf-8 so when you pair it with the other one you can have a property file that's all ammaji if you know you are so inclined okay you before that you could do it but you have to encode them now you can actually use utf-8 so that's pretty nice OC speed all CSP stapling for pls that's a mouthful that's one of my favorite features it's pretty technical but I love it here anybody knows what that is good I get to show off right now when you go on you ping a server right imagine that you try to connect to an API that says I'm going to connect to I don't know Microsoft the way it works is you go and you connect to Microsoft and Microsoft replies and says HTTP here's a certificate issued by Verisign that says I am Microsoft so what does your computer do it says when was the last time that we check the certificates that were revoked from Verisign was it more than an hour ago no it's less than an hour okay let me go check that list yeah that certificate is not there we're good if it's more than one hour of this is the first thing you check you have to go on Ping very time and say has that certificate been revoked right and that means that a lot of people are paying in first Microsoft and then Verisign there's even a theoretical denial of service attack where you use a certificate that has been revoked and you block the person from being in Verisign right and most browsers now they assume that if they cannot think very sad you know there's connection problems everything is probably okay very good let's just rest it right it also allows you to leak a little information Verisign has an idea so how many people are visiting Microsoft because they're getting pinging so how does this work Microsoft once an hour things very silences could you give me a signed note saying that I'm not expired and rather than every client having to being very time remember how you were going to trust the answer for a sign for one hour this is no different the only difference is now Microsoft says here's my certificate and here's a recent signature less than one hour old saying that I'm not expired you don't have to check anything else pretty neat huh new hash algorithms who here has kept abreast of all the news about md5 and sha-1 they're all getting hacked that means you need new ones so you know we're going to continue in this little hamster wheel for as long as I can think I don't see any answer now so they'll keep cracking and we'll keep adding html5 Java doc just looks better so here's another one HTTP - so this is protocol it's you know very used nowadays it makes things appear to load faster there's a whole set of tricks that they use - even though it's sending them as same amount of information things appear to load quicker now this one also allows me to introduce something new called incubator modules now what is that you may ask how about a nest oh no come on play with me what is that so incubator modules is when we define an API and we put it in this standard the minute that we put it out there somebody goes and builds a huge system on it and then we cannot change it ever again so whenever there is something that we're not quite sure if the API is ready we always have this problem right we try to ask for feedback but until it's actually in the JDK most people don't get feedback incubator modules are it's a set of modules that pretty much guarantees that that API will not be there in the next version ok so you can go and play with it but it comes with a warning you shall not build something on top of these that you intend to use in production for the long run because it will not be there in the next version hopefully it will help as though by getting some more feedback and we can make sure that the API when it gets into this standard is the right API okay now housekeeping we've set up some future improvements and we reduce some complexity this one is the one that's going to get the most news we've encapsulated most internal API now I can find you on 1998 web page you can look in the you know Internet Archive with Sun Microsystems telling its develop first do not use the internal API they're not part of the specification that's what we use internally to implement the specification so stay away from those they may change the may disappear and you know it's if you're using some other vendors implementation of Java they may not be there now when we did this we of course have access to the same open source repository that everybody has we went a look to a bunch of commonly used libraries how many people think you know that less than half of them but you know about half of them use this internal API half of them anybody know 60 80 90 percent how many do you think actually use internal API is even though we told them not to try a hundred percent okay every non-trivial API that we defined they use some of these internal API that makes your code brittle and it makes those internal API you know we cannot really evolve them so we really can and we're finally going to encapsulate them they're not going to be there by default okay now that means that those common libraries that I was talking about there's going to be a new version of them that doesn't use those internal API there's also escape clause there is a command line that you can pass to expose one of these api's back if you need it please don't do that unless you're planning to rewrite your code and this is just a temporary step okay there's a handful of API that when we went looking we decided you know what these are not just convenient things these actually do important things and there is no actual real you know supporting API part of the specification that can do what these things do so for the ones listed there and only those they will remain enabled by default you don't have to pass anything those will remain there we're working very hard to provide some api that are part of the spec that do the things that these guys did in a supportive way until we do they remain available this is not we've turned them into part of the specification and now that now they're there forever hopefully in JDK 10 or JDK 11 or as soon as we can app with a new replacement those will disappear but for nine don't they need to use them if you have to okay there is a tool that's available since JDK 8 called Java dependencies J depth that you can run against by code and it will tell you whether you're using this API so I would recommend that you go ahead and run it against your code and when I mean when I say your code I don't mean just the step you wrote but also the libraries that you rely on okay because I expect that most people will have to at least get the next version of their login utility or framework etcetera modular application packaging remember that I said that there's the J link that creates a special runtime we have a tool that will create a package so that it looks like a native application we have with JDK 8 but it bundles the whole jury with JDK 9 it uses this daily link tool to create a smaller runtime just for your application new version string have you okay which version of Java is the current one 8 update what 120 something right and if you do a Java - version string what do you get one dot 8.0 you something right what's that one dot what's that zero all of that there's very good reasons why those were there to begin with but they're gone in JDK 9 so the version string for 9 is 9 not 1.9 and it's got semantic versioning so there's no you know news and there is more than one digit to read so if you were parsing the version string we've seen code that looks at the version string discards the first digit and starts looking at the second one that won't work ok ahead of time compilation if you don't want to compile a winter Bureau on your jet you want to create a compilation ahead of running available in the next one md5 string concatenation I love this one I had to you know look up what that meant as I mentioned we've introduced invoke dynamic in 7 or 8 getting market in 7 JDK 7 and this means that rather than the compiler figuring out the code it can say you know figure it out at runtime now what this will allow us to do is anything compiled after we do this right now we're the same but if we think of a better way of doing a string concatenation in the future we can make it so that code compiled with 9 and above takes advantage of those benefits you don't have to recompile it so this is what I call you know housekeeping this is just looking forward when we come up with a better idea you won't have to recompile to get that advantage unified average collation login and we're switching the default garbage collector okay now anybody here cares about which garbage collector in your application uses if you do I'm guessing that you have a parameter telling the operator the the runtime which one to use so you will not be affected these will only affect people that don't specify a default okay project coin you're familiar with that one came with JDK 7 we did some minor changes to the language we're doing some further improvements ok this one I like filter incoming serialization data now this one I have here because this one is actually now available in versions 6 7 & 8 so it's a mechanism by which you can tell don't just accept any data here's a set of rules my application only expect this type of data to be serialize anything else kick it out okay and this is as I said the only feature I can think of that's started in 9 and has already been back board and it's available in current releases a bunch of garbage collection combinations where deprecating in 8 can you tell which ones are red that's visible right so these guys right here in red those were deprecated in JDK 8 and we have not been testing them so I don't have the work probably well they're going to be gone in JDK 9 now what does that mean as a general rule if you're running your JDK now and you're getting warnings things like this thing right if you set parmgen size in JDK 8 it tells you I'm ignoring this I remove that you know this is this is we remove this in JDK 8 in JDK 9 that same option will error out so don't just ignore those warnings they're there for a reason please and I know people are going to call me and complain about this when we go live and I cherry-pick the ones I liked as I said there's about 90 of them and there you can go and read about any one of them in a lot more detail than anybody you know could do in a single session okay so now for my call to action download the JDK and early access build I think I left it here just search for get ek9 you'll find it we change the build number periodically so don't just grab one and test forever you know check every time we've already reached feature complete so if you were waiting for these to have all of the features before you start a testing you're not to wait anymore you can do it today okay and there's a summary of changes on every build next one join the conversation for every one of those jabs if you look for the discussion field it'll tell you which one of these areas you can ask questions about that people that know most about these particular enhancements monitor their in those discussions you can go ahead join if you have any questions or suggestions please review the archive because we've got lots of questions and nobody enjoys answering questions that were answered six months ago but if you have any suggestions so you find any problems you could ping me and then I would pick them or you can just cut me out of the loop and go straight to them okay download some idea of your flavor like your favorite might taste NetBeans they offer now capabilities same thing they're working to provide support for the new features at GA like us they also need feedback please get back to them and tell them what they're doing right and what they're doing wrong that Jade EPS tool that I mentioned it's available in JDK 8 you're better off using the one in JDK 9 when you find something that you're not supposed to be using you'll actually tell you when we know which supported API you should be using instead okay so please run that it'll make your transition to JDK 9 much simpler this is a little bit like planning for retirement you do not want to wait until you have to go to JDK 9 to do this if you do it now and do it incrementally this will be easy and as I said there is this very convoluted set of here ad exports this is what will allow you to we remove that restriction and have those internal api's reappear for your program okay so that's it with the slide deck and I think we do have a few more minutes before I forget the guy that just came before we started Bruno reminded me to remind you that there is a reception we're going to have beer wine and that kind of stuff where we had the food so after this session don't just bowl to your cars you can kill some time there and wait for the traffic to die and is there any questions from what I show or does anybody care to see a little demo of J shell and perhaps some sample code yeah let's let's try that and I haven't prayed to the demo gods so you're going to have to bear with me my computer's also very slow can anybody read that first of all because this is not going to be fun can we change the resolution is that beatable yeah okay so this is JDK 9 I think I'm a couple of versions back and as I said my computer super slow here we go 156 I'm going to show you J she'll remember that I mentioned that there is this tool the repple tool that will allow you to explore a little code so one of my favorite here we go so haven't done anything I can do simple things like hello it's string right dot soup I'm going to tap here and it tells me what are the methods that are available for that string let's say substring now I'm going to do a shift tab and it tells me what are the possible right methods that I could be using there it's overloaded so it could be the beginning the trend and I can say let's say from 2 to 4 and it creates this pseudo variable 1 which is the 1 1 and also you can get if you don't want have access to the IDE you can do this the example that I want to show is anybody ever try to compute the phases of the Moon right you want to know whether it's full moon or waxing moon or wining moon etc etc you can do very complicated math to do it and I'm sure somebody at NASA would love to tell you how to do it but I'm just going to cheat and I'm going to simply convert the date that you want into a date in a lunar calendar and the beauty of lunar calendars is all of the months go between one to either 29 or 30 and those dates match exactly the day of the moon so that's all a blue right there is a calendar that supported here by default in JDK it's the historic calendar now it's where let's let's just do it again I could type date dot time every single time but I could just do an import date time I'm sorry Java dot time here I'm going to need a couple of others let's get the time dot chrono and import any case you don't remember Java that I can do the tap thing and it will tell me so it's it's got the completion let's try this temporal chrono-field there so now if I just wanted to get the current date I can just they say something and say local and I'm using that code completion because I just can type local date dot now that's a current date okay if I would like to know the same since I imported I'm going to show you by the way list it is all that I've typed okay I can do a help if I want to know everything I can do but let's get the current date in a lunar format and that's called cifra date dot now there I'm just going to look at the day Oh - since the moon starts at 0 0 new moon we're pretty much new moon there is no moon today out ok and you can do as you can see pretty simple I don't have to go and write code that does it I didn't even put the semicolon I can do even the dollar 6 it creates that variable for me dot get chrono-field dot day of month there you go so you can see here how can quickly do a function if I want to create a date rather than using now I say local date dot and I can say off and look it's a 2017 Oh 304 he'll create dates like that so as you can see creating new dates and times it's pretty straightforward that's one of the beauties of the new days hire 310 you don't have to do the whole let me create a calendar let me set the month and by the way in this calendar January is one guess what January was in the previous calendar zero you know we're developers we start counting so current month went from zero to 11 go figure here's what it looks like my little completed class right here I'm going to get the day form a year month day so if I say okay here's a date from local daytime year-month-day this will accept a year month day and it will return that lunar day if you will okay now that lunar day is based on a particular city on in the Middle East so it's not very accurate but I'm just gonna you know fat-finger it and say okay if the value is greater than four or less than twelve you're in the first quarter between 13 and 17 year on full moon between 18 and 26 you're in third quarter and everything else that's one two three and 27 to 30 that's New Moon okay now I could just run this but let's make it a little bit more interesting I would like to put this in the my Oracle cloud account because of course we have to put it in a cloud so that just means I have to create a little function that reads write whatever you pass and spit it out so here it is I'm using spark to not have to code anything of that because you know I'd not really want to go into the nitty gritties of listening to a board I I can pass the poll as a parameter if it doesn't work I'll use a DAT and here it says when I get a request just to check that it's alive you know if I don't pass anything I'll reply with it's alive and if I pass moon and I pass a parameter with date I can pass any date and I'll just return the date and time so here's this is I went to my Oracle application cloud and I just loaded this thing now here's the exact same can you read that can I write and just to see that I'm not cheating and adjusting in hard code a couple of them here's the moon phases for here California in 2017 and I just Google this one right so let's try full moon October 5 of 2017 so what we're going to say is there you go full moon you want to try first quarter let's say April 3rd aygul so it's up and running working literally about here this is it including the part where I listen to the poor word and do everything so pretty straightforward please give it a try and you know as you can see this is I had already logged in I can show you a little bit about the project just because all of your developers so it just requires there's a little tool here that will grab all of the dependencies put it in a single jar file include a little file that says how do I want to run it command Java - jar this is the name of the project right this is the jar puts all of this into that zip file and literally to run this in the Oracle cloud all I had to do was upload that zip file and this is what you have running here so if you have more questions about this particular part about putting it on the cloud there's a guy called Shawn Smith on the room right next door to this one that will be probably having beers in the next few minutes on the next session I can point them to you if you want that's it thank you for coming if you have a questions right okay what's the module and the module system sure okay so the idea of the module system as I said is instead of having one monolithic project for run the JDK we've separated the libraries into different modules now what does this mean to you in practice if you do not care for modules it means nothing right so your programs will continue to run you do not have to switch to a module system right everything they did it before will continue to work so it will impact us at the JDK level except for the fact that if you were using internal API a side-effect is their healing now because of the module system right and as I said that could probably be a full one-hour session right at a high level is we've grouped a collection of api's if you think of a bunch of packages all of the ones that have to do with security into one module whole ones have to do for managing the desktop into one module it's it's a different it's it's it as I said it's a collection of api's it's built into every module that has some dependencies to every to two different modules as I should probably show you the module system image [Music] right so we have modularized the JDK us a developer can mimic that and do that to your own code and separate your code instead of just having you know the package level you can have different modules and the idea is that modules will be self-contained they will only you know they'll create a dependency graph so it'll be easy to update on module at a time now you don't have to do any of this but you could right my point is as I said yeah you could say the JDK before was one gigantic module right you if you didn't want to exclude any module you're pretty much in the same place where you were before I said okay let me put a pin on that one come up here because as I said we can spend a lot more than five minutes that's not a three minute conversation that's more like a thirty minute conversation and I'll be happy to have it right here right now just not with everybody else here okay so see you guys at the refreshment table
Info
Channel: Oracle Developers
Views: 20,744
Rating: undefined out of 5
Keywords: oracle code, oracle developers, oracle technology network
Id: o-YQLLHc-xg
Channel Id: undefined
Length: 65min 16sec (3916 seconds)
Published: Sat Jul 29 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.