OkHTTP:
There are several ways to upload the file. OKHTTP is a one of a client to call
an api to upload file to the server.
HTTPCLIENT:
We can also use HTTP Client to write an api client to upload files to server.
There are several ways to upload the file. OKHTTP is a one of a client to call
an api to upload file to the server.
HTTPCLIENT:
We can also use HTTP Client to write an api client to upload files to server.
<groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <scope>compile</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency>
4) add following in application.properties file in src/main/resources
spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp
5) Create controller class named SpringJava4sController.java
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; @RestController public class SpringJava4sController { @RequestMapping(value="/test", method=RequestMethod.GET) public ModelAndView showLoginPage(Model model) { model.addAttribute("message", "Welcome to Java4s Spring Boot Tutorials"); return new ModelAndView("welcomePage"); } }
6) Make sure we have class with main as
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); }
7) create webapp/WEB-INF/jsp folder within src/main
8) place jsp file welcomePage inside jsp as:
<html xmlns:th="http://www.thymeleaf.org">
<body>
${message}
</body>
</html>
9) go to browsrer and see localhost:8080/test
This is the program n=in java where it checks whether the given zoneddatetime is holidays or not.
It uses java8 ZonedDateTime to determine the zoned date and time.
public class QuestionB { public static ArrayList<String> getPerms(String remainder) { int len = remainder.length(); ArrayList<String> result = new ArrayList<String>(); /* Base case. */ if (len == 0) { result.add(""); // Be sure to return empty string!
return result; } for (int i = 0; i < len; i++) { /* Remove char i and find permutations of remaining characters.*/
String before = remainder.substring(0, i); String after = remainder.substring(i + 1, len); ArrayList<String> partials = getPerms(before + after); /* Prepend char i to each permutation.*/
for (String s : partials) {
result.add(remainder.charAt(i) + s);
}
}
return result;
}
public static void main(String[] args) {
ArrayList<String> list = getPerms("abc");
System.out.println("There are " + list.size() + " permutations.");
for (String s : list) {
System.out.println(s);
}
}
}
public class GeneralizedSolution { public static void main(String[] args) { String s = "86435"; // System.out.println("\nString " + s + ":\nPermutations: " + Permutation(s));
Set<Integer> set = Permutation(s).stream().map(a -> Integer.parseInt(a))
.collect(Collectors.toSet()); List<Integer> list = new ArrayList<>(set); Collections.sort(list); // System.out.println(list); int index = list.indexOf(Integer.parseInt(s)); if (index == list.size() - 1) { System.out.println("there is no number greatet than " + s); } else { System.out.println("The number just greater than " + s + "is :" + list.get(index + 1)); } } public static Set<String> Permutation(String str) { Set<String> Result = new HashSet<String>(); if (str == null) { return null; } else if (str.length() == 0) { Result.add(""); return Result; } char firstChar = str.charAt(0); String rem = str.substring(1); Set<String> words = Permutation(rem); for (String newString : words) { for (int i = 0; i <= newString.length(); i++) { Result.add(CharAdd(newString, firstChar, i)); } } return Result; } public static String CharAdd(String str, char c, int j) { String first = str.substring(0, j); String last = str.substring(j); return first + c + last; } }
solution 3rd:
of permutation with finding permutation with making first element constant and
finding permutation of remaining:
class Permutations
{
// Recursive function to generate all permutations of a String
private static void permutations(String candidate, String remaining)
{
if (remaining.length() == 0) {
System.out.println(candidate);
}
for (int i = 0; i < remaining.length(); i++)
{
String newCandidate = candidate + remaining.charAt(i);
String newRemaining = remaining.substring(0, i) +
remaining.substring(i + 1);
permutations(newCandidate, newRemaining);
}
}
// Find Permutations of a String in Java
public static void main(String[] args)
{
String s = "ABC";
permutations("", s);
}
}
import java.util.regex.Matcher; import java.util.regex.Pattern; public class regex{ public static void main(String []args){ System.out.println("Hello World"); String s = "214投資者、43発行者"; Pattern p = Pattern.compile("([0-9]+)"); Matcher m = p.matcher(s); int index = 0; StringBuffer str = new StringBuffer(); while (m.find()){ String match = m.group(); m.appendReplacement(str,"replace"+">"); } m.appendTail(str); String result = str.toString(); System.out.println(result); } }
Graph can be represented in two ways:
1)adjacency matrix
2) adjancency list
Note here we create array of linkedlist. Array are of size length vertices.
Each array has all its childrens so each array is linkedlist of size vertices V.
class node1 { int data; node1 left; node1 right; node1(int data){ this.data = data; this .left = null; this.right = null; } void inorder(){ if(left != null) { left.inorder(); } System.out.println(this.data); if(right != null) right.inorder(); } } public class Tree { void inorder(node1 root) { if (root!= null) { inorder(root.left); System.out.println(root.data); inorder(root.right); } } public static void main(String[] args) { node1 root1 = new node1(5); root1.left = new node1(3); root1.right = new node1(7); root1.left.left = new node1(2); root1.left.right = new node1(4); root1.right.left = new node1(6); root1.right.right = new node1(8); Tree tree = new Tree(); tree.inorder(root1); root1.inorder(); } }
For addition of add_item function for creating binary tree:
Note to use in lower class if root has to be passed otherwise in the upper class of only item has
to be passed as root should be referenced with object.
class node1 { int data; node1 left; node1 right; node1(int data){ this.data = data; this .left = null; this.right = null; } void add_node(int item) { if(item < this.data ) { if(this.left == null) { this.left = new node1(item); } else{ this.left.add_node(item); } } else{ if(this.right == null) { this.right = new node1(item); } else { this.right.add_node(item); } } } } public class Tree { void inorder(node1 root) { if (root!= null) { inorder(root.left); System.out.println(root.data); inorder(root.right); } } void add_node(node1 root,int item) { if(root == null) root = new node1(item); else{ if(item < root.data ) if(root.left == null) root.left = new node1(item); else { add_node(root.left,item); } else{ if(root.right == null) root.right = new node1(item); else { add_node(root.right, item); } } } } public static void main(String[] args) { node1 root1 = new node1(5); // root1.add_node(3);// root1.add_node(2);// root1.add_node(1);// root1.add_node(6);// root1.add_node(8);// root1.add_node(7); Tree tree = new Tree(); tree.add_node(root1,3); tree.add_node(root1,2); tree.add_node(root1,1); tree.add_node(root1,6); tree.add_node(root1,8); tree.add_node(root1,7); tree.add_node(root1,9); tree.inorder(root1); } }
class node{ int data; node next; node(int item){ data = item; next = null; } } class linked_list{ node create_list() { node head = new node(2); head.next = new node(3); head.next.next = new node(4); head.next.next.next = new node(5); return head; } void get_list(node head) { node current = head; while(current != null) { System.out.println(current.data); current = current.next; } } } public class list { public static void main(String[] args) { linked_list start = new linked_list(); node head = start.create_list(); start.get_list(head); } }
2. Simple within the same class:
class list { int data; list next; list(int date) { data = date; next = null; } } public class graph { void add_data(list root,int item) { list current = root; while(current.next != null) { current = current.next; } current.next = new list(item); } void get_data(list root) { list current = root; while(current != null) { System.out.println(current.data); current = current.next; } } public static void main(String[] args) { list root = new list(5); graph obj = new graph(); obj.add_data(root,3); obj.add_data(root,4); obj.add_data(root,7); obj.get_data(root); } }
2.With recursive insert:
Note to always store head in an object so that each time it doesnot change. Otherwise we need to
keep track of head and end seperately.
class node{ int data; node next; node(int item){ data = item; next = null; } public int getData() { return data; } public node getNext() { return next; } public void setData(int data) { this.data = data; } public void setNext(node next) { this.next = next; } public void insert_number(int data) { if(next == null){ next = new node(data); } else{ next.insert_number(data); } } } class linked_list{ node head; linked_list(){ head = null; } void insert_node(int data){ if(head == null) { head = new node(data); } else{ head.insert_number(data); } /////or even can be done without recursion// note the n.next should be used./// public void insert_number(int data)//{// node end = new node(data);//node n = this;//while(n.next!= null)// {// n = n.next;// }// n.next = end;// }} void get_list() { node current = head; while(current != null) { System.out.println(current.data); current = current.next; } } } public class list { public static void main(String[] args) { linked_list start = new linked_list(); start.insert_node(2); start.insert_node(3); start.insert_node(4); start.insert_node(5); start.insert_node(6); start.insert_node(7); start.get_list(); } }3: To keep track of head and end seperately:class node{ int data; node next; node(int item){ data = item; next = null; } public int getData() { return data; } public node getNext() { return next; } public void setData(int data) { this.data = data; } public void setNext(node next) { this.next = next; } } class linked_list{ node head; node end; linked_list(){ head = null; end = head; } void insert_node(int data){ if(head == null) { head = new node(data); end = head; } else{ node nptr = new node(data); end.setNext(nptr); end = nptr; } } void get_list() { node current = head; while(current != null) { System.out.println(current.data); current = current.next; } } } public class list { public static void main(String[] args) { linked_list start = new linked_list(); start.insert_node(2); start.insert_node(3); start.insert_node(4); start.insert_node(5); start.insert_node(6); start.insert_node(7); start.get_list(); } }So overall with just only one class node isclass node{ int data; node next; node(int item){ data = item; next = null; } public void insert_number(int data) { node end = new node(data); node n = this; while(n.next!= null) { n = n.next; } n.next = end; } void get_list() { node current = this; while(current != null) { System.out.println(current.data); current = current.next; } } } public class list { public static void main(String[] args) { node start = new node(1); start.insert_number(2); start.insert_number(3); start.insert_number(4); start.insert_number(5); start.insert_number(6); start.insert_number(7); start.get_list(); } }