Posts

Showing posts from 2021

How to find total Memory, free Memory and max Memory from Java Runtime?

In this post, we will see how to find total Memory, free Memory and max Memory from Java Runtime. Here, we will use Runtime class to get this information. Every Java application has a single instance of class Runtime that allows the application to interface with the environment in which the application is running. The current runtime can be obtained from the getRuntime method. An application cannot create its own instance of this class. package basics ; import java.util.ArrayList ; import java.util.List ; public class MainApp { public static void main ( String [] args ) { Runtime runtime = Runtime . getRuntime (); System . out . println ( "runtime.totalMemory " + runtime . totalMemory ()); System . out . println ( "runtime.freeMemory " + runtime . freeMemory ()); System . out . println ( "runtime.maxMemory " + runtime . maxMemory ()); runtime . gc (); long m1 = runtime . freeMemory (); List < Strin...

How To Run Mongodb In Docker With Username and Password | Java Inspires

Image
How To Run Mongodb In Docker With Username and Password | Java Inspires In this post, we will see how to run mongodb in docker with username and password. First we will run without username and password. Command: $ docker run --name local-mongo -p 27017:27017 -d mongo Connect to DB using Robo3T Stop and remove container $ docker container ls $ docker container stop <containerId> $ docker container rm <containerId> Run mongo with username and password. Command: $ docker run --name local-mongo -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=password -d mongo Connect to DB using Robo3T Thats it .... THANK YOU... Power Shell Log: Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. Try the new cross-platform PowerShell https : //aka.ms/pscore6 PS C : \Users\developer> docker images REPOSITORY TAG IMAGE ID CREATED SIZE mongo latest 4253856b2570 2 weeks ago 701MB PS C : \User...

How To Convert LinkedList Object To Array Object In Java ?

In this post, we will see the code example to convert LinkedList Object to Array Object. Here, we will create a LinkedList of String type and then we convert to Array of String type :: String[]. package java8examples ; import java.util.Arrays ; import java.util.LinkedList ; /** * * @author #JavaInspires * */ public class Java8Example { public static void main ( String [] args ) { // Create a LinkedList of String LinkedList < String > linkedList = new LinkedList < String >(); // Add some elements to linkedList linkedList . add ( "Java" ); linkedList . add ( "Python" ); linkedList . add ( "Go" ); linkedList . add ( "Kotlin" ); linkedList . add ( "Scala" ); linkedList . add ( "Groovy" ); // Print linkedList System . out . println ( "Linked List" ); System . out . println ( linkedList ); // Convert LinkedList to Array Object [...

How to deploy mongodb image in docker? Connect to DB using ROBO3T.

Image
In this post, we will see How to deploy mongodb image in docker? and Connect to DB using ROBO3T. Open PowerShell 1, Check whether mongo image is there or not. $ docker image inspect mongo 2, Pull mongodb latest image from docker $ docker pull mongo:latest $ docker image ls 3, Run mongo image in detached mode on port 27017. $ docker run --name local-mongo -p 27017:27017 -d mongo 4, Check running containers. $ docker container ls 5, Open Mongo container logs. $  docker container logs <containerId> -f 6, Open Robo3T and connect to localhost:20172. 7, Stop running container. $ docker container stop <containerId> 8, Remove stopped container. $ docker container ls -a $ docker container rm <containerId> 9, Delete mongo image. $ docker image ls $ docker image rm -f <ImageId> 10, Check whether mongo image is there or not $ docker image inspect mongo Log: Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. Try the new cross-platform Po...