Kuby Block

Blog about programming, tech, society and more.

Category
javascript
(6 posts)

Optional Parameters in Programing

Optional parameters is the way for using method without required full all parameters in definition of method. It will be useful when using method in different contexts. Java In Java, we have two kinds of optional parameter of method: Overload methods Rest parameters Java: Overload methods In three methods below, we have different parameters for each method with the same method name: imp...

Overload in JavaScript

Overload is an interesting feature, with the same method name, we can use it in different cases. As a previous post, I have told about overloading vs overiding in OOP. But in JavaScript, overload does not exist. Simple case: function fn(x) { console.log("function with one parameter"); } function fn(x, y) { console.log("function with two parameters"); } Invoke it: fn(1); // Output: functi...

Call function with the specified parameter number

In javascript, there are some situation we only want to call a function with one, two or three parameter(s), but input of it maybe there are a lot of parameters. For example, we want to repeat every element in array one time: const data = [2, 11, 6, 10]; // expected [22, 1111, 66, 1010] What will you do? Simplest, we can do: const data = [2, 11, 6, 10]; data.map(el => el.toString()).ma...

Invoke a function and some more

Declare a function Declare a function to use in this post function info(firstname, lastname, age){ console.log(firstname); console.log(lastname); console.log(age); } Popular way As you know, we can invoke a function with syntax function_name(arg1, arg2). In our example, it will be: info("Rick", "Thomas", 30); // Output: // Rick // Thomas // 30 What happen if we leave empty the final argu...

Differences of variable declarations in javascript

Variable declaration ways: Along with the developer of javascript each year, the variable declaration has also made new improvements. var : the traditional variable declaration. let : the variable declaration from ES5. const : the variable declaration from ES5, immutable value. No keyword declaration. Difference between var and let: Declaring variables with var is a fairly arbitrary ...

Let's talk

