Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!

fred rosenberger

lowercase baba
+ Follow
since Oct 02, 2003
fred likes ...
Chrome Java Linux
St. Louis
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 Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt Green check

Recent posts by fred rosenberger

I haven't looked too closely, but couldn't you use some nested if statements?

even further, couldn't you "normalize" you text and TargetName outside your loop?  
normalizedText = text.Trim().toLowerCase()
normalizedTarge = TargetName.trim().toLowerCase();

and then just compare them once?  Note: i am sure I don't have that syntax exactly right...just trying to illustrate the idea.
2 weeks ago
You can spend days or week optimizing stuff, and in the end, you save the user 0.1 milliseconds (or whatever).  so users would have to run that millions of times before the cost is offset.  Is it really worth it?

and then let's not forget that in six months, or two years, someone will have to come back to that code and re-work it.  If your optimizations are "clever", the code becomes harder to understand and debug.

How efficient is efficient enough?  unless you have a documented target, you will never be done...someone can always ask for it to be faster.

Would you be better off spending money on faster computers/routers/other hardware?  
2 weeks ago
My advice:

First, turn off your computer.  Seriously.  do not write a single line of java until you can tell us in English how you'd do this.  You gave an example, which is fabulous, but you need to think about how to generalize the case.  You need to be able to give directions to a young child exactly what they should do in every case.

So, given a string of some arbitrary, unknown length, what is the first thing you need to do?  you say you need to split it in the would need to find the middle.  But before you can find the middle, what do you need to know?  How about the total length of the string?

Once you know the middle, what do you do? and so on.  you should literally write these steps out on paper (or notepad, or something), but actually writing them down, revising them, and simplifying them is critical at this point in your programming career. I know you want to start writing code - after all, you're trying to learn to code...but the secret, and the hardest single thing to learn, is that coding is 90% THINKING, and only 10% TYPING.  

The second hardest thing to learn is to break down your ideas into teeny, tiny parts, only code the smallest amount you can, and then compile and test it.  Write a lot of throwaway code to validate what you are doing, then throw it away later.  Skip over parts and write dummy code - i.e. if you just want to work on the splitting, don't bother with getting input from the user, just temporarily hard-code a string to use.  You want to separate the GETTING of the string from the PROCESSING of the string.  the code that processes the string does not care how you got it.  The code that gets the string does not care how you process it. These should be separate methods that get called.
2 weeks ago
i'll admit i have not used streams all.

But my interpretation is that they are much like piping together commands on a unix shell.  the output of each stage is passed as the input to the next...something like

ps -ef | grep MatchProcess |  cut -b 1-20  > myFile.txt

the output of the ps command is fed into grep, and that output is fed to cut, which is then written to a file.  there are several stages where the data is ephemeral as it works its way through, until at the end it's written to the file.  

Please correct me if i'm wrong.
2 weeks ago

Tim Holloway wrote:using backslashes in file paths is a sure indication of Windows infection.

Such is my curse.  I have to go back and forth between Windows and Unix all day long, and always get them backwards (or forwards...depending..)
3 weeks ago

gong tji wrote:
Do you have advice to keep eyes still healthy?(at least decrease chance to increase myopia).

Optometrists recommend the 20/20/20 rule.  Every 20 minutes, stare at something at least 20 feet (6 meters) away for 20 seconds.
3 weeks ago
I am not a Mac person, so i can't be much help...

where did you save your file named ""?  Since folders can be in folders which can be in folders, the full path means every single one, all the way up to the top level.

a "relative path" means relative to where you are currently.  I believe the mac OS is linux based.  so if you are on a command line (or whatever it's called in Mac-land), you can type "pwd" for "print working directory".  it will tell you what folder you are currently in.  if you have a directory like :

and your PWD says you are in SubDir1, then the relative path would be "go up one level, then go down to SubDir2, Down to SubSubDir1, and then find Party.Java". in linux speak, that would be "..\SubDir2\SubSubDir1\"

The Full path would be "\TopDir\SubDir2\SubSubDir1\".  The full path will always work, no matter what directory you are in, but the relative path changes depending on where you are.

Hope that helps a little...

3 weeks ago

Suane Mane wrote:That is good advice when trying to actually learn coding and when time is on your side and everything is fine. However, I didn't have the luxury of any of that at the time. Hopefully soon before actually graduating I can properly learn.

Thanks all for the answers. I did manage to figure out assignment after all.

Glad you figured it out.

I would argue, however, that following the method I described actually SAVES time.  In my opinion, this is the hardest single thing to learn in programming. I struggled with it when I first learned, i've read scores of posts of other people saying the same thing...

When you are learning, you think that writing code is just that - writing.  I believe that coding should actually be about 90% thinking, and 10% typing.  With more practice, you can think through things faster, and the ratio shifts a bit, but not much.  By thinking through it first, you make fewer mistakes, find bugs sooner, and fix them easier, thus in the end reducing your total time spent working on the project.
3 weeks ago
That's a hard question.  Part of the problem is that different people will react differently to how you speak. I work in a large, international corporation.  I  routinely speak to people from (and in) different countries than where I was raised. I'm from the USA, but I work with people from India, China, Ireland, the U.K., Belgium, Singapore, Nepal...,  Cultural norms vary drastically, and what one person sees as assertive, someone else sees as bullying.
3 weeks ago
I would suggest you stop writing code.  slow down.  back up a bit.

Programming is really 90% thinking, and 10% typing.  (Some may disagree on the exact percentages <cough><cough><Campbell><cough><cough>).

I try to never write code until i've thought through the problem A LOT.  What do i really want to do?  When do I want to do it?  What is a good way to accomplish my task?  What is the MINIMUM amount of code I can write to add value to what I want to do?

Assuming your ArrayList is populated, start by JUST printing out each value in the list.  Once that's done, try only printing values greater than the minimum.  Once that works, add in the condition to not print the maximum.

If you look at your current code, you have a loop that iterates the same number of times as there are elements in the list, but you don't actually look at the elements in the list.  Then, if there were 30 elements in the list, you'd print out your error messages (potentially) that many times.

Consider writing lots of small methods.  write a method to get input.  Write a method to validate input. Avoid hard-coding values in the middle of your code.  Define a variable like "final int upperLimit = 9", then use that variable in your code - that makes it easier to update later, when your specs change.
3 weeks ago
I try to take a multi-vitamin once a day.

I walk my dogs twice a day, which gets me a little exercise, but not much.  
3 weeks ago
So what is your actual question?  

I would suggest you change your variable names....'p' doesn't mean a lot...'principle' is a lot more clear to someone who sees your code for the first time.
3 weeks ago
Welcome! We're glad you came by.  Feel free to poke around, answer some questions, or ask a few yourself.  Everyone here is rather friendly, and you'll find we enjoy discussing programming in all its forms.
3 weeks ago
I agree with Tim.  After all, if they said "tell me about a project you worked on", would you talk about your hobbies?  
4 weeks ago

Erion Maxhari wrote:Yes they are just an example. The output is needed with headers, and there are only 10 sub records.  I have a class for parsing the records, and a method for each of the sub records. The problem i don't know and i am unable to hold records 000, while I put next other records.

I would define a class called DataRecord that holds a parent record, and then a list of child records.  As you parse the file, each time you come to a "05**000" line, create a new instance of a DataRecord and add it to a list or collection.  if the next line is not another "05**000" line, it is a child record of the current DataRecord, so add it (your class would have to have a method for adding a new child record).

When you are done parsing the file, you can iterate through your collection of DataRecords, printing each out (and print the header first, of course).
1 month ago