Change Project Explorer tree view font size in Eclipse
Window > Preferences > General > Appearance > Colors and Fonts > View and Editor Folders > Tree and Table font for views
Window > Preferences > General > Appearance > Colors and Fonts > View and Editor Folders > Tree and Table font for views
del /F /S /Q /A .git
rmdir .git
rm -rf .git
rm -rf .gitkeep
rm -rf .gitignore
rm -rf .gitattributes
find . | grep -i .git
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
server.port=8761
##Eureka Related
eureka.client.serviceUrl.defaultZone=http://127.0.0.1:8761/eureka/
eureka.client.healthcheck.enabled=true
package com.bootng.service;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer
@SpringBootApplication
public class ServiceDiscovery {
public static void main(String[] args) {
SpringApplication.run(ServiceDiscovery.class, args);
}
}
Discovery Service UI |
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
## Server Related
server.port=9051
## Eureka Related
eureka.client.serviceUrl.defaultZone=http://127.0.0.1:8761/eureka/
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=false
eureka.vipAddress=article-service
spring.application.name=article-service
@ComponentScan({ "com.siddb" })
@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
public class ArticleMicroservice {
public static void main(String args[]) {
SpringApplication.run(ArticleMicroservice.class, args);
}
}
@RestController
@RequestMapping("/api")
public class ArticleController {
private static final Logger log = LoggerFactory.getLogger(ArticleController.class);
@Autowired
ArticleService articleService;
@RequestMapping(value = {"/articles"}, method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Article>> getArticles() throws AppException {
List<Article> articles = articleService.getArticles();
return new ResponseEntity<List<Article>>(articles, HttpStatus.OK);
}
@RequestMapping(value = {"/articles/{id}"}, method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Article> getArticle(@PathVariable(value = "") String id)
throws AppException, NotFoundException {
Article articles = articleService.getByID(id);
return new ResponseEntity<Article>(articles, HttpStatus.OK);
}
//other methods for POST and Deleted removed from here for readability.
}
[
{
"id": "America-Travel",
"name": "America Travel",
"description": "Places to travel in AmericaLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum",
"category": "Travel"
}
]
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<!--ribbon related -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
hostname=localhost
logging.level.org.springframework=info
logging.level.root=info
spring.main.banner-mode=off
server.port=9053
##Management
management.endpoint.health.show-details
management.health.key.ping=enabled
management.endpoints.web.exposure.include=info,health,mappings
##Eureka Related
eureka.instance.leaseRenewalIntervalInSeconds=1
eureka.instance.leaseExpirationDurationInSeconds=90
eureka.instance.hostname=${hostname}
eureka.instance.hostname.metadataMap.instanceId=${spring.application.name}:${server.port}
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.serviceUrl.defaultZone=http://127.0.0.1:8761/eureka/
eureka.client.healthcheck.enabled=true
##Eureka Ribbon
article-service-consumer.ribbon.NIWSServerListClassName=com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList
article-service-consumer.ribbon.DeploymentContextBasedVipAddresses=article-service
@ComponentScan({"com.siddb", "com.siddb.controller"})
@SpringBootApplication
@EnableDiscoveryClient
public class ConsumerApplication {
public static void main(String args[]) {
SpringApplication.run(ConsumerApplication.class, args);
}
}
@RestController
public class RibbonController {
@Autowired
private RestTemplate restTemplate;
/**
* This method calls the microservice GET article-service/api/articles using Ribbon to get a list of
* Articles and returns the same. it uses RestTemplate to make the API calls.
* @return
* @throws Exception
*/
@RequestMapping(value = {"render"}, method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> renderArticles() throws Exception {
JsonNode repos =
restTemplate.getForObject("http://article-service-consumer/api/articles", JsonNode.class);
int counter = 1;
StringBuilder result = new StringBuilder("\n List of Articles");
if (repos.isArray()) {
for (JsonNode jsonNode : repos) {
result.append("\n Repo ").append(counter++).append("::");
result.append(jsonNode.get("name").asText());
}
}
return new ResponseEntity<String>(result.toString(), HttpStatus.OK);
}
}
Discovery Server UI with all services running |
private static String toBinary1(Integer i) {
return Integer.toBinaryString(i);
}
private static String toBinary2(Integer i) {
return Integer.toString(i, 2);
}
private static String toBinary2(Integer i) {
BigInteger bigInt = new BigInteger(String.valueOf(i));
return bigInt.toString(2);
}
private static String toBinary_divide(Integer i) {
StringBuilder ret = new StringBuilder();
while (i > 0) {
if (i % 2 == 1) {
ret.insert(0, "1");
}
else {
ret.insert(0, "0");
}
i = i / 2;
}
return ret.toString();
}
private static String toBinary_mask(Integer num) {
char ret[] = new char[32];
for (int i = 0; i < 32; i++) {
int mask = 1 << i;
ret[31 - i] = (num & mask) != 0 ? '1' : '0';
}
return new String(ret);
}
import java.math.BigInteger;
public class IntegerToBinaryConverter {
public static void main(String[] args) {
System.out.println("Convert to Binary 2020 = " + toBinary1(2020));
System.out.println("Convert to Binary 2020 = " + toBinary2(2020));
System.out.println("Convert to Binary 2020 = " + toBinary3(2020));
System.out.println("Convert to Binary 2020 = " + toBinary_divide(2020));
System.out.println("Convert to Binary 2020 = " + toBinary_mask(2020));
}
private static String toBinary1(Integer i) {
return Integer.toBinaryString(i);
}
private static String toBinary2(Integer i) {
return Integer.toString(i, 2);
}
private static String toBinary3(Integer i) {
BigInteger bigInt = new BigInteger(String.valueOf(i));
return bigInt.toString(2);
}
private static String toBinary_divide(Integer i) {
StringBuilder ret = new StringBuilder();
while (i > 0) {
if (i % 2 == 1) {
ret.insert(0, "1");
}
else {
ret.insert(0, "0");
}
i = i / 2;
}
return ret.toString();
}
private static String toBinary_mask(Integer num) {
char ret[] = new char[32];
for (int i = 0; i < 32; i++) {
int mask = 1 << i;
ret[31 - i] = (num & mask) != 0 ? '1' : '0';
}
return new String(ret);
}
}
var b1 = new Boolean();
console.log(b1); //false
var b2 = new Boolean(false);
console.log(b2);//false
var b3 = new Boolean(0);
console.log(b3);//false
var b4 = new Boolean(NaN);
console.log(b4);//false
var b5 = new Boolean(undefined);
console.log(b5);//false
var b6 = new Boolean(null);
console.log(b6); //false
var b7 = new Boolean({});
console.log(b7);//true
var b8 = new Boolean(true);
console.log(b8);//true
var b9 = new Boolean([]);
console.log(b9);//true
var n1 = null;
console.log(n1); //null
console.log(typeof n1); //object
var u1 ;
console.log(typeof u1);//undefined
console.log(u1);//undefined
const string1 = "A string primitive";
const string2 = new String("A String object");
console.log(typeof string1); //string
console.log(typeof string2); //object
console.log(typeof string2.valueOf());//string
console.log(Number.MAX_VALUE); //1.7976931348623157e+308
console.log(Number.MIN_VALUE); //5e-324
console.log(1/0); //Infinity
const xbig = 2n ** 53n;
console.log(xbig); //9007199254740992n
let sym1 = Symbol()
let sym2 = Symbol('foo')
let sym3 = Symbol('foo')
var o1 = {};
console.log(typeof o1);//object
var f1 = function () {};
console.log(typeof f1);//fuction
Symbol | Number |
---|---|
I | 1 |
V | 5 |
X | 10 |
L | 50 |
C | 100 |
D | 500 |
M | 1,000 |
/**
* I can be placed before V or X
*
* X can be placed before L or C
*
* C can be placed before D or M
*
*
*/
public static String convertToRomanNumber(int num) {
int number[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
String roman[] = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
StringBuilder result = new StringBuilder();
for (int i = 0; i < number.length; i++) {
while (num >= number[i]) {
num = num - number[i];
result = result.append(roman[i]);
}
}
return result.toString();
}
class Print {
int max;
public Print(int max) {
this.max = max;
}
public synchronized void even() throws InterruptedException {
for (int i = 0; i <= max; i++) {
notifyAll();
if (i % 2 == 0)
System.out.println(Thread.currentThread().getName() + ":: " + i);
wait();
}
}
public synchronized void odd() throws InterruptedException {
for (int i = 0; i <= max; i++) {
notifyAll();
if (i % 2 != 0)
System.out.println(Thread.currentThread().getName() + ":: " + i);
wait();
}
}
}
Print print = new Print(10);
//Thread to print even numbers
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
try {
print.even();
} catch (InterruptedException e) {
}
}
});
//Thread to print odd numbers
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
try {
print.odd();
} catch (InterruptedException e) {
}
}
});
t1.setName("Even Thread");
t2.setName(" Odd Thread");
t1.start();
t2.start();
[ 1 2 3 ]
[ 4 5 6 ]
[ 7 8 9 ]
[ 1 4 7 ]
[ 2 5 8 ]
[ 3 6 9 ]
public void rotateMatrixRight90Transpose(int[][] mat) {
int m = mat.length;
int n = mat[0].length;
for (int i = 0; i < m; i++) {
for (int j = i; j < n; j++) {
int x = mat[i][j];
mat[i][j] = mat[j][i];
mat[j][i] = x;
System.out.println("IC" + i + ":" + j);
}
}
// swap cols
for (int i = 0; i < m; i++) {
for (int j = 0; j < n / 2; j++) {
// swap mat[i][j] with mat[N-i-1][j]
int temp = mat[i][j];
mat[i][j] = mat[i][n - j - 1];
mat[i][n - j - 1] = temp;
}
}
}
Matrix Rotation with Transpose
<= Original Matrix =>
[ 1 2 3 ]
[ 4 5 6 ]
[ 7 8 9 ]
<= After Transpose =>
[ 1 4 7 ]
[ 2 5 8 ]
[ 3 6 9 ]
<= After Rotation =>
[ 7 4 1 ]
[ 8 5 2 ]
[ 9 6 3 ]
public void rotate(int[][] matrix) {
int n = matrix.length;
for (int i = 0; i < (n + 1) / 2; i++) {
for (int j = 0; j < n / 2; j++) {
int temp = matrix[n - 1 - j][i];
matrix[n - 1 - j][i] = matrix[n - 1 - i][n - j - 1];
matrix[n - 1 - i][n - j - 1] = matrix[j][n - 1 - i];
matrix[j][n - 1 - i] = matrix[i][j];
matrix[i][j] = temp;
}
}
}
Matrix Rotation with single pass
<= Original Matrix =>
[ 1 2 3 ]
[ 4 5 6 ]
[ 7 8 9 ]
<= After Rotation =>
[ 7 4 1 ]
[ 8 5 2 ]
[ 9 6 3 ]
package com.bootng.display;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
public class DisplayCustomNameTest {
@Test
public void test_if_it_will_rain() {
}
@Test
public void test_if_it_will_be_cloudy() {
}
@Test
public void test_if_it_will_be_sunny() {
}
}
package com.bootng.display;
@DisplayName("Vacation Weather Test")
public class DisplayCustNameTest {
@DisplayName("🌧")
@Test
public void test_if_it_will_rain() {
}
@DisplayName("🌨")
@Test
public void test_if_it_will_be_cloudy() {
}
@DisplayName("🌞")
@Test
public void test_if_it_will_be_sunny() {
}
}
package com.bootng.display;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@DisplayName("Weather Test DisplayExample ")
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
public class DisplayGeneratorExampleTest {
@Test
public void test_if_it_will_rain() {
}
@Test
public void test_if_it_will_be_cloudy() {
}
@Test
public void test_if_it_will_be_sunny() {
}
}