Andrea Binello

Ranch Hand
+ Follow
since Oct 30, 2013
Andrea likes ...
Eclipse IDE Spring Java
Senior Java developer
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 Andrea Binello

Richard Hayward wrote:
Could anyone point out my error here?

You need Please, see the official javadoc or here (end of page).

If you don't know these aspects of generics, it may seem a bit weird at first ... yes, you need a subclass (an anonymous class in that case) in order to have a full representation at runtime of a List<Something>. ;)
4 years ago

Ryan O'Mara wrote:

Sorry, your approach to painting is wrong.

Please study how painting works in Swing: Lesson: Performing Custom Painting
4 years ago

kennith stomps wrote:

You cannot do this, the x variable is not yet initialized and cannot be passed to getMenuOption before.
4 years ago

Alexander Maximilian wrote:

This is valid because objArr1[i] is an Object and an int[] (1 dimension) IS an Object .

So you could do:
Object e = objArr1[0];

Alexander Maximilian wrote:

This is NOT valid because objArr2[i] would be an Object[]. But an int[] is NOT an Object[] .

Alex Houser wrote:In the real world I could use multimap directly, but that isn't an option here.

If you have a plain map (from Java SE framework), a key is only associated to one value. Not more. However nothing stops you from having a kind of collection as the value.

Say for example a HashMap<String,List<Integer>>

Converting this map to a Guava multimap is rather easy.
4 years ago

Alex Houser wrote:Has anyone here loaded guava into NetBeans?  I tried and I can't get it to work.  There wasn't much info online so I'm hoping someone here can help me out.

The IDE used (Eclipse, NetBeans, etc..) is only partially relevant. What is important is what build system is used. If your project is Maven based, you only need to add the dependency on Google Guava (see on And that's all.

If it's not Maven based, please, clarify what build system you are using.
4 years ago

Prabhash Mishra wrote:But in jax-rs jersey i was able to do it using exceptionmapper class.There using HAETOS i was able to make json link clickable but in rest spring i am not.

Sorry but your statement is meaningless. A JSON is a text file. You don't "click" on the elements of a JSON ..... unless the browser renders the JSON in some way, either due to some installed plugin (in the case you have directly opened the JSON) or due to some Javascript manipulation in a web page (in the case the page gets the JSON using AJAX or other tecnique).

So please, explain who and where is using that JSON.
4 years ago

Mahar Qureshi wrote:It is complicated indeed because it would be a desktop application and should know every print command from any application.

You cannot detect print operations in other applications (either Java or "native"). Not in general and not without knowing something very specific about an application.

You may eventually interact with the print spooler. On Ms Windows the Win API has the Print Spooler API Functions. But these are "native" functions that are normally used by C/C++ applications. So you should be very well versed on C and/or C++ and on how to invoke these functions from Java using the JNI (Java Native Interface) specification or at least using the JNA library. And this is definitely not a thing for beginners/newbies.

And on another Operating System (e.g. Linux) the printing system is certainly radically different. At this level (printing, print spooler, etc..), unfortunately there is nothing really "standard" about APIs, environments, etc.

If you are a beginner, honestly, please choose another more reasonable project.
4 years ago

srikant nair wrote:Why do we need an instance of test1 for invoking testlab constructor

The c is an instance variable (it's not static and not even local to a method/block). Instance variables belong to objects. Each Test1 object has its specific, distinct c instance variable.

If you don't have an object of type Test1, you don't have that instance variable c. And this means that the initialization c= new TestLab() does not happen.
And there is no new Test1() in your code.
4 years ago

srikant nair wrote:TestLab c= new TestLab();

In the output why the constructor of TestLab is not called ?

Do you see a new Test1() somewhere? ;)
If you don't have an instance of Test1 ... you don't have an instance variable c (and thus c= new TestLab() is never executed).
4 years ago

Sucheta Shrivastava wrote:

The "empMap" is wrong.

is syntactically correct. (Employee must exists somewhere, obviously)
Note also that public on method is optional. Interface methods are always (implicitly) public.
4 years ago

Knute Snortum wrote:I think they mean every print command in the Java app

Ok but .... if it is a "desktop" application (now it doesn't mind if Swing, JavaFX, etc..) what is the meaning of "detect"?

If it is a desktop app, you developer provide a button, menu, etc to start a print. So you know when a printing is about to start .. there is nothing to "detect".
4 years ago

Mahar Qureshi wrote:2. Detect every print command

What does it mean for you? Which print commands? Of all the applications in the operating system? E.g. you open Notepad on Windows and print a text file and you want that your Java application intercepts this print? This sounds very very complicated because if it is really possible, it certainly cannot be done in "pure" Java.
4 years ago

Rhea Camille wrote: I am reading about IO and I'm confused what does it mean of binary data and byte data? How can I create one?
And also about Byte Streams and Character Streams. Let's say I have a MyFile.txt that is 2KB.

For Character Stream, does it mean if I have a file, it would read, string by string OR character by character?
It can read as "Hello" "World" or 'H' 'e' 'l' 'l' and so on...

How about the Byte Stream?

A "binary file" (or more generically "binary data") is a sequence of bytes that is not readable/meaningful for humans. If you use Notepad (or other text editor) to open a .exe/.dll on Windows, you will see tons of strange and not meaningful characters. This is because exe/dll are "binary" files. They are not text files. The sequence of bytes in an exe/dll respects a very detailed file format specification that also contains code for the CPU. As I repeat, this is not "text" readable by humans. In an exe/dll you may see meaningful text strings, because applications also have and use text informations.

On the other end, there are "plain" text files. In these files, all the bytes represent "characters". But 1 character does not necessarily mean 1 byte. This depends on the "character set". There are many character sets: ASCII, ISO/IEC 8859 (with its variants), Unicode, etc. So 1 character may be represented with one or more bytes, depending on the character set and (eventually) its specific encoding (e.g. UTF-8 is an encoding of the Unicode character set).

In Java XxxInputStream/XxxOutputStream are byte oriented. In general, they don't know anything about the meaning of these bytes. This is up to you, depending on what you know and you do with these bytes.

In Java XxxReader/XxxWriter are character oriented. They know how to read/write characters (not bytes). However, as stated above, 1 character may use one or more bytes. So at a certain point you need to have something that explicitly (or implicitly) "knows" how to convert between characters and bytes.

InputStreamReader/OutputStreamWriter are typically used for this. However there are other I/O classes that deals (explicitly or implicitly) with character sets/encodings.
4 years ago

Rhea Camille wrote:Could you please also explain to me the difference of thread vs process

A process is an instance of a computer program (which is an application installed somewhere on your machine). If you have e.g. Ms Win, locate the shortcut to the "Notepad". Notepad is an application. If you launch Notepad you have a process, an instance of Notepad. Launch again Notepad and you have *another* process.

A thread is a "flow of execution". It is the sequential execution of some code using a single processing unit (on modern CPUs a certain "core").

A process has at least one thread but may have more. All threads share the same memory address space of the process. Threads are normally scheduled by the Operating System.

Hope I have cleared your doubts. ;)