Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
The Glumslinger
Sep 24, 2008

Coach Nagy, you want me to throw to WHAT side of the field?


Hair Elf
I have a question that may have been asked, but from a general google search, I can't really find a good answer and trying to google this thread to find an answer isn't working well.

I'm trying to distribute a program as runnable jar, to be used for Java Webstart. The issue that I am having is that m jar contains multiple other jars internally that it uses. The most common answer that I found was to simply repackage the jars, but I am weary of this due licensing issues.

My current approach has been to try to move the files from inside of the jar, to another location outside of the jar and then use a class loader once they have been moved.

I have been running into trouble trying to get them to move, so I was wondering if people had any advice on dealing with jars, or any suggestions on how to do this in a better way.

EDIT: Ignore this, I managed to get it work

The Glumslinger fucked around with this message at 23:39 on Jul 21, 2010

Adbot
ADBOT LOVES YOU

Two Percent
Aug 26, 2005
I'm really sorry for barging into a subforum I never participated in just to ask for help. I've been trying to work around this for days and Google isn't helping. I'm a complete newbie to Java who barely got started and I'm having trouble with what I feel is a trivial issue but it has stumped.

Simply put, I want the String result of a Matcher search collapse the Unicode escape sequences, instead of presenting the whole String literally. For example, if I would simply use:

code:
String test = "@}~g0XQq}{?u{ah4ef'u xbzmrjym{4RtTuTp\023rSg\037u\030zIs\ntWuC}F:@zH B;g{srrf0|}ghtqw}{";
System.out.println(test);
It would properly replace the 4 escape sequences and show me the result I want:

