Found 9313 Articles for Object Oriented Programming

Check if a string has white space in JavaScript?

AmitDiwan
Updated on 09-Sep-2020 12:59:13

4K+ Views

To check whitespace in a string, use the concept of indexOf(‘ ’). Following is the code −Examplefunction stringHasTheWhiteSpaceOrNot(value){    return value.indexOf(' ') >= 0; } var whiteSpace=stringHasTheWhiteSpaceOrNot("MyNameis John");    if(whiteSpace==true){       console.log("The string has whitespace");    } else {       console.log("The string does not have whitespace"); }To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo108.js.OutputThis will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo108.js The string has whitespace

How to put variable in regular expression match with JavaScript?

AmitDiwan
Updated on 09-Sep-2020 12:57:59

1K+ Views

You can use match() with passing the variable name. The syntax is as follows −console.log(yourVariableName.match(yourMatchingVariableName));Examplevar senetence = 'My Name is John'; console.log("The actual value="); console.log(senetence); var matchWord = 'John'; console.log("The matching value="); console.log(matchWord); var matchRegularExpression = new RegExp(matchWord, 'g' ); console.log(senetence.match(matchWord));To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo107.js.OutputThis will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo107.js The actual value= My Name is John The matching value= JohnRead More

How to create a custom function similar to find() method in JavaScript?

AmitDiwan
Updated on 09-Sep-2020 12:56:13

335 Views

Let’s say we have the following records of studentId and studentName and want to check a specific student name −const studentDetails= [    {       studentId:101,       studentName:"John"    },    {       studentId:102,       studentName:"David"    },    {       studentId:103,       studentName:"Carol"    } ]Create a custom function to find by name. Following is the code −Exampleconst studentDetails= [    {       studentId:101,       studentName:"John"    },    {       studentId:102,       studentName:"David"    },    {       studentId:103,       studentName:"Carol"    } ] function findByName(name){    var flag=true;    for(var i=0;i node demo106.js The name found=David

Difference between mutable and immutable object

Himanshu shriv
Updated on 09-Sep-2020 11:58:34

4K+ Views

In Java, state of the immutable object can’t be modified after it is created b ut definitely reference other objects. They are very useful in multithreading environment because multiple threads can’t change the state of the object so immutable objects are thread safe. Immutable objects are very helpful to avoid temporal coupling and always have failure atomicity.On the other hand, Mutable objects have fields that can be changed, immutable objects have no fields that can be changed after the object is created.Sr. No.KeyMutable objectImmutable object1BasicWe can modify the state of a mutable object after it is createdWe can't modify the ... Read More

Difference between default and static interface method in Java 8.

Himanshu shriv
Updated on 31-Oct-2023 03:22:25

24K+ Views

According to Oracle's Javadocs −Default methods enable you to add new functionality to the interfaces of your libraries and ensure binary compatibility with code written for older versions of those interfaces.A static method is a method that is associated with the class in which it is defined rather than with any object. Every instance of the class shares its static methods.Static method in interface are part of the interface class can’t implement or override it whereas class can override the default method.Sr. No.KeyStatic Interface MethodDefault Method1BasicIt is a static method which belongs to the interface only. We can write implementation ... Read More

Difference between Function and Predicate in Java 8

Himanshu shriv
Updated on 09-Sep-2020 11:22:33

6K+ Views

Function and Predicate both functional interface was introduced in Java 8 to implement functional programming in Java.Function interface is used to do the transformation.It can accepts one argument and produces a result. On the other side, Predicate can also accept only one argument but it can only return boolean value. It is used to test the condition.Sr. No.KeyFunctionPredicate1BasicIt can take 2 type parameters First one represents input type argument type and second one represents return type.It can take one type parameter which represents input type or argument type.2Return TypeIt can return any type of value.It can only return boolean value3MethodIt ... Read More

Difference between scheduledThread pool and Single Thread Executor.

Himanshu shriv
Updated on 09-Sep-2020 11:16:53

1K+ Views

Sr. No.KeyScheduled Thread PoolSingle Thread Executor1BasicCreates a thread pool that can schedule commands to run after a given delay, or to execute periodically. Tasks are guaranteed to execute sequentially, and no more than one task will be active at any given time2QueueIt uses Delay Queue to store tasks. Schedule the task based on time delay.It uses blocking queue.3Thread LifetimeT he number of threads to keep in the pool, even if they are idleRecreate thread if killed because of the task.4.Thread Pool SizeIt always has a single thread running.The thread pool can grow from zero threads to Integer.MAX_VALUE5.Use CaseWe should used fixedthreadpool, ... Read More

Difference between JDK dynamic proxy and CGLib proxy in Spring

Himanshu shriv
Updated on 09-Sep-2020 09:28:58

3K+ Views

Spring AOP is proxy based. Spring used two types of proxy strategy one is JDK dynamic proxy and other one is CGLIB proxy.JDK dynamic proxy is available with the JDK. It can be only proxy by interface so target class needs to implement interface. In your is implementing one or more interface then spring will automatically use JDK dynamic proxies.On the other hand, CGLIB is a third party library which spring used for creating proxy. It can create proxy by subclassing. Spring uses CGLIB for proxy if class is not implementing interface.Sr. No.KeyJDK dynamic proxyCGLIB proxy1BasicIt can be only proxy ... Read More

Difference between applicationContext.xml and spring-servlet.xml in Spring Framework

Himanshu shriv
Updated on 09-Sep-2020 09:26:49

2K+ Views

Applicationcontext.xml - It is standard spring context file which contains all beans and the configuration  that are common among all the servlets. It is optional file in case of web app. Spring uses ContextLoaderListener to load this file in case of web application. Spring-servlet.xml- It is a single entry point for Spring. DispatcherServlet scan this file and starts to load its component. It defines the bean and configuration that are only related to that servlet.In Spring MVC application we chain them in below order −          web.xml --> dispatcher servlet --> application contextSr. No.KeyApplicationContext.xmlSpring-servlet.xml1BasicapplicationContext.xml  defines the beans that ... Read More

Difference between DispatcherServlet and ContextLoaderListener in Spring

Himanshu shriv
Updated on 09-Sep-2020 09:06:17

2K+ Views

ContextLoaderListener creates a root web-application-context for the web-application and puts it in the ServletContext. This context can be used to load and unload the spring-managed beans ir-respective of what technology is being used in the controller layer(Struts or Spring MVC).DispatcherServlet creates its own WebApplicationContext and the handlers/controllers/view-resolvers are managed by this context.Sr. No.KeyDispatcherServletContextLoaderListener1BasicThe task of the DispatcherServlet  is to send request to the specific Spring MVC controller ContextLoaderListener  reads the Spring configuration file (with value given against contextConfigLocation in web.xml ), parses it and loads the singleton bean defined in that config file. So we initialize the web application with ContextLoaderListener ... Read More

Advertisements