Implement an discussion In a room, there are several people - Person. Each person has some attributes and stands next to others, in a coutinuous row: class Person { #name = ""; #gender = "M"; #age = 0; #messages = []; #nextPerson = null; constructor({ name, gender, age, messages }) { this.#name = name; this.#gender = gender; this.#age = age; this.#messages = mess...

Category
oop
(1 posts)

Let's talk

Implement an discussion In a room, there are several people - Person. Each person has some attributes and stands next to others, in a coutinuous row: class Person { #name = ""; #gender = "M"; #age = 0; #messages = []; #nextPerson = null; constructor({ name, gender, age, messages }) { this.#name = name; this.#gender = gender; this.#age = age; this.#messages = mess...

Category
variable
(1 posts)

Differences of variable declarations in javascript

Variable declaration ways: Along with the developer of javascript each year, the variable declaration has also made new improvements. var : the traditional variable declaration. let : the variable declaration from ES5. const : the variable declaration from ES5, immutable value. No keyword declaration. Difference between var and let: Declaring variables with var is a fairly arbitrary ...

Category
invoke
(1 posts)

Invoke a function and some more

Declare a function Declare a function to use in this post function info(firstname, lastname, age){ console.log(firstname); console.log(lastname); console.log(age); } Popular way As you know, we can invoke a function with syntax function_name(arg1, arg2). In our example, it will be: info("Rick", "Thomas", 30); // Output: // Rick // Thomas // 30 What happen if we leave empty the final argu...

Category
function
(3 posts)

Overload in JavaScript

Overload is an interesting feature, with the same method name, we can use it in different cases. As a previous post, I have told about overloading vs overiding in OOP. But in JavaScript, overload does not exist. Simple case: function fn(x) { console.log("function with one parameter"); } function fn(x, y) { console.log("function with two parameters"); } Invoke it: fn(1); // Output: functi...

Call function with the specified parameter number

In javascript, there are some situation we only want to call a function with one, two or three parameter(s), but input of it maybe there are a lot of parameters. For example, we want to repeat every element in array one time: const data = [2, 11, 6, 10]; // expected [22, 1111, 66, 1010] What will you do? Simplest, we can do: const data = [2, 11, 6, 10]; data.map(el => el.toString()).ma...

Invoke a function and some more

Declare a function Declare a function to use in this post function info(firstname, lastname, age){ console.log(firstname); console.log(lastname); console.log(age); } Popular way As you know, we can invoke a function with syntax function_name(arg1, arg2). In our example, it will be: info("Rick", "Thomas", 30); // Output: // Rick // Thomas // 30 What happen if we leave empty the final argu...

Category
java
(7 posts)

Manually to create LDAP authentication provider

Have you ever want to create a custom login flow with composite of ldap and other authentication? But you relize that, LDAP almost use integrated with Spring security? And you would like to use it seperatedly, yes, me too and now I will share you the way I have used. 1. Use class DefaultSpringSecurityContextSource to create LDAP context source. It is a little weird that we will use DefaultSpring...

Optional Parameters in Programing

Optional parameters is the way for using method without required full all parameters in definition of method. It will be useful when using method in different contexts. Java In Java, we have two kinds of optional parameter of method: Overload methods Rest parameters Java: Overload methods In three methods below, we have different parameters for each method with the same method name: imp...

Be careful when using Scanner in Java

To interact with a java application in command line, Scanner is one of the most popular way to implement. But you know, it also has a mistake that we may easily make. First, let use it in a simple program: import java.util.Scanner; public class Main { private static String inputString() { final Scanner scanner = new Scanner(System.in); String result = ""; if (scanner.hasNextLine...

Primitive type in java

Definition: Any data-type built-into a programing language is called primitive data type. Basic behavior of a primitive data type itself, however, cannot be changed. There are 8 primitive data types in java. They are as follow: 1. byte byte: The byte data type is an 8-bit signed two’s complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type ...

Mess with polymorphism

Definition: Polymorphism is one of four main concepts of Object Oriented Programming (OOP). In common, a parent interface defines common methods, then will be specify by children class. So although they have the same type, but each specific entity will do a method with different ways. How to implement: overloading overriding We have some scenarios: We have some method with the same name...

Overloading versus Overriding

Overloading and overriding are two important concepts, not only in java language but in programming too. Definitions Overloading is concept about the methods have the same method name but different parameters. It is not just in class (Object Oriented Programming - OOP), but in any programing language. Overriding is concept about the methods have the same method name and parameters as well. ...

Package class files to jar library file

Reuse java classes When programming, reuse a class, a module or a method is not rarely. If it simple and short, we can rewrite it, or copy it. But it is long and complex, we couldn’t spend a lot of time to rewrite a class - which we have written before. We can copy the whole files from this project to another project, but it will be bulky and raise some issues how to put it in. That is, we can do ...

Category
package
(1 posts)

Package class files to jar library file

Reuse java classes When programming, reuse a class, a module or a method is not rarely. If it simple and short, we can rewrite it, or copy it. But it is long and complex, we couldn’t spend a lot of time to rewrite a class - which we have written before. We can copy the whole files from this project to another project, but it will be bulky and raise some issues how to put it in. That is, we can do ...

Category
jar
(1 posts)

Package class files to jar library file

Reuse java classes When programming, reuse a class, a module or a method is not rarely. If it simple and short, we can rewrite it, or copy it. But it is long and complex, we couldn’t spend a lot of time to rewrite a class - which we have written before. We can copy the whole files from this project to another project, but it will be bulky and raise some issues how to put it in. That is, we can do ...

Category
class
(1 posts)

Package class files to jar library file

Reuse java classes When programming, reuse a class, a module or a method is not rarely. If it simple and short, we can rewrite it, or copy it. But it is long and complex, we couldn’t spend a lot of time to rewrite a class - which we have written before. We can copy the whole files from this project to another project, but it will be bulky and raise some issues how to put it in. That is, we can do ...

Category
library
(1 posts)

Package class files to jar library file

Reuse java classes When programming, reuse a class, a module or a method is not rarely. If it simple and short, we can rewrite it, or copy it. But it is long and complex, we couldn’t spend a lot of time to rewrite a class - which we have written before. We can copy the whole files from this project to another project, but it will be bulky and raise some issues how to put it in. That is, we can do ...

Category
method
(3 posts)

Optional Parameters in Programing

Optional parameters is the way for using method without required full all parameters in definition of method. It will be useful when using method in different contexts. Java In Java, we have two kinds of optional parameter of method: Overload methods Rest parameters Java: Overload methods In three methods below, we have different parameters for each method with the same method name: imp...

Mess with polymorphism

Definition: Polymorphism is one of four main concepts of Object Oriented Programming (OOP). In common, a parent interface defines common methods, then will be specify by children class. So although they have the same type, but each specific entity will do a method with different ways. How to implement: overloading overriding We have some scenarios: We have some method with the same name...

Overloading versus Overriding

Overloading and overriding are two important concepts, not only in java language but in programming too. Definitions Overloading is concept about the methods have the same method name but different parameters. It is not just in class (Object Oriented Programming - OOP), but in any programing language. Overriding is concept about the methods have the same method name and parameters as well. ...

Category
overload
(3 posts)

Overload in JavaScript

Overload is an interesting feature, with the same method name, we can use it in different cases. As a previous post, I have told about overloading vs overiding in OOP. But in JavaScript, overload does not exist. Simple case: function fn(x) { console.log("function with one parameter"); } function fn(x, y) { console.log("function with two parameters"); } Invoke it: fn(1); // Output: functi...

Mess with polymorphism

Definition: Polymorphism is one of four main concepts of Object Oriented Programming (OOP). In common, a parent interface defines common methods, then will be specify by children class. So although they have the same type, but each specific entity will do a method with different ways. How to implement: overloading overriding We have some scenarios: We have some method with the same name...

Overloading versus Overriding

Overloading and overriding are two important concepts, not only in java language but in programming too. Definitions Overloading is concept about the methods have the same method name but different parameters. It is not just in class (Object Oriented Programming - OOP), but in any programing language. Overriding is concept about the methods have the same method name and parameters as well. ...

Category
override
(2 posts)

Mess with polymorphism

Definition: Polymorphism is one of four main concepts of Object Oriented Programming (OOP). In common, a parent interface defines common methods, then will be specify by children class. So although they have the same type, but each specific entity will do a method with different ways. How to implement: overloading overriding We have some scenarios: We have some method with the same name...

Overloading versus Overriding

Overloading and overriding are two important concepts, not only in java language but in programming too. Definitions Overloading is concept about the methods have the same method name but different parameters. It is not just in class (Object Oriented Programming - OOP), but in any programing language. Overriding is concept about the methods have the same method name and parameters as well. ...

Category
polymorphism
(1 posts)

Mess with polymorphism

Definition: Polymorphism is one of four main concepts of Object Oriented Programming (OOP). In common, a parent interface defines common methods, then will be specify by children class. So although they have the same type, but each specific entity will do a method with different ways. How to implement: overloading overriding We have some scenarios: We have some method with the same name...

Category
data-type
(1 posts)

Primitive type in java

Definition: Any data-type built-into a programing language is called primitive data type. Basic behavior of a primitive data type itself, however, cannot be changed. There are 8 primitive data types in java. They are as follow: 1. byte byte: The byte data type is an 8-bit signed two’s complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type ...

Category
primitive
(1 posts)

Primitive type in java

Definition: Any data-type built-into a programing language is called primitive data type. Basic behavior of a primitive data type itself, however, cannot be changed. There are 8 primitive data types in java. They are as follow: 1. byte byte: The byte data type is an 8-bit signed two’s complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type ...

Category
input
(2 posts)

Be careful when using Scanner in Java

To interact with a java application in command line, Scanner is one of the most popular way to implement. But you know, it also has a mistake that we may easily make. First, let use it in a simple program: import java.util.Scanner; public class Main { private static String inputString() { final Scanner scanner = new Scanner(System.in); String result = ""; if (scanner.hasNextLine...

Call function with the specified parameter number

In javascript, there are some situation we only want to call a function with one, two or three parameter(s), but input of it maybe there are a lot of parameters. For example, we want to repeat every element in array one time: const data = [2, 11, 6, 10]; // expected [22, 1111, 66, 1010] What will you do? Simplest, we can do: const data = [2, 11, 6, 10]; data.map(el => el.toString()).ma...

Category
parameter
(2 posts)

Optional Parameters in Programing

Optional parameters is the way for using method without required full all parameters in definition of method. It will be useful when using method in different contexts. Java In Java, we have two kinds of optional parameter of method: Overload methods Rest parameters Java: Overload methods In three methods below, we have different parameters for each method with the same method name: imp...

Call function with the specified parameter number

In javascript, there are some situation we only want to call a function with one, two or three parameter(s), but input of it maybe there are a lot of parameters. For example, we want to repeat every element in array one time: const data = [2, 11, 6, 10]; // expected [22, 1111, 66, 1010] What will you do? Simplest, we can do: const data = [2, 11, 6, 10]; data.map(el => el.toString()).ma...

Category
reuse
(1 posts)

Call function with the specified parameter number

In javascript, there are some situation we only want to call a function with one, two or three parameter(s), but input of it maybe there are a lot of parameters. For example, we want to repeat every element in array one time: const data = [2, 11, 6, 10]; // expected [22, 1111, 66, 1010] What will you do? Simplest, we can do: const data = [2, 11, 6, 10]; data.map(el => el.toString()).ma...

Category
scanner
(1 posts)

Be careful when using Scanner in Java

To interact with a java application in command line, Scanner is one of the most popular way to implement. But you know, it also has a mistake that we may easily make. First, let use it in a simple program: import java.util.Scanner; public class Main { private static String inputString() { final Scanner scanner = new Scanner(System.in); String result = ""; if (scanner.hasNextLine...

Category
c-sharp
(1 posts)

Optional Parameters in Programing

Optional parameters is the way for using method without required full all parameters in definition of method. It will be useful when using method in different contexts. Java In Java, we have two kinds of optional parameter of method: Overload methods Rest parameters Java: Overload methods In three methods below, we have different parameters for each method with the same method name: imp...

Category
spring
(1 posts)

Manually to create LDAP authentication provider

Have you ever want to create a custom login flow with composite of ldap and other authentication? But you relize that, LDAP almost use integrated with Spring security? And you would like to use it seperatedly, yes, me too and now I will share you the way I have used. 1. Use class DefaultSpringSecurityContextSource to create LDAP context source. It is a little weird that we will use DefaultSpring...

Category
boot
(1 posts)

Manually to create LDAP authentication provider

Have you ever want to create a custom login flow with composite of ldap and other authentication? But you relize that, LDAP almost use integrated with Spring security? And you would like to use it seperatedly, yes, me too and now I will share you the way I have used. 1. Use class DefaultSpringSecurityContextSource to create LDAP context source. It is a little weird that we will use DefaultSpring...

Category
spring-boot
(1 posts)

Manually to create LDAP authentication provider

Have you ever want to create a custom login flow with composite of ldap and other authentication? But you relize that, LDAP almost use integrated with Spring security? And you would like to use it seperatedly, yes, me too and now I will share you the way I have used. 1. Use class DefaultSpringSecurityContextSource to create LDAP context source. It is a little weird that we will use DefaultSpring...

Category
ldap
(1 posts)

Manually to create LDAP authentication provider

Have you ever want to create a custom login flow with composite of ldap and other authentication? But you relize that, LDAP almost use integrated with Spring security? And you would like to use it seperatedly, yes, me too and now I will share you the way I have used. 1. Use class DefaultSpringSecurityContextSource to create LDAP context source. It is a little weird that we will use DefaultSpring...

Category
authentication
(1 posts)

Manually to create LDAP authentication provider

Have you ever want to create a custom login flow with composite of ldap and other authentication? But you relize that, LDAP almost use integrated with Spring security? And you would like to use it seperatedly, yes, me too and now I will share you the way I have used. 1. Use class DefaultSpringSecurityContextSource to create LDAP context source. It is a little weird that we will use DefaultSpring...

Category
provider
(1 posts)

Manually to create LDAP authentication provider

Have you ever want to create a custom login flow with composite of ldap and other authentication? But you relize that, LDAP almost use integrated with Spring security? And you would like to use it seperatedly, yes, me too and now I will share you the way I have used. 1. Use class DefaultSpringSecurityContextSource to create LDAP context source. It is a little weird that we will use DefaultSpring...