About Question enthuware.ocpjp.v7.2.1427 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
vijayanand
Posts: 10
Joined: Fri Sep 26, 2014 8:40 am
Contact:

About Question enthuware.ocpjp.v7.2.1427 :

Post by vijayanand »

arg[0] is "\s[\d]*\s"

Shouldn't it be "\\s[\\d]*\\s" ?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1427 :

Post by admin »

No, since you are supposed to type it on the command line, you don't need to using \\. \\ is required when you put it as a String in the code.
If you like our products and services, please help us by posting your review here.

maderkse
Posts: 5
Joined: Thu Sep 13, 2018 3:46 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1427 :

Post by maderkse »

The command line arguments given in the question are: \s[\d]*\s "12 3abc ab23". The double quotes are missing in the first argument. Perhaps you can correct this. Without the quotes it's not working as should.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1427 :

Post by admin »

The issue is not with the quotes. There seems to be an extra / at the beginning, which should not be there. I tried it just now. It compile and runs fine without producing any output just as the correct option says.
If you like our products and services, please help us by posting your review here.

maderkse
Posts: 5
Joined: Thu Sep 13, 2018 3:46 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1427 :

Post by maderkse »

The difference between quotes and without quotes will only show when something is found. Below in the picture you see my sample code, an example without quotes and with quotes. It should find " 1 " but it fails in the example without quotes. (OS is Linux)

Image

maderkse
Posts: 5
Joined: Thu Sep 13, 2018 3:46 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1427 :

Post by maderkse »

The picture link is not working in my previous post. Below, I pasted the terminal text, which is the same content as in the picture.

[12:27 tmp ]$ cat R8.java

Code: Select all

import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class R8 {
   public static void main(String[] args) {
      System.out.println("Hi " + R8.class.getSimpleName() + " here!");

      Pattern p = Pattern.compile(args[0]);
      Matcher m = p.matcher(args[1]);
      boolean find = false;
      while (find = m.find()) {
         System.out.println(m.start() + m.group());
      }
   }
}
[12:27 tmp ]$ java R8 \s[\d]*\s " 1 "
Hi R8 here!
[12:28 tmp ]$ java R8 "\s[\d]*\s" " 1 "
Hi R8 here!
0 1

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1427 :

Post by admin »

Can you tell me which JDK version are you using? Because I am running it on Win 10 with JDK 1.8.0.121 and when I run it with arguments \s[\d]*\s " 1 "
it prints 0 1.
If you like our products and services, please help us by posting your review here.

maderkse
Posts: 5
Joined: Thu Sep 13, 2018 3:46 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1427 :

Post by maderkse »

Code: Select all

[13:54 ~ ]$ java -version
java version "1.8.0_172"
Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)
[13:55 ~ ]$ uname -a
Linux localhost 4.4.111-13688770-QB19092629 #1 SMP PREEMPT Wed Jul 25 16:14:55 KST 2018 aarch64 GNU/Linux

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1427 :

Post by admin »

So it could be that the behavior is different on Linux.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 34 guests