java-8

Java command works but javac command doesn't

亡梦爱人 提交于 2021-02-17 06:12:31
问题 I just install jdk and jre version 8 In windows. Environment variable already set. I try run "java -version" in cmd and it shows the version of java installed. But when I try to compile java project with "javac projectName" system says javac is not recognized as internal or external command. So can anyone tell me how to fix it? here is my environment variable: C:\Users\Foody>echo %PATH% C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\NVIDIA Corporation\Ph ysX\Common;C:\WINDOWS

Java command works but javac command doesn't

陌路散爱 提交于 2021-02-17 06:12:05
问题 I just install jdk and jre version 8 In windows. Environment variable already set. I try run "java -version" in cmd and it shows the version of java installed. But when I try to compile java project with "javac projectName" system says javac is not recognized as internal or external command. So can anyone tell me how to fix it? here is my environment variable: C:\Users\Foody>echo %PATH% C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\NVIDIA Corporation\Ph ysX\Common;C:\WINDOWS

Java 8 collecting the list that is already present in object

醉酒当歌 提交于 2021-02-17 03:44:07
问题 I was just searching for better way to handle this scenario using java 8 streams. Object A has list of object b. What I get is a list of object A (List). I need to stream through list of object A and get all the listB's in each of the object A as a one single list. class A { List<B> listB } I have tried the below way it throws compilation List<A> as = someObject.getAs(); List<B> listofBs = as.stream().map(in -> in.getListB()).collect(Collectors.toList()); 回答1: To get a single list of all B's,

Syntax error on token(s), misplaced construct(s) for lambda expression

烈酒焚心 提交于 2021-02-16 21:19:32
问题 I have encountered a syntax problem in the following code used for Threading: btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ new Thread(() -> { GrabberShowUsesCallable gs = new GrabberShowUsesCallable(); //GrabberShow gs = new GrabberShow(); ExecutorService executorService = Executors.newSingleThreadExecutor(); Future<String> future = executorService.submit(gs); String cc; try { //Add data to table cc = future.get(); model.addRow(new Object[]

Syntax error on token(s), misplaced construct(s) for lambda expression

社会主义新天地 提交于 2021-02-16 21:17:12
问题 I have encountered a syntax problem in the following code used for Threading: btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ new Thread(() -> { GrabberShowUsesCallable gs = new GrabberShowUsesCallable(); //GrabberShow gs = new GrabberShow(); ExecutorService executorService = Executors.newSingleThreadExecutor(); Future<String> future = executorService.submit(gs); String cc; try { //Add data to table cc = future.get(); model.addRow(new Object[]

How do I deal with checked exceptions in lambda? [duplicate]

允我心安 提交于 2021-02-16 15:36:08
问题 This question already has answers here : Java 8 Lambda function that throws exception? (26 answers) Closed 4 years ago . I have the following code snippet. package web_xtra_klasa.utils; import java.util.Arrays; import java.util.Properties; import java.util.function.Function; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class

Java current time different values in api

强颜欢笑 提交于 2021-02-16 14:57:50
问题 I'm a little confused using the DateTime related class for Java SE 7 and 8 API's, for displaying the current time, I'm reviewing the multiple ways for get the system's current datetime. My question is : Which one is more accurate for displaying time in millis? Next is the code snippet, I'm using Java 8 for the reviewing. import java.time.Instant; import java.util.Calendar; import java.util.Date; public class CurrentTimeValidationDemo { public static void main(String[] args) { Instant now =

Java current time different values in api

坚强是说给别人听的谎言 提交于 2021-02-16 14:57:43
问题 I'm a little confused using the DateTime related class for Java SE 7 and 8 API's, for displaying the current time, I'm reviewing the multiple ways for get the system's current datetime. My question is : Which one is more accurate for displaying time in millis? Next is the code snippet, I'm using Java 8 for the reviewing. import java.time.Instant; import java.util.Calendar; import java.util.Date; public class CurrentTimeValidationDemo { public static void main(String[] args) { Instant now =

Java 8 - why they provided method references?

点点圈 提交于 2021-02-16 14:46:10
问题 What is better in calling names.stream().forEach(System.out::println); Than names.stream().forEach(n -> System.out.println(n)); Despite the fact you have to write less code? Are there any other advantages of introducing method references in Java 8? 回答1: Despite the fact you have to write less code? Are there any other advantages of introducing method references in Java 8? Having to write less code is enough of an advantage to consider introducing a language feature. There is a similar feature

Convert List<Person> to Map<Integer, List<Integer>> using Lambdas

可紊 提交于 2021-02-16 14:39:25
问题 I wanted to convert list to Map as below. Here is the example. I have student list something like below code snippet. Get a Hasmap out of it with Key as Integer which is Age and value as List. From the below input feed, My response should be something like below. How do I achieve this ? Map[[10, {1}], [20, {2,3,4}], [30,{5}]. [40,{6}]]; private static List<Person> getPersonTestData() { List<Person> personList = new ArrayList<>(); personList.add(Person.of(1, "First1", "Last1", 10)); personList