.
├── com
│ ├── vicky
│ └── Main.java
package com.vicky;
import org.apache.commons.lang3.StringUtils;
import java.util.*;
public class Main {
public static void main(String arg[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Please Enter a String");
String enteredString = sc.next();
String reversedString = StringUtils.reverse(enteredString);
if (enteredString.equals(reversedString)) {
System.out.println("Given String is Palindrome");
} else {
System.out.println("Given String is not a Palindrome");
}
sc.close();
}
}
Above code has a dependency with Apache's Common Lang
All commands mentioned below has to run from parent directory of the project
- Download apache commons lang jar file & keep it inside the parent directory
.
├── commons-lang3-3.12.0.jar
├── com
│ ├── vicky
│ └── Main.java
- Command to compile .java file to .class file
javac -classpath commons-lang3-3.12.0.jar com/vicky/*.java
- Create a Manifest.txt file with following content in parent directory
(Note: Its mandatory to add an empty line at the end)
Class-Path: commons-lang3-3.12.0.jar
Main-Class: com.vicky.Main
- Command to create Jar file
jar cfm Palindrome.jar Manifest.txt com/vicky/*.class
- Command to execute Jar file
java -jar Palindrome.jar
.
├── com
│ ├── vicky
│ └── Main.java
package com.vicky;
import java.util.*;
public class Main {
public static void main(String arg[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Please Enter a String");
String enteredString = sc.next();
StringBuilder input = new StringBuilder();
input.append(enteredString);
String reversedString = input.reverse().toString();
if (enteredString.equals(reversedString)) {
System.out.println("Given String is Palindrome");
} else {
System.out.println("Given String is not a Palindrome");
}
sc.close();
}
}
The above code uses only Java's in-built classes.
All commands mentioned below has to run from parent directory of the project
- Command to compile .java file to class file
javac com/vicky/*.java
- Command to create Jar file
jar cfve Palindrome.jar com.vicky.Main com/vicky/*.class
- Command to execute Jar file
java -jar Palindrome.jar
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>
com.vicky.Main
</mainClass>
</transformer>
</transformers>
<createDependencyReducedPom>
false
</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
Thats all folks !