We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

New Java Features & Apache NetBeans

00:00

Formal Metadata

Title
New Java Features & Apache NetBeans
Title of Series
Number of Parts
490
Author
License
CC Attribution 2.0 Belgium:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal purpose as long as the work is attributed to the author in the manner specified by the author or licensor.
Identifiers
Publisher
Release Date
Language

Content Metadata

Subject Area
Genre
Abstract
The Java platform experiences an outburst of cool new features – recently, local variable type inference, switch enhancements and multi-line string literals have been added to the Java language. Many other features are being in the pipeline and are actively worked on, like simple data carriers and pattern matching for the Java language, or value classes for the Java virtual machine. These features are delivered quickly, thanks to the recently adopted, predictable, six-months schedule of major Java SE releases. This new release cadence means new Java platform features are delivered twice every year! In this talk, we will show a live demo of many of the recently added and newly developed features and improvements for the Java platform, including those mentioned above. The Apache NetBeans IDE will be used to demonstrate the features.
Product (business)Local GroupOracleJava appletArithmetic meanMultiplication signProcess (computing)CompilerComputer animation
Computer fontProduct (business)Function (mathematics)Decision theoryOracleStatement (computer science)InformationDesign by contractCodeCommitment schemeFormal languageJava appletDemo (music)Source codeDemo (music)Slide ruleKeyboard shortcutStokes' theoremComputer animation
String (computer science)Image resolutionComputer animation
Execution unitImage resolutionComputer animation
Fluid staticsOvalPoint (geometry)Boolean algebraEquals signExecution unitFeedbackMathematicsFormal languageSystem callCASE <Informatik>Right angleBasis <Mathematik>Single-precision floating-point formatState of matterConnectivity (graph theory)FacebookLine (geometry)RoutingSoftware testingMultiplication signArithmetic meanMereologyGame theoryMultiplicationContent (media)Revision controlPrime idealString (computer science)Block (periodic table)Function (mathematics)Expected valueJava appletType theoryComputer-assisted translationSocial classConfidence intervalCodeOpen setException handlingHash functionSpacetimeComputer animation
OvalPoint (geometry)Cellular automatonFluid staticsArithmetic meanProjective planeCompilerConstructor (object-oriented programming)Hash functionRow (database)Coefficient of determinationString (computer science)CASE <Informatik>Position operatorConnectivity (graph theory)Conservation lawComputer animation
Connectivity (graph theory)Arithmetic meanPoint (geometry)Perspective (visual)Process (computing)Speech synthesisInterface (computing)AdditionConsistencyOverhead (computing)Computer animation
OvalPattern matchingComputer programConnectivity (graph theory)MultiplicationRegular expressionComputer animation
OvalBinary fileConvex hullJava appletInstance (computer science)Type theoryCasting (performing arts)Multiplication signInterface (computing)System callAbstract syntax treeCASE <Informatik>Pattern languageCodeGoodness of fitAnalytic continuationVariable (mathematics)Formal languageArithmetic meanHeegaard splittingConnectivity (graph theory)Integrated development environmentDataflowElectronic visual displayPhysical systemMathematicsRow (database)Medical imagingProcess (computing)Different (Kate Ryan album)BootingPhysicalismGraph coloringData storage deviceRegular expressionAxiom of choiceEstimationSource codeComputer animation
Integrated development environmentInfinityConstructor (object-oriented programming)BuildingText editorFormal languageJava appletPattern languageDifferent (Kate Ryan album)Source code
OvalCodeError messageComplete metric spaceCompilerMultiplication signSource codeComputer animation
OvalInstance (computer science)Interface (computing)Surjective functionJava appletConnectivity (graph theory)Presentation of a groupCompilerLatent heatPattern languageObject (grammar)Row (database)Theory of relativityMaxima and minimaPlanningPoint (geometry)Semiconductor memoryType theoryNeuroinformatikPhase transitionMereologyPressureWorkstation <Musikinstrument>Musical ensembleRight angle2 (number)View (database)DistanceConstructor (object-oriented programming)Online helpComputer chessComputer animationSource code
Point cloudOpen sourceFacebook
Transcript: English(auto-generated)
Okay, so hi, I'm Mihail Nahoda, and my day job is to work on the JIRA Compiler inside JDK. And on evenings, if I have time, I work on that means,
but that's like my personal hobby. And I work for Oracle, so and I will be talking about some future stuff. So I'm pretty sure you have seen this slide about 20 times already. Okay, and this talk is only demo
of new JIRA features in NetBeans. And basically, many of the features that Tricia went through we will go through in more detail saying why we are doing it in the way we are doing it, how the features work, and so on. Okay, so let me switch to NetBeans, of course.
So do you know the shortcut? I don't know the shortcut, right? Okay, let me.
Yeah, I, yeah. Yeah, okay. I think the dark isn't working, actually. It's too dark, and I think, I think, okay. Sorry, maybe make the editor white somehow. Yeah, yeah. Okay, so, yeah, I know.
Yes, sorry for this.
It should be fine. Okay, yeah, I'm sorry for this. Maybe not.
And, but yeah, that's not the resolution we wanted. Yeah, apparently putting too much strain on Linux.
So is it better? Okay, and let me, okay. Okay, so text blocks. Java has, as a previous, okay. First of all, as Java is releasing every six months now,
and we can have like a major, any kind of feature, including language features every six months, that's good. But at the same time, it's not really possible to design, test, evaluate, verify, everything, a language feature in six months.
So the idea is that we will introduce them as preview features, ask you all for feedback on the feature, adjust to the feedback, and after some time, then we are, yeah, and while the feature is in the preview mode, we can change it even incompatibility,
and after some time, then we are more confident in the feature, or confident in the feature, we change it to the final and permanent, and then it cannot be changed incompatibility that easily. So one of the features, I will skip switches
because that's old. So one of the features are basically multi-link string literals, which we call text blocks, and yeah, and it looks like this, and yeah, it's good, there is the highlight.
Part of the reason why it's called text blocks is that it like creates a block, and what you see like with the highlight on the background, that's the actual content of the literal, so everything from the beginning is stripped, the common indent is stripped,
and another part of the reason by text blocks is that actually you cannot type anything on this first line, anything except white spaces, to be more precise, because like the opening delimiter for the text blocks is three double quotes and a new line, and you can type white spaces at the end of lines,
that's fine, and yeah, let's not waste more time on the feature. I think it will be nice, especially for tests, because in tests you often have like a lot of code embedded, or a lot of like expected output embedded, and this will be really good.
And of course, okay, one more thing, of course you don't need to escape single double quotes because there is no conflict with detecting the end of the literal, but if you need to type three consecutive double quotes, and want this
to be part of the literal, you need to escape at least one of them, but that's, so there is a way to create a string literal that has three consecutive double quotes inside. So another feature is text blocks, and it's, you probably know it from other languages,
so probably some details, like imagine a class that has two components, X and Y, and you want to like make the class work properly, so you create a constructor, you create some accessors, note the accessors don't have cat here,
and note the, also note the components are final, and that's not like, that's intentional. And then you have equals hash code, in this case I was lazy, so there is no to string, and so you probably don't want to write this code if you add the new component, you need to regenerate
this in the ID again, and so on. So what if you would type just record, and then this, and now you have,
the meaning of this is basically the same as what was there before, except this also has to string. So we have, I hope it's visible, I'm sorry for the black color, it's probably not working, that's our only projector.
So we have record that has constructor equals hash code to string accessors, everything. Records are implicitly static final, so we don't need this, but now, what if you want to add, I don't know, logging for the accessors? Well just add the accessor, and add some logging,
and that's fine. You can like yourself overwrite everything that the compiler is generating, yep, please. No, no, no, the question is how about documentation,
I believe that you can write X and some dog here, and you want to coordinate the documentation properly for you, for the accessors, for constructors, and so on,
using these params, at least I believe that's the case. And there is another thing, and that's like, sorry, you can like overwrite the implicit constructor if you want to add some validation, like I don't know that X must not be less than Y,
for whatever reason, you can do this, but you have duplicated a lot of code, and you created a lot of trouble for yourself if you need to add another component. So there is a special feature for constructors, and that's concise constructors, and you can write this,
and the meaning is the same as before. Like no parameters, no assignments, and it should just work. The question is about overwrite annotation,
you cannot use it because you are not actually overwriting anything. You are like overwriting an implicitly generated method, but the overwrite annotation means I am overwriting something from my supertype, but you are not overwriting something from the supertype. Yeah, and yeah, another point about records,
you can add custom methods, you can implement interfaces, you cannot extend classes. Okay, and now let us switch to the real fun, and that is pattern matching. And so as you have seen, oh, yeah,
let me first show this, and imagine a program that can pass simple expressions, create an AST for it, so the AST looks like this,
so you have some node for the plus that has a left component that is literal one, the right component is the multiplication, we just, again, five and three as the components, and then you want a method that evaluates like these ASTs. So we have this interface node which represents
any kind of the AST node. We have a special subtypes for the node types, and no desire records, and that's very intentional. And then you can have method eval that will evaluate the expression, produce some answer,
and you can use instance of to check the types of the nodes, and then creating a variable, cast to it, and then you are suddenly repeating the same type several times. Yeah, let me write this small note here. And so this is not very nice.
So this pattern matching, what you can do is this, and the meaning of this code is exactly the same as the previous one. It will create a new variable called an N, and so on. And yeah, you can ask why we are doing it this way,
like introducing a new variable instead of using flow typing and just changing the type of the existing variable. Like in this case of that node, we have this N here, and can you just change the type of N here?
And N is at node, well, there is an issue with Java, with this, and that's one of the reasons why we are not doing this. And that is there is already a lot of code that's written like this, that's doing instance
of inside it and so on. And now if I, I have two really interesting, yeah, let me switch that this way. I have two really interesting methods down here, and one of them, they are called the same way, and one of them takes node,
and one of them takes at node. And here I am actually like calling two different methods, right? This first call will call the first method, and the second call will call the second method. And now if you change the type of N to be at node, you would be calling a different method.
So that's like, I don't think you can do it. It's like a silent, incompatible change in language. So that's like maybe half of the reason why we don't use flow typing for instance of.
But there is another reason, and the reason is, and now we will get quicker into the NetBeans part, at least a little bit. If you look at this handling of more node, we are actually not really using the,
or interested in the variable N anymore. We are only interested in the knowledge that the node is more node, and in the components. We don't care about the variable as such. So can we write, I don't know, this.
And okay, let me first say what this should mean. This should mean that if N is of type more node, then please split it into components, left and right,
and then declare the variables and continue. But you see it's not working very well in the IDE, right? And the reason is that first, this IDE knows basically nothing about this kind of patterns, the reconstruction patterns, and second, the JDK on which the IDE is running right now knows anything about these patterns.
So the good thing on NetBeans is that it actually can use the Java C from the JDK inside its editor to provide the language features. So I just switched the JDK to a different belt of JDK
that understands these reconstruction patterns. And like, it should be all fine. There are no errors. If I make mistake here, I should get an error
in basically the same error as I would get from the compiler on the command line. I should be able to see code completion maybe, yeah, the first time it's slow, sorry. Okay, and now briefly switch back to these features.
Of course you, yeah, one more thing. This, the kind of patterns like this are preview in JDK 14, these reconstruction patterns
are not in preview yet. There is no like, it is JDK that understands them. And it's not like targeted yet, so we don't know in the JDK it will be. But then you see they are repeating the type node here,
but actually the compiler can infer the type for us, so we can just say bar. But we can go one step further and maybe we can look inside the components themselves. So maybe we could say something like this,
and that basically means if there is a more node and the first component is a literal node, which has like, has a value, has zero, then there is no much point in like computing anything for the right, apparent, right?
And we could even replace the pattern here, this, this. And maybe eventually we could do this. And yeah, I would say this is the maximum
that this specific belt of JDK can handle. But there are like, and what we can fit into this presentation. But there are of course further like ideas that we could do this inside switches, switch expressions, and so on. There is relation to seal types and many other features,
but yeah, I guess even this is pretty impressive, at least to me, like that you can look inside, inside how the objects look inside memory very easily, mostly in a decorative fashion.
So yeah, I guess that that's it for me for now. So if you have questions, yeah. Okay, the question is whether this,
these reconstruction patterns need records. And the answer is that for what, for the phase that is planned, or that we are working on right now, it must be records.
There are plans for future to allow it for any class so that the user could say how to split the object into parts, but that's not part of the second, of the upcoming iteration,
which we don't yet know when it will be, but yeah. Yeah, I'm not sure how that works, exactly.