Castore  DeRose

Castore DeRose

1562553482

Explore MongoDB in a Java application for basic usage.

In day-to-day life in the industry, we have data to be saved and fetched from any persistence source. The persistence source can be SQL, NoSQL, or other types. MongoDB is a NoSQL database. Sometimes we need a small tool to look at data or delete data in MongoDB. For quick development, we need a solution/layer/UI that simplifies our task.

MongoDB holds data in the form of a document, so any data that needs to be stored has to be converted into a MongoDB Document, and it's a cumbersome task, in general. To make things easier, we need a helper/util java class. MongoDB Java framework provides a mechanism to implement the same. The following enum class helps to do so. Through this enum class, the data that exists in any POJO can be saved/queried/updated with ease. The enum class can fetch the MongoDB collection data with the default security mechanism.

public enum MongoUtility {
    INSTANCE;
    private final Map<String, MongoDatabase> databaseMap = new HashMap<>();
    private final CodecRegistry pojoCodecRegistry;
    private final MongoClient mongo;
    private MongoUtility() {
        pojoCodecRegistry = fromRegistries(MongoClient.getDefaultCodecRegistry(),
                fromProviders(PojoCodecProvider.builder().automatic(true).build()));
        mongo = new MongoClient();
    }
    public void closeMongoDB() {
        Optional.of(mongo).ifPresent(mongoInstance -> mongoInstance.close());
    }
    public MongoDatabase getDatabase(String database) {
        Optional<MongoDatabase> mongoDBOptional = Optional.ofNullable(databaseMap.get(database));
        return mongoDBOptional.orElseGet(createMongoDatabaseInstance(database));
    }
    private Supplier<MongoDatabase> createMongoDatabaseInstance(String database) {
        return () -> {
            MongoDatabase mongoDB = mongo.getDatabase(database);
            mongoDB = mongoDB.withCodecRegistry(pojoCodecRegistry);
            databaseMap.put(database, mongoDB);
            return mongoDB;
        };
    }
    public <T> MongoCollection<T> getBucket(String database, String bucket, Class<T> cls) {
        MongoDatabase mongoDB = getDatabase(database);
        return mongoDB.getCollection(bucket, cls);
    }
}

The above implementation can be achieved in Maven by putting the dependency in the pom.xml file.

<dependency>
  <groupId>org.mongodb</groupId>
  <artifactId>mongo-java-driver</artifactId>
  <version>3.10.2</version>
</dependency>

So, the framework can get things done with the least amount of effort.

Thanks for reading. If you liked this post, share it with all of your programming buddies!

Originally published on https://dzone.com

#mongodb #java #web-development

What is GEEK

Buddha Community

Explore MongoDB in a Java application for basic usage.
Tyrique  Littel

Tyrique Littel

1600135200

How to Install OpenJDK 11 on CentOS 8

What is OpenJDK?

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

Joseph  Murray

Joseph Murray

1623302550

Top 5 Java Web Application Technologies You Should Master in 2021

Web Development in Java

Java is a commonly used language for web development, especially on the server-side. Java web applications are distributed applications that run on the internet. Web development with Java allows us to create dynamic web pages where users can interact with the interface.

There are various ways through which you can create dynamic web pages in Java. The Java EE (Enterprise Edition) platform provides various Java technologies for web development to developers. Services like distributed computing, web services, etc. are provided by Java EE. Applications can be developed in Java without using any additional scripting language. Let us see how web applications are made via Java.

**Java Web Application **

Java Web Application Technologies

#software development #java #java web applications #web applications #java web application technologies #top 5 java web application technologies you should master

Java Development Company in USA | Java Application Development Company

Large enterprises usually have unique requirements for their website and mobile app development and there can be no better technology to fulfil that requirement than Java Development. Java can add that unique element to your development and make it stand out among competitors.

Want to develop a unique website or mobile app with Java?

WebClues Infotech with its highly skilled team and updated with the latest technology is the way to go for your development needs as there can be no one better to work in Java. After successfully delivering 1500+ projects we are ready to serve you with our expertise in Web & Mobile App Development.

Want to know more about our Java Development Service?

Visit: https://www.webcluesinfotech.com/java-development/

Share your requirements https://www.webcluesinfotech.com/contact-us/

View Portfolio https://www.webcluesinfotech.com/portfolio/

#java development company in usa #java application development company #java development company #java application development #java software development company #hire java developers

Samanta  Moore

Samanta Moore

1620458875

Going Beyond Java 8: Local Variable Type Inference (var) - DZone Java

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

Joseph  Murray

Joseph Murray

1624047480

Keeping Your Java Applications Secure

Java security is an important topic for all businesses that use Java applications. Java Champion Simon Ritter takes a deep dive into the JDK and the potential shortcomings of not keeping your applications up to date, as well as why it’s essential to know the difference between critical patch updates (CPUs) and patch set updates (PSUs).

A little over a year ago, in April 2019, the way most Java users accessed updates for the JDK changed. The reason for this was a combination of changes made by Oracle to how the JDK is developed and the licensing terms of the Oracle JDK.

The Oracle JDK 11 and Oracle JDK 8 (from update 211) now use the Oracle Technology Network License Agreement. This limits free use to only four cases:

  1. Personal use (laptop or desktop for personal applications)
  2. Development use
  3. Oracle approved product use
  4. Oracle cloud infrastructure use

For all other cases, a Java SE subscription must be purchased from Oracle.

**SEE ALSO: **Type-safe Unit Expressions for Java (and you)

This has required users to make decisions about their JDK deployment strategy. One such approach is “well, it works fine on the JDK we have now; let’s just stick with that”.

There is an obvious flaw to this, which is the effect this decision will have on the security of applications.

Ever since people started developing software, other people have been trying to find ways to use it in ways not originally intended. This is often for malicious goals such as stealing credit card numbers or user’s identities. We use the term hacker to describe someone who is able to subvert computer security. There are a myriad of ways that hackers use to achieve their goals; from fooling people into revealing confidential information (phishing) to sophisticated manipulation of software through techniques like buffer overruns.

Unfortunately, the more complex a piece of software, the more likely there is to be a vulnerability that hackers can exploit. The JDK is a very complex piece of software and, as such, may contain vulnerabilities.

As vulnerabilities in software are discovered, they are normally recorded as a Common Vulnerability and Exposure (CVE). The National Cybersecurity FFRDC, operated by the Mitre Corporation, maintains the CVE database. Each CVE, identified by a unique number, has a textual description of the vulnerability.

#articles #java #keeping your java applications secure #java applications #java applications secure