Lennie De Villiers

Greenhorn
+ Follow
since Jul 17, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
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 Lennie De Villiers

So I did my SCJP 6 exam... Now I prob need to re-do this since its not Sun anymore but Oracle... I tried to look around for a OCPJP book but can't find anything.
I also want to study that is in my career goal since currently am a Android mobile developer (also do abit of iOS)

Can anyone please direct me in the proper process etc?
Hi,

Can I use Netbeans on Mac OS X to development J2ME MIDP applications?
9 years ago
Hi,

If you can't use the design pattern because of the following 2x reasons, what can you do?

- Can't sub-class because the class is marked final.
- Can't use an interface because its a 3rd party library or you don't have the source.
Hi, I've got a multi-core machine (2.5GHz x 2) how are threads handled in the JVM in this case? Are they parallel?

Thanks
Hi,

The Thread class expect a run() method (no arguments), but how can I let it call a overload method? like run(MyClassName aClass)

Regards,

Lennie
Yes the priority of how threads are executed, the book say that JVMs might implement it differently per JVM... but my question is that they all should actually have the same implementation right?


M M kaimkhani wrote:if I'm not wrong you are talkin about time slicing?right?

well schedulin/time slicing is depend on processors/memory.
obviously scheduling mechanisms will be different on single processor machine rather than multi-processor machine.


hth

Minhaj

Hi, I read in the certificate book that JVMs might have different scheduling mechanisms. Doesn't Sun make sure that there is a standard to how a JVM must be implemented to prevent such problems?
Hi :-)

6 months away from my exam...
Each chapter in the study book end with a 2 minute drill, can I download study cards for them somewhere? Don't want to re-invent the wheel.

cheers

Lennie
Hi,

What is the benefits of having a try... finally block only (no catch clause):

try
{
// whatever
}
finally
{
// cleanup
}

To me it never make sense to have one since the code will execute as being the same without the try block.
Maybe readability? Another developer can see that some cleanup is done?

Thanks

Kind Regards,

Lennie De Villiers

Hi,

I'm a professional Java developer with 4 years experience available for remote freelance work.

Experience: Java 6, Java 3rd party packages, Eclipse, Netbeans, J2ME, Tomcat, Orion, mySQL/MS SQL Server

Location: Cape Town, South Africa
For a free quote email: capriconsoftware@gmail.com
12 years ago
Hi,

I've got the following sample program where you can provide it a link to an MP3 file, it must them stream the file.
But once I select the link it doesn't play, please advise.

Program:

import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import javax.microedition.midlet.*;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import java.io.InputStream;

public class PlayerMIDlet extends MIDlet implements
CommandListener, PlayerListener, Runnable {
private Display display;
private Form form;
private TextField url;
private Command start = new Command("Play",
Command.SCREEN, 1);
private Command stop = new Command("Stop",
Command.SCREEN, 2);
private Player player;

public PlayerMIDlet() {
display = Display.getDisplay(this);
form = new Form("Demo Player");
url = new TextField("Enter URL:", "", 100,
TextField.URL);
form.append(url);
form.addCommand(start);
form.addCommand(stop);
form.setCommandListener(this);
display.setCurrent(form);
}

protected void startApp() {
try {
if(player != null && player.getState() ==
Player.PREFETCHED) {
player.start();
} else {
defplayer();
display.setCurrent(form);
}
}
catch(MediaException me) {
reset();
}
}

protected void pauseApp() {
try {
if(player != null && player.getState() ==
Player.STARTED) {
player.stop();
} else {
defplayer();
}
}
catch(MediaException me) {
reset();
}
}

protected void destroyApp(
boolean unconditional) {
form = null;
try {
defplayer();
}
catch(MediaException me) {
}
}

public void playerUpdate(Player player,
String event, Object data) {
if(event == PlayerListener.END_OF_MEDIA) {
try {
defplayer();
}
catch(MediaException me) {
}
reset();
}
}

public void commandAction(Command c, Displayable d) {
if(c == start) {
start();
} else if(c == stop) {
stopPlayer();
}
}

public void start() {
Thread t = new Thread(this);
t.start();
}

// to prevent blocking, all communication should
// be in a thread
// and not in commandAction
public void run() {
play(getURL());
}

String getURL() {
return url.getString();
}

void play(String url) {
try {
VolumeControl vc;
defplayer();
// create a player instance
HttpConnection conn = (HttpConnection) Connector.open(url, Connector.READ_WRITE);
InputStream is = conn.openInputStream();
player = Manager.createPlayer(is,"audio/mpeg");
player.addPlayerListener(this);
// realize the player
player.realize();
vc = (VolumeControl) player.getControl("VolumeControl");
if(vc != null) {
Form v = new Form("Playing Audio...");
StringItem si = new StringItem("Status: ",
"Playing...");
v.append(si);;
display.setCurrent(v);
}
player.prefetch();
player.start();
}
catch(Throwable t) {
reset();
}
}

void defplayer() throws MediaException {
if (player != null) {
if(player.getState() == Player.STARTED) {
player.stop();
}
if(player.getState() == Player.PREFETCHED) {
player.deallocate();
}
if(player.getState() == Player.REALIZED ||
player.getState() == Player.UNREALIZED) {
player.close();
}
}
player = null;
}

void reset() {
player = null;
}

void stopPlayer() {
try {
defplayer();
}
catch(MediaException me) {
}
reset();
}
}

12 years ago
Hi,

What is the book to get for the SCMAD exam?

thanks

Lennie De Villiers
Hi,

What is the difference between parseXXX and valueOf in the Java primitive types wrapper classes?

Thanks

Lennie
Oops i got it wrong, an interface can't implement another interface (not even one) but can only extend another interface or more then one interface.
This is where the confusing come in where an interface vs a class.
Hi,

What is the difference between an interface extending (extend keyword) one or more interfaces vs implementing (implements keyword) one or more interfaces?
I see that the concreate class that implement the interface (wherever in the inheritance tree) need to anyway implement all the methods from all the interfaces extended or implement.

But is there a reason why I would rather extend and not implement an interface on an interface?
Doesn't make sense to provide both features in Java.

thanks