[Solved] Format date by provided time zone in java [duplicate]

Use the modern Java date and time classes for everything that has got to do with dates or times. DateTimeFormatter usFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT) .withLocale(Locale.US); System.out.println(date.format(usFormatter)); DateTimeFormatter deFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT) .withLocale(Locale.GERMANY); System.out.println(date.format(deFormatter)); This will print something like 6/27/17 27.06.17 It’s not exactly the formats you asked for, but it’s the formats Java thinks are appropriate for … Read more

[Solved] How can I read this string in Java? [closed]

Here are several ways to get the first character: String str = “x , y – zzzzzz”; System.out.println(str.charAt(0)); System.out.println(str.substring(0, 1)); System.out.println(str.replaceAll(“^(.).*”, “$1”)); See IDEONE demo Choose the one you like more 🙂 UPDATE: To find the first word, you may use the following regex pattern: String pattern = “[\\s\\p{P}]+”; \s stands for whitespace, and \p{P} … Read more

[Solved] how to redirect system input to javaFX textfield?

Preface: Given your “console application” doesn’t involve forking any processes or performing any “actual” I/O, you may want to redesign your application to use the TextField and TextArea directly, or at least more directly than you’re currently trying to do. Using System.out and System.in adds a layer of unnecessary indirection and makes everything more complex. … Read more

[Solved] Java: How to access implementation of a method of Sub class from Super class

Consider following: public interface Animal { bool isVertebrate(); bool isDomesticable(); } and an abstract class that implements this interface: abstract class Cat implements Animal { public bool isVertebrate() {return true;} public void dealWithCat(){ if (isDomesticable()){ … } } But implementation for isDomesticable is delegated to subclass: public class Tiger extends Cat { public bool isDomesticable(){ … Read more

[Solved] math need a number between -180 and 180

You could solve it like this: private static final int MIN = -180; private static final int MAX = 180; public static void main(String[] args) { System.out.println(keepInRange(-150 + 90)); System.out.println(keepInRange(0 + 90)); System.out.println(keepInRange(150 + 90)); System.out.println(keepInRange(-150 – 90)); } private static int keepInRange(final int value) { if (value < MIN) { /* * subtract the … Read more

[Solved] OpenCV to android Opencv (JAVA)

I hope this might help you as I am doing something similar. Mat gray8 = new Mat(marked.size(), CvType.CV_8UC1); Imgproc.cvtColor(marked, gray8, Imgproc.COLOR_RGB2GRAY); Scalar mean = Core.mean(gray8); Imgproc.threshold(gray8, gray8, mean.val[0], 255, Imgproc.THRESH_BINARY); /*Imgproc.erode(gray8, gray8, new Mat(), new Point(-1, -1), 2);*/ List<MatOfPoint> contours = new ArrayList<MatOfPoint>(); MatOfInt4 hierarchy = new MatOfInt4(); Imgproc.findContours(gray8, contours, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE); Toast.makeText(getApplicationContext(), contours.size()+” … Read more

[Solved] I am working on OCR reader application. below is my java code. My question is how to start another method if one is completed?

just use the same mode on text to speech ADD and it will play when the first one is done, ADD = ADD, FLUSH = reset textToSpeech.speak(“this will play when first is done”, TextToSpeech.QUEUE_ADD, null); solved I am working on OCR reader application. below is my java code. My question is how to start another … Read more

[Solved] Calculate the distance between two points

import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class MainActivity extends Activity{ Cal cal; TextView textView; public void onCreate(Bundle s){ super.onCreate(s); setContentView(R.layout.<your layout name>); // You can not set id of any view here cal = new Cal(this); // This is a object cal.cal(); textView.setText(“”+ cal.result); // set the value instead of view object } } … Read more

[Solved] How to replace a substring with ( from a string

This regex String a = “Want to Start (A) Programming and (B) Designing”; String b = a.replaceAll(“\\(“, “\n\\(“); System.out.println(b); results in Want to Start (A) Programming and (B) Designing Just escape the brackets with \\ and you’re fine. Edit: more specific, like mentioned below a.replaceAll(“(\\([AB]\\))”, “\n$1”); to match only (A) and (B) or a.replaceAll(“(\\(\\w\\))”, “\n$1”); … Read more

[Solved] how to display values in jsp through java class [closed]

i think you should try this public class EmpBean { public java.util.List dataList(){ ArrayList list=new ArrayList(); try{ Class.forName(“driver”); Connection con = DriverManager.getConnection(“url”, “user”, “pwd”); Statement st=con.createStatement(); System.out.println(“hiiiii”); ResultSet rs=st.executeQuery(“select * from employee”); while(rs.next()){ list.add(rs.getString(“name”)); list.add(rs.getString(“address”)); list.add(rs.getString(“contactNo”)); list.add(rs.getString(“email”)); } System.out.println(rs.getString(“contactNo”)); } catch(Exception e){} return list; } } Assuming this class working fine and it is returning … Read more