1555303175
There’s a lot going on in the Java ecosystem lately. Now that major Java versions are released every six months, it can be difficult to keep up. Personally, I develop the majority of my Java applications using Spring Boot. Because of this, I was stuck on Java 8 until Spring Boot 2.1 was released last October.
Spring Boot 2.1 added Java 11 support, along with performance improvements, a new metrics implementation, new actuator endpoints, and Spring Security’s first-class OIDC support.
I was a web developer years before I became a Java developer. I’ve been developing Java for 20 years, so that’s saying a lot! If you’re a Java developer, chances are you’re baffled by the pace of change in the JavaScript world. If you think Java is hard to keep up with, try keeping up with JavaScript and its ecosystem! The good news is there’s an excellent way to keep up with both: just use JHipster.
JHipster 6 uses Spring Boot 2.1 for its backend API, which means you can use Java 11+ to develop your JHipster apps!
JHipster is one of my favorite open source projects on the planet. It’s a development platform to generate, develop, and deploy Spring Boot + Angular applications. In addition, it supports React, Vue, and creating microservice architectures with Netflix OSS, the Elastic Stack, and Docker.
Java developers tend to dislike JavaScript, but many are OK with TypeScript. Guess what? JHipster uses TypeScript for all its UI framework implementations!
JHipster makes Java and JavaScript development easier by configuring everything for you and using the latest versions of its underlying frameworks. Want to upgrade your app to use the latest versions? Simply run jhipster upgrade
.
Before you worry about installing JHipster, install Java 11. I recommend using SDKMAN! for this task. If you don’t have it installed, it’s just a command away:
curl -s "https://get.sdkman.io" | bash
Once you have it installed, you can see all the Java 11 versions available using sdk list java
.
Install the OpenJDK version:
sdk install java 11.0.2-open
If you’d rather use Amazon’s Corretto, simply use 11.0.2-amzn
for the name. If you want to be as hipster as possible, you can even use Java 12!
sdk install java 12.0.0-open
Azul’s Zulu is also available if you use 12.0.0-zulu
for the name. |
A beta of JHipster 6 was released today. You can install it using the command below.
npm install -g generator-jhipster@beta
The npm
command is part of Node.js. You’ll need to have Node 10.x to install JHipster and run useful commands. |
The most basic way to get started with JHipster is to create a new directory, cd into it, and run jhipster
. You’ll be prompted to answer a number of questions about the app you’d like to create. Question range from the name of your app, to the authentication type you’d like to use, to SQL vs. NoSQL.
JHipster also has a domain language (called JDL for JHipster Domain Language) that you can use to define your app.
application { config {} }
If you used the above code to create your app, it’ll use the default values:
jhipster
monolith
sql
You can see all the default values in JHipster’s JDL documentation. |
To generate an OAuth 2.0-enabled app with JHipster, create an app.jh
file in a new project directory (e.g., ~/hipapp
):
application { config { baseName hipapp authenticationType oauth2 } }
Open a terminal window and navigate to the same directory as this file. Run the following command to generate a Spring Boot API with an Angular UI.
Make sure you’re not in your home directory! Your project will be generated in the same directory as app.jh
. |
jhipster import-jdl app.jh
This will create a multitude of files and install dependencies using npm install
. Your terminal should look similar to the following when you run this command:
If you’d prefer to see what this command looks line in-action, you can watch the recording below.
Since you specified oauth2
as the authentication type, a Docker Compose configuration will be installed for Keycloak.
Keycloak is an Apache-licensed open source identity and access management solution. In addition to creating a src/main/docker/keycloak.yml
file for Docker Compose, JHipster generates a src/main/docker/config/realm-config
directory with files in it that configure Keycloak to work with JHipster out-of-the-box.
Keycloak must be running for your JHipster app to start successfully. This is because Spring Security 5.1’s first-class OIDC support is leveraged in JHipster 6.
This OIDC support includes discovery, which means that Spring Security talks to a /.well-known/openid-configuration
endpoint to configure itself. I completed the migration myself and deleted more code than I added!
Start Keycloak using Docker Compose:
docker-compose -f src/main/docker/keycloak.yml up -d
If you don’t have Docker Compose installed, see these instructions for how to install it. |
Then start your application using Maven:
./mvnw
When your app is up and running, open [http://localhost:8080](http://localhost:8080)
in your favorite browser and click sign in. You’ll be redirected to Keycloak, where you can enter admin/admin
to log in.
Pretty slick, eh? You just created a modern single page application (SPA) that uses the latest released version of Angular! Not only that, but it uses the most secure form of OAuth 2.0 - authorization code flow.
| | If you’re confused by how OAuth 2.0 and OpenID Connect (OIDC) work together, please see What the Heck is OAuth? In short, OIDC is a thin layer on top of OAuth 2.0 that adds identity. |
Keycloak is an excellent project that works great for development and testing. However, if you use it in production, you’ll be responsible for maintaining it, updating it to the latest releases, and making sure it’s up 24/7. For these reasons, I recommend using Okta in production. After all, we’re always on! 😃
To begin, sign up for a forever-free Okta developer account (or sign in to {yourOktaDomain}
if you already have an account).
Once you’re signed in to Okta, register your client application.
Awesome OIDC
for the Name (this value doesn’t matter, so feel free to change it)[http://localhost:8080/login/oauth2/code/oidc](http://localhost:8080/login/oauth2/code/oidc)
[http://localhost:8080](http://localhost:8080)
as a Logout redirect URIYour settings should resemble the screenshot below when you’re finished.
Create an okta.env
file in your project’s root directory and replace the {..}
values with those from your Okta application:
export SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_OIDC_ISSUER_URI="https://{yourOktaDomain}/oauth2/default" export SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_ID="{clientId}" export SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_SECRET="{clientSecret}"
Add *.env
to your .gitignore
file so this file won’t end up in your source control system. |
JHipster is configured by default to work with two types of users: administrators and users. Keycloak is configured with users and groups automatically, but you need to do some one-time configuration for your Okta organization.
Create a ROLE_ADMIN
and ROLE_USER
group (Users > Groups > Add Group) and add users to them. You can use the account you signed up with, or create a new user (Users > Add Person). Navigate to API > Authorization Servers, and click on the the default
server. Click the Claims tab and Add Claim. Name it groups
, and include it in the ID Token. Set the value type to Groups
and set the filter to be a Regex of .*
. Click Create.
Start your application with the following commands:
source okta.env ./mvnw
Navigate to [http://localhost:8080](http://localhost:8080)
and log in with your Okta credentials.
Isn’t it cool how Spring Boot and Spring Security make it easy to switch OIDC providers?!
I’ve barely scratched the service of what JHipster is capable of in this post. For example, you can create CRUD functionality for entities (with tests!) using JDL. For example, create a blog.jh
file with the code below.
entity Blog { name String required minlength(3), handle String required minlength(2) }entity BlogEntry {
title String required,
content TextBlob required,
date Instant required
}entity Tag {
name String required minlength(2)
}relationship ManyToOne {
Blog{user(login)} to User,
BlogEntry{blog(name)} to Blog
}relationship ManyToMany {
BlogEntry{tag(name)} to Tag{entry}
}paginate BlogEntry, Tag with infinite-scroll
Then run jhipster import-jdl blog.jh
in your project. The jdl-samples GitHub repository has many more examples.
Thanks for reading ❤
If you liked this post, share it with all of your programming buddies!
Follow me on Facebook | Twitter
☞ Java Programming Masterclass for Software Developers
☞ Selenium WebDriver with Java -Basics to Advanced+Frameworks
☞ Java In-Depth: Become a Complete Java Engineer!
☞ JSP, Servlets and JDBC for Beginners: Build a Database App
☞ JSP, Servlet, JSLT + Hibernate: A complete guide
☞ Top 5 Java Test Frameworks for Automation in 2019
☞ Java Hibernate Tutorial for Beginners
☞ 50+ Java Interview Questions for Programmers
☞ Functional programming for Java developers
#java
1600135200
OpenJDk or Open Java Development Kit is a free, open-source framework of the Java Platform, Standard Edition (or Java SE). It contains the virtual machine, the Java Class Library, and the Java compiler. The difference between the Oracle OpenJDK and Oracle JDK is that OpenJDK is a source code reference point for the open-source model. Simultaneously, the Oracle JDK is a continuation or advanced model of the OpenJDK, which is not open source and requires a license to use.
In this article, we will be installing OpenJDK on Centos 8.
#tutorials #alternatives #centos #centos 8 #configuration #dnf #frameworks #java #java development kit #java ee #java environment variables #java framework #java jdk #java jre #java platform #java sdk #java se #jdk #jre #open java development kit #open source #openjdk #openjdk 11 #openjdk 8 #openjdk runtime environment
1620458875
According to some surveys, such as JetBrains’s great survey, Java 8 is currently the most used version of Java, despite being a 2014 release.
What you are reading is one in a series of articles titled ‘Going beyond Java 8,’ inspired by the contents of my book, Java for Aliens. These articles will guide you step-by-step through the most important features introduced to the language, starting from version 9. The aim is to make you aware of how important it is to move forward from Java 8, explaining the enormous advantages that the latest versions of the language offer.
In this article, we will talk about the most important new feature introduced with Java 10. Officially called local variable type inference, this feature is better known as the **introduction of the word **var
. Despite the complicated name, it is actually quite a simple feature to use. However, some observations need to be made before we can see the impact that the introduction of the word var
has on other pre-existing characteristics.
#java #java 11 #java 10 #java 12 #var #java 14 #java 13 #java 15 #verbosity
1620462686
On March 16th, 2021, Java 16 was GA. With this new release, tons of new exciting features have been added. Check out the release notes to know more about these changes in detail. This article’s focus will be on Java Records, which got delivered with JEP 395. Records were first introduced in JDK 14 as a preview feature proposed by JEP 359, and with JDK 15, they remained in preview with JEP 384. However, with JDK 16, Records are no longer in preview.
I have picked Records because they are definitely the most favored feature added in Java 16, according to this Twitter poll by Java Champion Mala Gupta.
I also conducted a similar survey, but it was focused on features from Java 8 onwards. The results were not unexpected, as Java 8 is still widely used. Very unfortunate, though, as tons of new features and improvements are added to newer Java versions. But in terms of features, Java 8 was definitely a game-changer from a developer perspective.
So let’s discuss what the fuss is about Java Records.
#java #springboot #java programming #records #java tutorials #java programmer #java records #java 16
1555303175
There’s a lot going on in the Java ecosystem lately. Now that major Java versions are released every six months, it can be difficult to keep up. Personally, I develop the majority of my Java applications using Spring Boot. Because of this, I was stuck on Java 8 until Spring Boot 2.1 was released last October.
Spring Boot 2.1 added Java 11 support, along with performance improvements, a new metrics implementation, new actuator endpoints, and Spring Security’s first-class OIDC support.
I was a web developer years before I became a Java developer. I’ve been developing Java for 20 years, so that’s saying a lot! If you’re a Java developer, chances are you’re baffled by the pace of change in the JavaScript world. If you think Java is hard to keep up with, try keeping up with JavaScript and its ecosystem! The good news is there’s an excellent way to keep up with both: just use JHipster.
JHipster 6 uses Spring Boot 2.1 for its backend API, which means you can use Java 11+ to develop your JHipster apps!
JHipster is one of my favorite open source projects on the planet. It’s a development platform to generate, develop, and deploy Spring Boot + Angular applications. In addition, it supports React, Vue, and creating microservice architectures with Netflix OSS, the Elastic Stack, and Docker.
Java developers tend to dislike JavaScript, but many are OK with TypeScript. Guess what? JHipster uses TypeScript for all its UI framework implementations!
JHipster makes Java and JavaScript development easier by configuring everything for you and using the latest versions of its underlying frameworks. Want to upgrade your app to use the latest versions? Simply run jhipster upgrade
.
Before you worry about installing JHipster, install Java 11. I recommend using SDKMAN! for this task. If you don’t have it installed, it’s just a command away:
curl -s "https://get.sdkman.io" | bash
Once you have it installed, you can see all the Java 11 versions available using sdk list java
.
Install the OpenJDK version:
sdk install java 11.0.2-open
If you’d rather use Amazon’s Corretto, simply use 11.0.2-amzn
for the name. If you want to be as hipster as possible, you can even use Java 12!
sdk install java 12.0.0-open
Azul’s Zulu is also available if you use 12.0.0-zulu
for the name. |
A beta of JHipster 6 was released today. You can install it using the command below.
npm install -g generator-jhipster@beta
The npm
command is part of Node.js. You’ll need to have Node 10.x to install JHipster and run useful commands. |
The most basic way to get started with JHipster is to create a new directory, cd into it, and run jhipster
. You’ll be prompted to answer a number of questions about the app you’d like to create. Question range from the name of your app, to the authentication type you’d like to use, to SQL vs. NoSQL.
JHipster also has a domain language (called JDL for JHipster Domain Language) that you can use to define your app.
application { config {} }
If you used the above code to create your app, it’ll use the default values:
jhipster
monolith
sql
You can see all the default values in JHipster’s JDL documentation. |
To generate an OAuth 2.0-enabled app with JHipster, create an app.jh
file in a new project directory (e.g., ~/hipapp
):
application { config { baseName hipapp authenticationType oauth2 } }
Open a terminal window and navigate to the same directory as this file. Run the following command to generate a Spring Boot API with an Angular UI.
Make sure you’re not in your home directory! Your project will be generated in the same directory as app.jh
. |
jhipster import-jdl app.jh
This will create a multitude of files and install dependencies using npm install
. Your terminal should look similar to the following when you run this command:
If you’d prefer to see what this command looks line in-action, you can watch the recording below.
Since you specified oauth2
as the authentication type, a Docker Compose configuration will be installed for Keycloak.
Keycloak is an Apache-licensed open source identity and access management solution. In addition to creating a src/main/docker/keycloak.yml
file for Docker Compose, JHipster generates a src/main/docker/config/realm-config
directory with files in it that configure Keycloak to work with JHipster out-of-the-box.
Keycloak must be running for your JHipster app to start successfully. This is because Spring Security 5.1’s first-class OIDC support is leveraged in JHipster 6.
This OIDC support includes discovery, which means that Spring Security talks to a /.well-known/openid-configuration
endpoint to configure itself. I completed the migration myself and deleted more code than I added!
Start Keycloak using Docker Compose:
docker-compose -f src/main/docker/keycloak.yml up -d
If you don’t have Docker Compose installed, see these instructions for how to install it. |
Then start your application using Maven:
./mvnw
When your app is up and running, open [http://localhost:8080](http://localhost:8080)
in your favorite browser and click sign in. You’ll be redirected to Keycloak, where you can enter admin/admin
to log in.
Pretty slick, eh? You just created a modern single page application (SPA) that uses the latest released version of Angular! Not only that, but it uses the most secure form of OAuth 2.0 - authorization code flow.
| | If you’re confused by how OAuth 2.0 and OpenID Connect (OIDC) work together, please see What the Heck is OAuth? In short, OIDC is a thin layer on top of OAuth 2.0 that adds identity. |
Keycloak is an excellent project that works great for development and testing. However, if you use it in production, you’ll be responsible for maintaining it, updating it to the latest releases, and making sure it’s up 24/7. For these reasons, I recommend using Okta in production. After all, we’re always on! 😃
To begin, sign up for a forever-free Okta developer account (or sign in to {yourOktaDomain}
if you already have an account).
Once you’re signed in to Okta, register your client application.
Awesome OIDC
for the Name (this value doesn’t matter, so feel free to change it)[http://localhost:8080/login/oauth2/code/oidc](http://localhost:8080/login/oauth2/code/oidc)
[http://localhost:8080](http://localhost:8080)
as a Logout redirect URIYour settings should resemble the screenshot below when you’re finished.
Create an okta.env
file in your project’s root directory and replace the {..}
values with those from your Okta application:
export SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_OIDC_ISSUER_URI="https://{yourOktaDomain}/oauth2/default" export SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_ID="{clientId}" export SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_SECRET="{clientSecret}"
Add *.env
to your .gitignore
file so this file won’t end up in your source control system. |
JHipster is configured by default to work with two types of users: administrators and users. Keycloak is configured with users and groups automatically, but you need to do some one-time configuration for your Okta organization.
Create a ROLE_ADMIN
and ROLE_USER
group (Users > Groups > Add Group) and add users to them. You can use the account you signed up with, or create a new user (Users > Add Person). Navigate to API > Authorization Servers, and click on the the default
server. Click the Claims tab and Add Claim. Name it groups
, and include it in the ID Token. Set the value type to Groups
and set the filter to be a Regex of .*
. Click Create.
Start your application with the following commands:
source okta.env ./mvnw
Navigate to [http://localhost:8080](http://localhost:8080)
and log in with your Okta credentials.
Isn’t it cool how Spring Boot and Spring Security make it easy to switch OIDC providers?!
I’ve barely scratched the service of what JHipster is capable of in this post. For example, you can create CRUD functionality for entities (with tests!) using JDL. For example, create a blog.jh
file with the code below.
entity Blog { name String required minlength(3), handle String required minlength(2) }entity BlogEntry {
title String required,
content TextBlob required,
date Instant required
}entity Tag {
name String required minlength(2)
}relationship ManyToOne {
Blog{user(login)} to User,
BlogEntry{blog(name)} to Blog
}relationship ManyToMany {
BlogEntry{tag(name)} to Tag{entry}
}paginate BlogEntry, Tag with infinite-scroll
Then run jhipster import-jdl blog.jh
in your project. The jdl-samples GitHub repository has many more examples.
Thanks for reading ❤
If you liked this post, share it with all of your programming buddies!
Follow me on Facebook | Twitter
☞ Java Programming Masterclass for Software Developers
☞ Selenium WebDriver with Java -Basics to Advanced+Frameworks
☞ Java In-Depth: Become a Complete Java Engineer!
☞ JSP, Servlets and JDBC for Beginners: Build a Database App
☞ JSP, Servlet, JSLT + Hibernate: A complete guide
☞ Top 5 Java Test Frameworks for Automation in 2019
☞ Java Hibernate Tutorial for Beginners
☞ 50+ Java Interview Questions for Programmers
☞ Functional programming for Java developers
#java
1602637135
Java is not the hardest language to start with. So, it becomes way popular among novice developers joining the ranks of Java coders every single day. If you are reading this blog post, you might be interested in learning Java.
Java is widely used across industry, and especially in the area of Enterprise software, which results in many high paying job opportunities and makes this programming language a common language for newbies. A general promotion of it within colleges and other institutions providing a formal Computer Science education also contributes to its popularity.
However, these are not the only advantages of Java — among other things, it allows you to adopt good practices and makes it way easier to learn other languages in the future. And with no doubt, you can easily learn it if you’re following the right approach. In this post, I am going to share some of them with you.
Beyond all doubt, practice is important and valuable. But, before we get to the advantages of hands-on experience, I want to draw your attention to one essential thing I often tell my students.
New programmers who are just learning and start implementing things, without being supervised, often end up adapting bad practices. To avoid that, especially when you are making your first steps in programming, I recommend looking for a person who will supervise you and teach you. A strong mentorship with someone engaged in a serious project, as well as communication within the community in the form of sharing code and asking for feedback, is worth the effort. Similarly, when you are applying for your first job, you want to be looking for a company with a strong team and a good leader who would be keen on investing into your learning.
Now, let’s return to practical experience. Learning by doing is different from learning by passively consuming the information. To make sure we can use all the newly acquired technology, we should put our skills to test and write tons of code. The benefits of hands-on experience are almost endless.
By practicing, you get a clear understanding of what programming is. Consequently, you start doing better with each new hands-on task, complete it faster, and thus become more productive.
Even if you are not working on real-world projects yet, it’s important to get used to having deadlines. They are inextricably linked to the programming process. My recommendation is to set up your own deadlines while practicing stage and follow them as closely as possible.
#java #learn java #java code #learn java in easy way #learn java course #learn java development