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); 

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.

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 ...

JOINs in MySQL

JOIN's is used to query data from two or more than two table based on relationship between certain columns in these tables. Tables in Database are related to each other with some constraints like (Primary Key & Foreign Key) Primary Key :- Column with unique value for each row that is not value matching to each other in the column. Foreign Key :- Two tables are mapped through concept of primary and foreign key, that means primary key of one table is used in other table as foreign key. fig : Primary Key and Foreign Key Example Query to create the above two tables. CREATE TABLE `project_mst` (   `PK_PROJECT_ID` varchar(10) NOT NULL,   `PROJECT_NAME` varchar(100) default NULL,   `PROJECT_DURATION` varchar(50) default NULL,   `FK_MANAGER_ID` varchar(10) default NULL,   PRIMARY KEY  (`PK_PROJECT_ID`) ) CREATE TABLE `manager_mst` (   `PK_MANAGER_ID` varchar(10) NOT NULL,   `MANAGER_...

Uploading data on Remote Server in Java

This blog demonstrate how to upload data from file to remote server/database. Follow the steps as shown. 1. Create new Dynamic Web Project. 2. Now create all the packages as show in the image below. 3. Create controller with name ImportContact.java 4. Create pojo with name Contact.java 5. Create database layer code with name ImportContactBroker.java 6. Create connectivity with name DBConnection.java 7. Create db connectivity setting file as connectionSetting.java 8. Create jsp page with importcontact.jsp 9. Create supporting files like Constant.java and CsvReader.java 10. You can download the war file and import in your workspace. 11. MultipartRequest in Servlet and inside jsp helps to upload file on the remote server. 12. Download sample csv file from here . 13. Create Table with name Contact in Database as given in configuration file. 14.Just compile and run the code. ImportContact.java package com.uploadfile.controller; import java.io.BufferedReader; impo...

Creating Webservice in Java

What is Web Service? A Web service is a method of communication between two electronic devices over the World Wide Web. A Web service is a software function provided at a network address over the web or the cloud, it is a service that is "always on" as in the concept of utility computing. The W3C defines a "Web service" as "a software system designed to support interoperable machine-to-machine interaction over a network". It has an interface described in a machine-processable format (specifically Web Services Description Language, known by the acronym WSDL). Other systems interact with the Web service in a manner prescribed by its description using SOAP messages, typically conveyed using HTTP with an XML serialization in conjunction with other Web-related standards. Web services creation process 1. To create webservice you have to Download axis2.1.x 2. Open eclipse-> windows ->preferences as shown in screen print. 3. In preferences-...