Matt Wong

Ranch Hand
+ Follow
since Aug 18, 2017
Matt likes ...
MS IE Notepad Suse
Cows and Likes
Cows
Total received
4
In last 30 days
1
Total given
0
Likes
Total received
7
Received in last 30 days
3
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Matt Wong

use javara to remove all java runtimes and then re-install only one
6 hours ago
int x=y/2;
if(x==0||x==1)
//...

This will always be true for positive y, as you can get only 0 or 1 when dividing by 2 and your if checks for either of them (your if: (is x equal to 0?) [logical OR] (is x equal to 1?) - wich is effectively: is x either 0 or 1 or both - but as x cannot be 0 and 1 at the same time, it comes down to: is x 0 or 1? - and as you devide by 2 wich always return 0 or 1 for positive numbers - your if will always partial true - and anything partial true using OR becomes effective true for the whole statement).
6 hours ago
Well, another approach: Why do you think it shouldn't be possible the it is?
Everytime you ask yourself, why something is or has to be the it is/has to start your very first step with: Why not?

Real-life example: Most tires are round. Why?
First step: Why not? - Could there be any reason a tire should have any other shape? You very easy come to the awnser, that it's not useful to shape a tire any other but a circle - even if it's possible. Then you can start to examine, why it's not useful to build a tire with a different shape. And the more examples you can find, the more it becomes clear to your first questions, why tires are those round objects they are.

So - back to Why java.io.File/Reader/Writer is a subclass of java.lang.Object: well, first: someone once decided so. second: there is no limit like package-boundary. For a class to be extented it only has to be visible and has not to be final. On the other hand: well, all this stuff with packages would make no sense when java was designed the way only classes in same package can inhired each other.
4 days ago
first: get rid of applets - they're dead
second: the code you posted doesn't make sense in any way
third: there's a loop and sleep inside a method run in EDT - a gui no-go - in any language
Maybe you should try to re-phrase what you want to accomplish so we can try to help you in some usefull direction.
4 days ago
Well, if you want early 90's old skool "pseudo-gui" style (I will refer to this as DOS as on linux there was/is n/curses) use a monospace font. I guess your "it doesn't match up" comes from using a font with variable character width. Back in ASCII days your typical DOS or linux console had a fixed width font style where each character is the same size, basically to match 80x24 character resolution.

Otherwise I would recommend drawing a uniform border around the text instead of trying to make one out of border-characters.

Matt
6 days ago
the difference is that a List is a mutual object - so it's something wich contents can be altert

java is always pass by value

why? think of your List as a box wich is stored in a shelf
when you call your methods you're not passing around the box itself but only the information where to find the box in the shelf

so when someones throws something in the box it is this very one box you created before

your example goes like this:

you create a box - put something in it - store it somewhere - later you give the information where to find the box to someone else - who doesxsomething to the box - and later you come back to examine the contents of the box

at no time you create a second box
2 weeks ago
Hm, I guess I have to express myself a bit more precise: Why would someone use such complicated stuff instead of just using a==b?
Also: My guess is, no matter how one would write such lines - I guess the compiler would simplyfi and optimized it anyway (not tested) and therfore it doesn't make sense in the first place to write such code as it would never run that way after JIT (wich most likely opitimize it down to some cpu instruction like storing both values in two registers, compares them and then does a conditional branch like "bz" (branch if zero) or "jez" (jump if equal zero)).

Even if this isn't java but some other language - but I guess any high-level language wich has something like "ArithmeticException" expressing a "divide by zero"-error has also a shortcut like a==b wich should result in the same result. I simple just can't come up with a reasonable explation for writing such mess. Maybe there's something more to it I just don't know about modern high-level languages.

Also: As the parameters are typed as ints - there is no such thing as to worry about floating-point im-precission as ints by definition - well, are integers - wich means a whole real number without fraction.
So - I've read this:



Yes, I know this comes down to "divide by zero" - but: WHY? I thought I'm smart about maths (held record for 4 years not getting a single B but all A) - but what's the magic behind this abusing of Exception? Is there really any difference than "return a==b;"?
2 weeks ago
Thanks so far, but I guess my field is way different than servlets and application servers.

In my case it's a centralized x509-certificate based authentication system. In fact, it doesn't matter how many users are connect to my service, as authentication and access privileges all managed by javas built-in ssl-stuff. The only thing I use the database for is to keep track of users, thier certificats, revocation-status (wich is used to create CRLs once each night) and contact-information plus some other stuff for identity automatic certificate re-newal. It's a management back-end only used by administrators. There is no user-interaction with it, cause there're no data stored i  database a client-connection relies on.

I do understand the pooling in servlets and app-servers - but for my code it's a few administrators and a daily cronjob. Maybe the one who suggested DatSource to me didn't understood this.
So, to keep it short: as I recently published some code using database some suggested to me to use DataSource instead of DriverManager. I thought to give it a try and looked at some examples, but the only difference I found was on how the Connection object is created. Also I read some on Google that using DataSource is the preferred way of doing so. I guess this was already asked, but the didn't got me something useful.

What's the main advantage of using DatSource over DriverManager? Yes, I've read something about connection pooling and distributed transaction, but I don't use these.

In my code I have a single master server instance wich only uses one connection and all queries are synchronized. I can't see any advantage using DataSource. Maybe could give me some hint?

Matt
C:\Users is a system-directory - so you need to run your code as privileged user with elevated administrative rights to write to it - as for any other system-directory. The reason you can use it on your system is cause your user account is marked as administrator, so you have system-wide access.

Best option: System.getProperty("user.home") wich returns absolute path to user home directory C:\Users\username - also it's system independent and can be used on linux.
Next: don't use a file but rather os-stuff with Preferences - wich gets stored in registry on windows - and I guess in a file in ~/.local/ or some similar on linux - not sure.
1 month ago

Micheal Bush wrote:No, man, that is not problem, problem is I assign a object to a new object, so it can not update the original one.


Well, aside from that's pretty rude, it sounds like you're asking us to solve your problem instead of help so you can fix the issues yourself.
Ok, so, here you have one possible solution to your problem: If you don't want to learn don't bother to try to implement it yourself but use java.util.LinkedList instead. Otherwise, it would be a good start to try the adviced: Take the code aside for now - try to write down what you want to do in your own words - then describe each single step with a small block - and THEN try to implement these steps one-by-one.

We're here the help you to learn so you can fix your issues yourself - not to solve your problems.
1 month ago
maybe an addition to your own solution when windows-users isn't what you end up with: instead of making the whole application available to specific users or not, you still can limit write-access to an administrator

it sounds the workstations are in a windows domain anyway, or at least there has to be on centralized place where your 'user-file' is reachable from anyone want to use your application - so as anyone can read the file to determine if access should be granted to some credentials - you can simply restricted the write-access to only administrative users trusted to manage this user-file

it's just shifting what's available - but manage write-permissions is usually easier then overall access permissions
1 month ago