Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!

Andrey Kozhanov

Ranch Hand
+ Follow
since Mar 12, 2010
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
11
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Andrey Kozhanov

No idea why you do have "holes" in the song - usually sending a file as byte array leads to recieving it "as is", even if to send it "in chunks".

But if you do not want to save it to disk, you could try to use ByteArrayOutputStream to store it in memory until recieving the whole file and then get it as byte array via toByteArray() method. It is much better then creating new byte array for every file chunk.
Why use such complicated way for sending a file? Why not just send byte array directly? Such approach worked fine for me, without any data loss.
6 years ago
Just use another JTextField constructor - JTextField(String text), where text contains initial text field string, or JTextField(int columns).
6 years ago
We can. Use Graphics2D.drawRenderedImage function.
6 years ago
General approach to GUI creation: ANY task which might be time-consuming should be performed via javax.swing.SwingWorker.
Your problem is on line 90: g2.drawRenderedImage(m_ScaledImage, at);

Timing shows that it took about 0.5 seconds to complete. paintComponent method is triggered every time you do something in application window, that's why you have 0.5 seconds delay for every operation. So looks like you should either remove background picture or have a set of different size pictures or use some other technology for drawing. Maybe you would find something useful here: http://fivedots.coe.psu.ac.th/~ad/jg/ch045/index.html
6 years ago
Things to check:

1. Did you put image.gif into your jar file?

2. Is there a new line symbol after last line of your manifest file?
6 years ago
Vijay is right, the code you provided will indeed fail in runtime with NullPointerException. But if you change variable c to be static (on line 12), it will be initialized on line 17 and answers will be indeed C and E.

Two new threads are started on lines 18 and 19. We don't know which one will actually start first, so right answer could start with any thread ID (in our case 2 and 4). But we have only two threads, so only two thread IDs, that's why answer B is wrong. Neither thread is daemon thread and neither thread is interrupted in any way, so yack method will be executed in full, i.e. will output thread ID two times, that's why answer D is wrong. Thread.yield() on line 7 will pause current thread to allow other threads to be executed, but yack method is synchronized. That means it could be rewritten as follows: I.e. only one thread could call yack method of the same instance of Chicks class in the same time. With changes to line 12 i proposed above we will have single instance of Chicks class, i.e. both threads will be executed one by one. Considering that we don't know which out of two our threads will actually start first, right answers are C and E.
6 years ago
It has. And what's the problem with not being visible in the api? You can't create Math instance in any case.
6 years ago
It is set in HashSet documentation:

This class implements the Set interface, backed by a hash table (actually a HashMap instance). It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time. This class permits the null element.
6 years ago
Just think about it. Static block is executed during class initialization, and you cannot initialize a non-static inner class without having an instance of the enclosing class, that's the reason.

if the variable is static final then it compiles fine


That's not exactly true. According to specification inner classes may not declare static members, unless they are compile-time constant field. Consider the following code:
6 years ago
6 years ago
Look at your path. You declare Test1 class to be in com.test package, that means class file should reside in /com/test folder. But your class is in tmp folder. That's why you got this error. So either remove package declaration from your file or put it in the right folder.
6 years ago
Common way to solve such problems is to use java.util.Observable/java.util.Observer pair.
6 years ago