code:
@}~g0XQq}{?u{ah4ef'u xbzmrjym{4RtTuTprSguzIs
tWuC}F:@zH B;g{srrf0|}ghtqw}{
However, if I use the usual Matcher search:

code:
private static String replaceLinks(String aText){
	 Pattern p = Pattern.compile("x\\.a\\(\"(.*?)\"\\)", Pattern.DOTALL );
	 Matcher m = p.matcher(aText);
	 StringBuffer sb = new StringBuffer();
	 while (m.find()) {
		 String test = m.group(1);
		 m.appendReplacement(sb, Matcher.quoteReplacement(x.a(test)));
	 	 System.out.println(test);
	 }
}
The substring is located but Println shows it like this:

code:
@}~g0XQq}{?u{ah4ef'u xbzmrjym{4RtTuTp\023rSg\037u\030zIs\ntWuC}F:@zH B;g{srrf0|}ghtqw}{
Because it was stored literally so as to preserve the \, so the content of test is:

code:
@}~g0XQq}{?u{ah4ef'u xbzmrjym{4RtTuTp\\023rSg\\037u\\030zIs\\ntWuC}F:@zH B;g{srrf0|}ghtqw}{
At first I tried a simple test.replaceAll("\\\\", "\\") but it seems the new substring field accepts just about anything except "\\". Using Matcher.quoteReplacement("\") obviously doesn't work. I've tried all sorts of type changes to try and make the Unicode collapse, but this simple problem is too much for my newbie self and I can't help but feel all that I need is a simple basic library method I don't know about.

lamentable dustman
Apr 13, 2007

🏆🏆🏆

YouAreCorrect posted:

I have a question.

My current employer wants me to get my Sun Certified Java Programmer certificate. This exam costs a poo poo load of :10bux:, so I really want to pass it the first time.

People in my office say it is very hard, some have failed 3-5 times now. This makes me terrified just at the thought of spending $1000 dollars on a loving certificate.

Can someone point me to a good source to prepare? Thanks.

Never met a recruiter or manager who cared about that cert but if my employer wanted me to get it and expected me to pay for it I would laugh in their face

epswing
Nov 4, 2003

Soiled Meat

YouAreCorrect posted:

This exam costs a poo poo load of :10bux:, so I really want to pass it the first time.

Wait they're asking you to foot the bill?

Or you don't want to waste your company's money?

YouAreCorrect
Oct 2, 2008

epswing posted:

Wait they're asking you to foot the bill?

Or you don't want to waste your company's money?

Well of course they will reimburse me. Just only when I pass.

Contra Duck
Nov 4, 2004

#1 DAD
That's still a joke. You don't want to do this certification, why should you be $1,000 in the hole if you fail?

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!

Two Percent posted:

I'm really sorry for barging into a subforum I never participated in just to ask for help. I've been trying to work around this for days and Google isn't helping. I'm a complete newbie to Java who barely got started and I'm having trouble with what I feel is a trivial issue but it has stumped.

Simply put, I want the String result of a Matcher search collapse the Unicode escape sequences, instead of presenting the whole String literally. For example, if I would simply use:

code:
String test = "@}~g0XQq}{?u{ah4ef'u xbzmrjym{4RtTuTp\023rSg\037u\030zIs\ntWuC}F:@zH B;g{srrf0|}ghtqw}{";
System.out.println(test);
It would properly replace the 4 escape sequences and show me the result I want:

code:
@}~g0XQq}{?u{ah4ef'u xbzmrjym{4RtTuTprSguzIs
tWuC}F:@zH B;g{srrf0|}ghtqw}{

Those aren't unicode escape characters, they're octal escape characters. You convert them by finding the base10 representation and looking in the ASCII table, basically.

This seems to do what you want, though it will require some modification to fit in with your stuff (since I couldn't really figure out what some of that code was doing).

code:
  public static void main(String[] args) {
    String test = "@}~g0XQq}{?u{ah4ef'u xbzmrjym{4RtTuTp\\023rSg\\037u\\030zIs\\ntWuC}F:@zH B;g{srrf0|}ghtqw}{";
    test = test.replace("\\\\", "\\").replace("\\n", "\n");
    test = clean(test);
    System.out.println(test);
  }

  private static String clean(String s) {
    Pattern p = Pattern.compile("\\\\(\\d{3})");
    Matcher m = p.matcher(s);
    StringBuffer sb = new StringBuffer();
    while (m.find()) {
      String test = m.group(1);
      m.appendReplacement(sb, Matcher.quoteReplacement("" + (char)Integer.parseInt(test, 8)));
    }
    m.appendTail(sb);
    return sb.toString();
  }
output:
code:
@}~g0XQq}{?u{ah4ef'u xbzmrjym{4RtTuTprSguzIs
tWuC}F:@zH B;g{srrf0|}ghtqw}{

Kilson fucked around with this message at 09:15 on Jul 21, 2010

Two Percent
Aug 26, 2005

Kilson posted:

Those aren't unicode escape characters, they're octal escape characters. You convert them by finding the base10 representation and looking in the ASCII table, basically.

Told you I'm a newbie...

Yeah, I was trying to mean exactly what you said, I wanted them parsed to ASCII.

Kilson posted:

This seems to do what you want, though it will require some modification to fit in with your stuff (since I couldn't really figure out what some of that code was doing).

code:
  public static void main(String[] args) {
    String test = "@}~g0XQq}{?u{ah4ef'u xbzmrjym{4RtTuTp\\023rSg\\037u\\030zIs\\ntWuC}F:@zH B;g{srrf0|}ghtqw}{";
    test = test.replace("\\\\", "\\").replace("\\n", "\n");
    test = clean(test);
    System.out.println(test);
  }

  private static String clean(String s) {
    Pattern p = Pattern.compile("\\\\(\\d{3})");
    Matcher m = p.matcher(s);
    StringBuffer sb = new StringBuffer();
    while (m.find()) {
      String test = m.group(1);
      m.appendReplacement(sb, Matcher.quoteReplacement("" + (char)Integer.parseInt(test, 8)));
    }
    m.appendTail(sb);
    return sb.toString();
  }
output:
code:
@}~g0XQq}{?u{ah4ef'u xbzmrjym{4RtTuTprSguzIs
tWuC}F:@zH B;g{srrf0|}ghtqw}{

And this worked perfectly. I just had to tweak it to accept more escape sequences like \t or \f and so on and it's working flawlessly. God bless you.

Funny that replace("\\\\", "\\") works but replaceAll("\\\\", "\\") doesn't. Gotta pay more attention to the docs.

HFX
Nov 29, 2004

Contra Duck posted:

That's still a joke. You don't want to do this certification, why should you be $1,000 in the hole if you fail?

Obviously you didn't work hard enough.

From friends that took it, most of the tripping up for people comes from knowing some of the lesser used API's and gotchas along with poor wording. I've had two or three friends pass it, but they pretty much only studied for it, and were not working at the time.

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!

Two Percent posted:

Told you I'm a newbie...

To be honest, I had to look that up as well. It's not a terribly common construction.

quote:

Yeah, I was trying to mean exactly what you said, I wanted them parsed to ASCII.

And this worked perfectly. I just had to tweak it to accept more escape sequences like \t or \f and so on and it's working flawlessly. God bless you.

Funny that replace("\\\\", "\\") works but replaceAll("\\\\", "\\") doesn't. Gotta pay more attention to the docs.

I think you can do replaceAll("\\\\\\\\", "\\") and it works the same way (yeah, it's stupid - gently caress you Java for not having a non-escaped regex syntax). I can't be 100% sure here, because this Linux machine I'm using seems to handle these characters strangely and outputs only characters that look like empty boxes, and won't allow me to copy/paste them here. :sigh:

HFX
Nov 29, 2004

Kilson posted:

To be honest, I had to look that up as well. It's not a terribly common construction.


I think you can do replaceAll("\\\\\\\\", "\\") and it works the same way (yeah, it's stupid - gently caress you Java for not having a non-escaped regex syntax). I can't be 100% sure here, because this Linux machine I'm using seems to handle these characters strangely and outputs only characters that look like empty boxes, and won't allow me to copy/paste them here. :sigh:

It is a pain in the rear end. I've resorted to having a loader class which loads from POTF to make it easy. It also makes sense not to include regular expressions as part of the language since this isn't a language built around them. However, yes it does make them much more painful.

I suppose you could have this get planted into the file with a shell / ant script during the build process. Maybe make a nice way to handle them in Eclipse through extension and second file?

HFX fucked around with this message at 09:52 on Jul 22, 2010

mfcrocker
Jan 31, 2004



Hot Rope Guy
Has anyone ever had any success using the client's Windows credentials to login to a web application written in Java? I'm currently developing a Vaadin application and have been asked to investigate using said credentials in a single sign-on, but from what I've read around and about the internet it doesn't seem possible.

Suggestions?

covener
Jan 10, 2004

You know, for kids!

bigfatspacko_uk posted:

Has anyone ever had any success using the client's Windows credentials to login to a web application written in Java? I'm currently developing a Vaadin application and have been asked to investigate using said credentials in a single sign-on, but from what I've read around and about the internet it doesn't seem possible.

Suggestions?

java AppServers can do this with SPNEGO:
http://www.ibm.com/developerworks/websphere/techjournal/0707_rogers/0707_rogers.html

Notorious H.P.B.
Jun 19, 2006

by Y Kant Ozma Post
I have what's probably a really dumb question about unit testing and mocking. Is it possible to mock an object inside a class that doesn't have getters and setters? Right now I'm trying to write a unit test for a class that submits an XML feed to Amazon.com's marketplace web service. The problem is the class was designed to be totally self-contained. Normally all of our services are written with web service objects configured through Spring, so it's easy to pass a mock object in the unit test instead of directing it to the normal Spring configuration. In this case, the web service object is set up within the class I'm trying to test itself. We don't want to hit the actual service--just test that the code is working properly and is submitting the correct XML at the end of its process. Ideally, I could use a mock web service to "receive" the XML. What can I do here, aside from modifying the production code so that the web service object can be passed in?

I hope this makes sense.

zootm
Aug 8, 2006

We used to be better friends.

Notorious H.P.B. posted:

I have what's probably a really dumb question about unit testing and mocking. Is it possible to mock an object inside a class that doesn't have getters and setters? Right now I'm trying to write a unit test for a class that submits an XML feed to Amazon.com's marketplace web service. The problem is the class was designed to be totally self-contained. Normally all of our services are written with web service objects configured through Spring, so it's easy to pass a mock object in the unit test instead of directing it to the normal Spring configuration. In this case, the web service object is set up within the class I'm trying to test itself. We don't want to hit the actual service--just test that the code is working properly and is submitting the correct XML at the end of its process. Ideally, I could use a mock web service to "receive" the XML. What can I do here, aside from modifying the production code so that the web service object can be passed in?

I hope this makes sense.
If you really don't want to modify the production code, you could use reflection to change the field containing the item you want to substitute after the instance was constructed; something like the following:
code:
SealedComponent sealed = new SealedComponent(); // Say this is your object you want to change a field on.
Field field = sealed.getClass().getField( "fieldWithService" );
field.setAccessible( true ); // Lets you write to a private field
field.set( sealed, mockService ); 
The reflective methods through about a million exception types, but putting "throws Exception" on a test case is pretty common practice. Obviously if the constructor of the object has non-trivial logic that will not be executed on the mock.

zootm fucked around with this message at 21:26 on Jul 22, 2010

Notorious H.P.B.
Jun 19, 2006

by Y Kant Ozma Post
Thanks! That's great to know in case I'm trying to test with these restrictions again. For now though, I got permission to modify the production code. This definitely seems like it will be useful, however. I can already think of a few test cases that this will make possible.

sonic bed head
Dec 18, 2003

this is naturual, baby!
I'm trying to make some changes to someone else's code written a few months ago that has since left the company. I am quite confused by his use of Class[] class.getClasses().

http://download.oracle.com/docs/cd/E17476_01/javase/1.4.2/docs/api/java/lang/Class.html#getClasses%28%29

What exactly does this return? An array of the class and all of it's subclasses?

Thanks for your help.

covener
Jan 10, 2004

You know, for kids!

sonic bed head posted:

I'm trying to make some changes to someone else's code written a few months ago that has since left the company. I am quite confused by his use of Class[] class.getClasses().

http://download.oracle.com/docs/cd/E17476_01/javase/1.4.2/docs/api/java/lang/Class.html#getClasses%28%29

What exactly does this return? An array of the class and all of it's subclasses?

Thanks for your help.

As in classes defined within the class -- not the types/superclasses of the class itself.
code:
utils.ThreadedClient.class.getClasses().toString()
===> [class utils.ThreadedClient$IHSThreadGroup, class utils.ThreadedClient$Worker]
$ grep "class" src/utils/ThreadedClient.java

public class ThreadedClient extends TestCase {
    public class IHSThreadGroup extends ThreadGroup { 
    public class Worker implements Runnable {
    private class ThreadedClientRunner implements Runnable {

sonic bed head
Dec 18, 2003

this is naturual, baby!

covener posted:

As in classes defined within the class -- not the types/superclasses of the class itself.
code:
utils.ThreadedClient.class.getClasses().toString()
===> [class utils.ThreadedClient$IHSThreadGroup, class utils.ThreadedClient$Worker]
$ grep "class" src/utils/ThreadedClient.java

public class ThreadedClient extends TestCase {
    public class IHSThreadGroup extends ThreadGroup { 
    public class Worker implements Runnable {
    private class ThreadedClientRunner implements Runnable {

Ah! Got it. For some reason those two paragraphs in the docs were too confusing for me. Thank you.

Chairman Steve
Mar 9, 2007
Whiter than sour cream

Notorious H.P.B. posted:

I hope this makes sense.

What zootm posted works sufficiently for testing (though I would always use Reflections as a last resort, in testing or production code). However, in future designs, getter/setter methods are good idea. If I want to maintain the immutability of an object's fields (i.e., no public getter/setters and no protected getter/setters to be used by a subclass of the given class), I make the setter method package-private - that way, the method is only exposed to classes within the same package (which includes the JUnit tests). Some might argue that it's still exposure because a programmer can make their package the same as your class' package, but the immutability of a class is still vulnerable as long as the Reflections API is allowed via security permission (which, if you're using Spring, I imagine it is).

magnafides
Feb 7, 2004
I love molesting 8 year old girls, their tiny little hands make my cock look huge

YouAreCorrect posted:

Questions on SCJP exam.

http://www.amazon.com/SCJP-Certified-Programmer-Java-310-065/dp/0071591060/ref=sr_1_1?ie=UTF8&s=books&qid=1280013265&sr=8-1
That is the book to get for studying; it was written by the people that wrote the certification exam. There are pdf versions of it floating around also.

I haven't taken the exam myself, but I haven't heard anyone say it was particularly difficult. Judging from the practice questions in that book, there is some "trickiness" for sure, but nothing that seems too bad.

If you look hard enough you can also find some brain dumps/actual test questions.

magnafides fucked around with this message at 00:26 on Jul 25, 2010

zootm
Aug 8, 2006

We used to be better friends.

Chairman Steve posted:

What zootm posted works sufficiently for testing (though I would always use Reflections as a last resort, in testing or production code). However, in future designs, getter/setter methods are good idea.
Yeah, I categorically would not recommend fiddling with this sort of thing except if there is no other option. For what it's worth I find getters/setters a bad paradigm as they make it impractical or impossible to use the language's built-in features for enforcing some degree of immutability, but constructor injection is definitely worthwhile.

magnafides posted:

http://www.amazon.com/SCJP-Certified-Programmer-Java-310-065/dp/0071591060/ref=sr_1_1?ie=UTF8&s=books&qid=1280013265&sr=8-1
That is the book to get for studying; it was written by the people that wrote the certification exam. There are pdf versions of it floating around also.

I haven't taken the exam myself, but I haven't heard anyone say it was particularly difficult. Judging from the practice questions in that book, there is some "trickiness" for sure, but nothing that seems too bad.

If you look hard enough you can also find some brain dumps/actual test questions.
I can recommend this book, although I do think the qualifications are a bit pointless for the individual. They're largely used by consulting/bespoke firms to put into contract bids.

zootm fucked around with this message at 12:34 on Jul 26, 2010

mfcrocker
Jan 31, 2004



Hot Rope Guy
Carrying on the search, is there any Java equivalent of ASP's WindowsIdentity, or any libraries that emulate it? I need to get hold of the Windows token for a single sign-on solution in a Vaadin app, but am having merry hell finding a pure-Java solution. I'd really rather not have to use an ASP page first.

fart factory
Sep 28, 2006

SHREK IS COOL
Is there a way to remove all text from a Java Swing TextArea component? It seems like there should be, but on looking through the documentation I can't find a method to do so.

csammis
Aug 26, 2003

Mental Institution

fart factory posted:

Is there a way to remove all text from a Java Swing TextArea component? It seems like there should be, but on looking through the documentation I can't find a method to do so.

setText(""); ?

Chairman Steve
Mar 9, 2007
Whiter than sour cream

zootm posted:

For what it's worth I find getters/setters a bad paradigm as they make it impractical or impossible to use the language's built-in features for enforcing some degree of immutability, but constructor injection is definitely worthwhile.

Definitely. I like constructor injection because it ensures that all dependencies are accounted for (assuming proper constructor...er...construction). My personal preference is to write an interface with only getters (no setters) and implement it with an object that has setters - effectively, the consumer has no idea about the setters and sees only the interface, but I'm still able to override and inject for testing. I probably should have mentioned that in my original post.

Oh, interfaces. :allears:

fart factory
Sep 28, 2006

SHREK IS COOL

csammis posted:

setText(""); ?

:ughh:

Fly
Nov 3, 2002

moral compass

Chairman Steve posted:

Definitely. I like constructor injection because it ensures that all dependencies are accounted for (assuming proper constructor...er...construction). My personal preference is to write an interface with only getters (no setters) and implement it with an object that has setters - effectively, the consumer has no idea about the setters and sees only the interface, but I'm still able to override and inject for testing. I probably should have mentioned that in my original post.

Oh, interfaces. :allears:
Immutability and representation invariants :love:

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Chairman Steve posted:

Definitely. I like constructor injection because it ensures that all dependencies are accounted for (assuming proper constructor...er...construction). My personal preference is to write an interface with only getters (no setters) and implement it with an object that has setters - effectively, the consumer has no idea about the setters and sees only the interface, but I'm still able to override and inject for testing. I probably should have mentioned that in my original post.

Oh, interfaces. :allears:

Do you name everything IFoo and/or FooImpl? That's the part of that paradigm that I hate.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."

TRex EaterofCars posted:

Do you name everything IFoo and/or FooImpl? That's the part of that paradigm that I hate.

In Java, I totally agree with you. IFoo is the language convention in C# though, so it's easy to see how you could slip into that naming scheme on autopilot.

Parantumaton
Jan 29, 2009


The OnLy ThInG
i LoVe MoRe
ThAn ChUgGiNg SeMeN
iS gEtTiNg PaId To Be A
sOcIaL MeDiA sHiLl
FoR mIcRoSoFt
AnD nOkIa

Internet Janitor posted:

In Java, I totally agree with you. IFoo is the language convention in C# though, so it's easy to see how you could slip into that naming scheme on autopilot.

There isn't convention for this which causes people to use at least these three depending on how bad the coffee was the morning they started programming:

Interface starts with I (ICarAnalogy), class name as normal. (CarAnalogy) Quite straight forward, nothing special about it.
Interface is named normally(CarAnalogy), implementation is appended with Impl(CarAnalogyImpl). This, in my opinion, is the ugliest convention. Looks especially horrible if you use common clutter words such as Factory, Processor or Service.
Interface denotes general level of applicability(CarAnalogy), class name denotes specific part of specialized implementation(WhatCarIsToCarpetAnalogy). As you can see from the example, it's very explicit which is good but it will also easily cause quite lengthy and thus horrible class names very easily.

Within Java API there isn't any hierarchies with IInterfaces but the other two can be found easily. If I had the power, I'd enforce the usage of the third option though, since it forces the programmer to think about class names for just a bit longer and usually if you can't find a good name for whatever you're doing, then you most likely have an issue with your whole architecture in that specific point of the domain model.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Parantumaton posted:

There isn't convention for this which causes people to use at least these three depending on how bad the coffee was the morning they started programming:

Interface starts with I (ICarAnalogy), class name as normal. (CarAnalogy) Quite straight forward, nothing special about it.
Interface is named normally(CarAnalogy), implementation is appended with Impl(CarAnalogyImpl). This, in my opinion, is the ugliest convention. Looks especially horrible if you use common clutter words such as Factory, Processor or Service.
Interface denotes general level of applicability(CarAnalogy), class name denotes specific part of specialized implementation(WhatCarIsToCarpetAnalogy). As you can see from the example, it's very explicit which is good but it will also easily cause quite lengthy and thus horrible class names very easily.

Within Java API there isn't any hierarchies with IInterfaces but the other two can be found easily. If I had the power, I'd enforce the usage of the third option though, since it forces the programmer to think about class names for just a bit longer and usually if you can't find a good name for whatever you're doing, then you most likely have an issue with your whole architecture in that specific point of the domain model.

I agree, I tend to prefer the third method so that I am forced to sit there and think about what I'm doing. It's definitely caused me to rethink my strategy a number of times.

Chairman Steve
Mar 9, 2007
Whiter than sour cream

TRex EaterofCars posted:

Do you name everything IFoo and/or FooImpl? That's the part of that paradigm that I hate.

I go the route of naming the interface the noun or adjective it represents ("Car" or "Driveable"), which satisfies the "is/isa" kind of relationship that an interface is supposed to be in Java. I used to do the *Impl pattern, but I've moved to the following:

  • For a default implementation that's to be used in lieu of an implementation provided via IoC, I use Default*.
  • Otherwise, I name it depending on what backs the implementation - JdbcCar, XmlCar, HibernateCar, JpaCar, etc. It describes what the object is and how it's implemented.

[ Edit: I hate the ICar naming convention. It violates the nature of interfaces, in my opinion - you don't go around naming your classes "CCar" or "CDriveable", do you? ]

Brain Candy
May 18, 2006

Parantumaton posted:

There isn't convention for this which causes people to use at least these three depending on how bad the coffee was the morning they started programming:

Interface starts with I (ICarAnalogy), class name as normal. (CarAnalogy) Quite straight forward, nothing special about it.
Interface is named normally(CarAnalogy), implementation is appended with Impl(CarAnalogyImpl). This, in my opinion, is the ugliest convention. Looks especially horrible if you use common clutter words such as Factory, Processor or Service.
Interface denotes general level of applicability(CarAnalogy), class name denotes specific part of specialized implementation(WhatCarIsToCarpetAnalogy). As you can see from the example, it's very explicit which is good but it will also easily cause quite lengthy and thus horrible class names very easily.

Bad programmer, no biscuit! Hungarian notation is terrible unless you program exclusively in notepad.

UberJumper
May 20, 2007
woop
Okay so after reading about the util.concurrent package for a day or two and playing around with it. I have grown pretty fond of how well it works, with regards to locks and synchronization. However i still have not really found any concrete example/reasoning behind "Why" was it needed. As opposed to using the synchronized keyword? I understand it scales better, but alot of the articles mention something along the lines of: "java.util.concurrent resolves several long standing issues with java threading" However nothing really follows up with explain exactly what problems it solves.

Parantumaton
Jan 29, 2009


The OnLy ThInG
i LoVe MoRe
ThAn ChUgGiNg SeMeN
iS gEtTiNg PaId To Be A
sOcIaL MeDiA sHiLl
FoR mIcRoSoFt
AnD nOkIa

UberJumper posted:

Okay so after reading about the util.concurrent package for a day or two and playing around with it. I have grown pretty fond of how well it works, with regards to locks and synchronization. However i still have not really found any concrete example/reasoning behind "Why" was it needed. As opposed to using the synchronized keyword? I understand it scales better, but alot of the articles mention something along the lines of: "java.util.concurrent resolves several long standing issues with java threading" However nothing really follows up with explain exactly what problems it solves.

The point of java.util.concurrent is that it does all the common (and some not-so-common) tasks for you with guaranteed non-breaking functionality while you can just go and code away whatever you're doing. Sure, writing your own ExecutorService isn't hard (or it may at least seem like so) but when you look at FutureTask and realize that all YOU need to do is to implement Callable and the actual task you want to perform and you still get all the possible things Executors allow you to do and pausing, canceling etc. provided by FutureTask with guaranteed behavior out of the box, you should just look smug and be happy that some people spent a lot of time so that you wouldn't have to.

As minor trivia, java.util.concurrent is the base package for multiple other JVM languages which deal with concurrency. These languages include at least Clojure and Scala which bot actually just wrap Executors for most of the concurrent structures they have.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
How come something like this works:
code:
public static String[] test() {
	String[] stuff = { "stuff" };
	return stuff;
}
but this does not:
code:
public static String[] test() {
	return { "stuff" };
}
(not that I want to use it, just curious)

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
No good reason. You can use array-literal syntax, though: new String[]{ "stuff" }.

Parantumaton
Jan 29, 2009


The OnLy ThInG
i LoVe MoRe
ThAn ChUgGiNg SeMeN
iS gEtTiNg PaId To Be A
sOcIaL MeDiA sHiLl
FoR mIcRoSoFt
AnD nOkIa

rjmccall posted:

No good reason. You can use array-literal syntax, though: new String[]{ "stuff" }.

The reason is (most likely) that
code:
return { "stuff" };
doesn't define the actual object type of the array. Object[] os = { "1", 2 }; is after all just syntactic sugar and Java likes to care about the left side of the assignment a lot.

Adbot
ADBOT LOVES YOU

RitualConfuser
Apr 22, 2008

Parantumaton posted:

The point of java.util.concurrent is that it does all the common (and some not-so-common) tasks for you with guaranteed non-breaking functionality while you can just go and code away whatever you're doing. Sure, writing your own ExecutorService isn't hard (or it may at least seem like so) but when you look at FutureTask and realize that all YOU need to do is to implement Callable and the actual task you want to perform and you still get all the possible things Executors allow you to do and pausing, canceling etc. provided by FutureTask with guaranteed behavior out of the box, you should just look smug and be happy that some people spent a lot of time so that you wouldn't have to.
Having to deal with someone else's half-assed implementations of concurrency "patterns" are really the best way to learn why java.util.concurrent is so useful. Regarding UberJumper's question, this is kind of a a non-answer but, couldn't the same be said about a lot of libraries after only using them for a couple of days? That is, at first, the reason why they're so useful may not be readily apparent. After some experience with them, you learn the pros and cons of the solution and gain some insight into the core problems that are being addressed.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply