Skip to content

Instantly share code, notes, and snippets.

View 2013techsmarts's full-sized avatar

Siva Prasad Rao Janapati 2013techsmarts

View GitHub Profile
@2013techsmarts
2013techsmarts / jshell-2
Created February 15, 2017 16:43
Create a class with method via jshell and invoke the method
jshell> public class Sample {
...> public int add(int a, int b) {
...> return a+b;
...> }
...> }
| created class Sample
jshell> Sample s = new Sample();
s ==> Sample@49993335
jshell> s.add(10,9);
@2013techsmarts
2013techsmarts / jshell-3
Created February 15, 2017 16:48
Create a class with static method and use java API with imports using jshell
jshell> public class Sample {
...> public static void join() {
...> StringBuilder sb = new StringBuilder();
...> sb.append("Smart").append(" ").append("Techie");
...> System.out.println("The string is " + sb.toString());
...> }
...> }
| created class Sample
jshell> Sample.join();
@2013techsmarts
2013techsmarts / Collections.unmodifiableList
Last active February 15, 2017 17:11
Demonstration of Collections.unmodifiableList method
jshell> List<String> list = new ArrayList<String>();
list ==> []
jshell> list.add("Smart");
$2 ==> true
jshell> list.add("Techie");
$3 ==> true
jshell> System.out.println("The list values are: "+ list);
@2013techsmarts
2013techsmarts / Immutable Empty List
Created February 15, 2017 17:17
Demonstration of Immutable empty list
jshell> List immutableList = List.of();
immutableList ==> []
//Add an item to the list
jshell> immutableList.add("Smart");
| Warning:
| unchecked call to add(E) as a member of the raw type java.util.List
| immutableList.add("Smart");
| ^------------------------^
| java.lang.UnsupportedOperationException thrown:
@2013techsmarts
2013techsmarts / Non-Empty Immutable List
Last active February 22, 2017 05:03
Demonstration of Non-Empty immutable list
jshell> List immutableList = List.of("Smart","Techie");
immutableList ==> [Smart, Techie]
jshell> //add an item to the list
jshell> immutableList.add("Smart_1");
| Warning:
| unchecked call to add(E) as a member of the raw type java.util.List
| immutableList.add("Smart_1");
| ^--------------------------^
@2013techsmarts
2013techsmarts / Non-Empty Immutable Map
Last active February 15, 2017 17:24
Demonstration of Immutable Map
jshell> Map immutableMap = Map.of(1,"Smart",2,"Techie");
immutableMap ==> {1=Smart, 2=Techie}
//Get item from Map
jshell> immutableMap.get(1);
$2 ==> "Smart"
//Add item to map
jshell> immutableMap.put(3,"Smart_1");
| Warning:
@2013techsmarts
2013techsmarts / Interface Private methods
Created February 15, 2017 17:52
Demonstration of private methods in Interfaces - Java 9 feature
jshell> public interface Sample {
...> default void doSomeThing(String message) {
...> //Call private method
...> doSomeThing();
...> System.out.println("The deafult interface method!!!");
...>
...> }
...>
...> private void doSomeThing() {
...> System.out.println("Demonstration of interface private methods!!!");
@2013techsmarts
2013techsmarts / private method error scenarios
Created February 15, 2017 18:07
Demonstration of private method error scenarios
jshell> public interface Sample {
...>
...> private void doSomeThing();
...>
...> }
| Error:
| missing method body, or declare abstract
| private void doSomeThing();
| ^-------------------------^
@2013techsmarts
2013techsmarts / Spring Boot Admin Server Dependencies
Last active June 18, 2017 04:55
Maven Dependencies for Spring Boot Admin Server
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
<version>1.5.1</version>
</dependency>
@2013techsmarts
2013techsmarts / Spring Boot Admin Server
Created June 18, 2017 04:45
Spring Boot Admin Server Configuration
package org.samrttechie;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import de.codecentric.boot.admin.config.EnableAdminServer;