Liutauras Vilda

+ Follow
since Nov 12, 2014
Liutauras likes ...
software developer, moderator at coderanch, a father, husband and nintendo switch owner
London, United Kingdom
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Liutauras Vilda

While Salvin's solution seems closest (at least for now) to what OP described, but I tend to agree with Norm.

@OP. Imagine you go through thousand of directories and all of them look empty except one. Why such efforts to put on user?

If you could narrow down the area enough where such templates possibly can be, your program probably would be much more useful if would find all existing templates and would give an ability for user to choose a needed one at a given point in time.


v1  c:\documents\templates\v1\Sample.txt
v2  c:\documents\templates\v2\Sample.txt
[select] [cancel]

The appended version number at the beginning could be extracted from the Path object.
3 days ago

Roger Wells wrote:The file may be in any directory on the system. There maybe be many text files in the directory. So wherever the file is I want to make sure they get the correct one.

Is there a way to find just Sample.txt ?

The correct one is only one you said - "Sample.txt".

If your goal is to open the file X, and that X you know, and user needs to select that X and nothing else - why do you want to involve that selection process, I don't get that part.

Maybe somebody else understands what you want as I don't - sorry. I don't get maybe because of tired, been hard day.
3 days ago

Roger Wells wrote:In line 5 I want to have something like "Source Template", "Sample.txt" and only those text files will be highlighted and selectable.

In line 5 you are using FileNameExtensionFilter. "Sample.txt" isn't an extension. Extension is what is after the last . (dot). In your case it is "txt".

Anyway, you can have at most one filename Sample.txt in the same file system directory. Why do you want to filter Sample.txt only? If you want user to select such file, just assume user selected that if that's what you want.

Not quite clear to me actually, what exactly you want. Concrete examples maybe with 3 random filenames?
3 days ago

Dipen Kadecha wrote: i want to know the logic behind this like how it's happening.

Can you be a bit more specific, what's in particular happening?

shalini marimuthu wrote:

1. Why you call variable "shalini" and later trying to explain in a comment what it actually is, while you could call it right away what it represents?

2. Fix indentation and formatting - important.

3. Create separate methods for converting number to particular bases, i.e.:
base10ToBase2(...); base10ToBase8(...); base10ToBase16(...);

Start small. Start creating method to convert to base 2; Make it work, test it on various inputs; once you happy, put it aside and work on other base;

When I solving these kind of puzzles I'm taking apart problem into small pieces and solve them individually - then combine them into a whole picture. The advantage is, that you don't need to think about 4 levels of nested if's; else's; for's;

Basically, once you catch yourself nesting loop - you can create a method which represents a more concrete task.

At least this is what I'd do. As an extra what I'd do, I'd delete what's created already and start over. In most cases than not at the beginning it is a better approach than desperately try to fix things over.
4 days ago
Thank you. You'll have to take care of cattle
Please explain what is the difference between:

Stream.of(inputString.split(" "))
vs" "))

And why did you choose one over another in your blog post?
Read carefully Henry’s post which is one before the last one he posted, he explained there couple of scenarios. Try one or another, you should be able to nail it on your own.

One thing, when you say your classpath is set to c:\temp, can you please show some evidence how you achieve that?
My suggestion seem to have flaw, I thought it is about changing one chatacter, while actually there is about changing all occurences of character to something else. Regardless, there are native string methods to do that for both cases.

But OP seems gets training on loops, so all fine.
1 week ago
If you want to discover other possible solution to this problem, try to use indexOf() and substring() methods in order to come up with a solution of 2 lines. That looks to me much easier.
1 week ago
I don't know your setup, but I can try to explain in my words, so you could try to re-assemble problem solution on your side.

Let's go from the beginning.

There is a file system's directory structure and Java's package structure. That's one. Note, structure I've made it slightly more complicated than it actually could be.

Second is, that to an end-user they both look the same (and in fact they are), if you open some file explorer and look to two let's say directories "aa" and "bb", you couldn't say if one of these directories play any role in an existing (any) Java source file.

Let's say currently you are in the directory "Documents" (navigated through either command-prompt in case of Windows, or terminal in case of UNIX flavour system) and you have such setup:

Class A looks like:

Class B looks like:

So, what is important to know. You have at the moment only source files, you don't have them compiled yet. As you see, class A doesn't appear to be in any user's defined package (so it is in default/no-named package). Contrary wise, class B is in a package io.github.liutaurasvilda

Remember from earlier, that Java package and file system's directory looks same if we were to talk about the directories (or for other people maybe easier to understand - folders).
And if you look once again now how the source files are located in the file system currently, you'd notice, that there is missing mentioned part "io.github.liutaurasvilda", this is what class B has as its package.

So, after you compile your B class's source file "", your compiled file "B.class" must reside in:

or if you look at it as tree structure in your head (ellipsis mean "could be anything"):

Now. The classpath is, where to look for *.class files EXCEPT its package structure. That means that Java knows how to find class files once you show to it, where classes package is located.

So let's assume I compiled my both classes, class A has no package statement, class B has as specified above, so I currently am in the Documents directory, so what I supposed to end up with is:

When you compile classes which contain package statements, you can tell compiler to create packaging structure if it doesn't exist on file system already, and that could be done as next..

In case you are in Documents direcotry:
javac -d temp temp/

In case you are in Documents/temp directory:
javac -d .

(note: . means present working directory)

Once you do that, in your directory Documents/temp the directories /io/github/liutaurasvilda appear along with B.class file inside.

So, you got compiled all stuff and once again, you have:

Now you want to run Java program which's starting point is class A. How you do that. Currently you are in directory Documents.

;  <-- classpath separator in Windows
:  <-- classpath separator in UNIX flavour OS

The . means, that look for classes in present working directory (meaning in /Documents), and temp means, that look for classes in /Documents/temp, documents get assumed because you are in Documents when issuing such compile instruction.

In case class A also had package statement let's say liu.test, then in an execution instruction you'd need specify class name along with package name, such as:

If you can't re-assemble solution, please show exact structure where your files reside and please show us what instruction you issue from your command-prompt.

A Lauran wrote:duck.quack();                   // DOES NOT COMPILE
System.out.println(duck.noise); // DOES NOT COMPILE

That's correct.

Because you are calling method which is private to FatherDuck class, same as noise variable is private to FatherDuck class, that means only FartherDuck class can use them while you trying to do so from BadDuckling class.
Light google search and results (<-- click) are pretty much in the very first 2-3 links.
1 week ago