Skip to main content

Posts

Remove element from Array Javascript

Remove element from Array Javascript ----------------------------------------------------------------------- const array = ["test1", "test2", "test3", "test4"]; console.log(array); const index = array.indexOf("test2"); if (index > -1) {   array.splice(index, 1); } // **** array = ["test1", "test3", "test4"] console.log(array); 
Recent posts

Java 8 Features

Java 8 features was released on 18th March 2014 and we need to be on top of it. In this tutorial, we will look into Java 8 features with examples. ----------------------------------------------------------------------------- Java 8 features : 1. Lambda Expression 2. Method references 3. Interface changes: Default and static methods 4. Streams 5. StringJoiner class with example 6. Stream filter 7. forEach() Method 8. Functional interfaces 9. Optional class with example 10. Collectors class with example 11. Arrays Parallel Sort

Lambda Expression

Java Lambda Expressions Lambda expression is a new and important feature of Java 8. It provides a way to represent one method interface using an expression. This expression will help to iterate, filter and extract data from collection. The Lambda expression provides an implementation of an interface which has functional interface. It saves a lot of code. When we use lambda expression, we don't need to define the method again for providing the implementation. We just need to write the implementation code. .class file is not created for lambda Expression as compiler treat this as function. Functional Interface Lambda expression provides implementation of functional interface. An interface which has only one abstract method is called functional interface. Java provides an anotation @FunctionalInterface, which is used to declare an interface as functional interface.

Uploading files on Remote Server using Spring 3.x

$(document).ready(function() { $("#quoteCount").keydown(function(event) { if ( event.keyCode == 46 || event.keyCode == 8 ) { // Allow only backspace and delete // let it happen, don't do anything } else { if (event.keyCode < 48 || event.keyCode > 57 ) { // Ensure that it is a number and stop the keypress event.preventDefault(); } } }); });

Executing executable Jar file from Java Program

Sample code to execute jar file from Java Program. Pre-requisite 1. Need to have executable jar file. 2. Copy the code in your workspace and Run the code. package com.test.reusable.enterprise.service; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import org.apache.commons.lang.exception.ExceptionUtils; public class ExecuteJarFile { public static void main(String[] args) { try { //Method1 to Execute Jar file From Java Program ProcessBuilder pb = new ProcessBuilder("java", "-jar", "HelloWorld.jar"); // command to execute jar file with fileName.jar pb.redirectErrorStream(true); pb.directory(new File("C:/www/")); // Directory path where your jar file is placed. Process p = pb.start();

Reading and Writing text File in Java

var regex = /^([a-zA-Z0-9])+([\w_\.\-]([a-zA-Z0-9])*[a-zA-Z0-9])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; Simple code to demonstrate to Read and Write text file in Java. package email; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class ReadAndWriteFile { public static void main(String[] args) {   try {         String content = "This is the content to write into file";          File writeFile = new File("D:/Sample.txt");    // if file doesnt exists, then create it    if (!writeFile.exists()) {     writeFile.createNewFile();    } /**   * When we pass true as parameter to FilwWriter   * then it appends the content in file instead of overwriting the content   */    //FileWriter fw = new FileWriter(file.getAbsoluteFile(),true);    FileWriter fw = new FileW