java

LBYL vs EAFP in Java?

Hello, I was recently teaching myself Python and discovered the LBYL/EAFP idioms. In Python, it seems the accepted style is EAFP, and it seems to work well with the language. For those that don't know, LBYL and EAFP refer to Look Before You Leap and It's Easier to Ask Forgiveness Than Permission, both with regards to error checking befo...

Java Covariants

public class CovariantTest { public A getObj() { return new A(); } public static void main(String[] args) { CovariantTest c = new SubCovariantTest(); System.out.println(c.getObj().x); } } class SubCovariantTest extends CovariantTest { public B getObj() { return new B(); } } class...

How to create a java.awt.Image from image data ?

How to create a java.awt.Image from image data? Image data is not pure RGB pixel data but encoded in jpeg/png format. JavaME has a simple api Image.createImage(...) for doing this. public static Image createImage(byte[] imageData, int imageOffset, int imageLength) image...

Porting easily from 2D to 3D on a Java game

Due to lack of capital and time we are having to do our game in 2D even though me (the developer) would prefer if it was done in 3D. I would hate for users to join the game, only to think the graphics look bad and leave. Though I suppose we just have to try and do our best. That being said, I would like to develop the game in such a way...

Best way to get started on simple 3D user interfaces using Java?

I'm writing a time management application and I have an idea for presenting timelines and todo items in 3D. Visually, I imagine this as looking down a corridor or highway in 3D, with upcoming deadlines and tasks represented as signposts - more important items are larger and upcoming deadlines are nearer. I want to do this in Java, howev...

Should I unit test methods which are inherited from super class?

I'm currently writing an implementation of a JDBC driver (yes, you read that correctly) in a TDD manner and while I have only finished class stubs at this point and only some minor functionality, it just occured to me that since Statement is a superclass for PreparedStatement which is a superclass for CallableStatement, what should I do ...

Why is accessing a static method from a non-static method bad?

Netbeans tells me it's bad to access a static method from a non static method. Why is this bad? "Accessing static method getInstance" is the warning: import java.util.Calendar; public class Clock { // Instance fields private Calendar time; /** * Constructor. Starts the clock at the current operating system time *...

Whats up with static memory in java?

This question is for the java language in particular. I understand that there is a static protion of memory set aside for all static code. My question is how is this static memory filled? Is a static object put into static memory at import, or at first reference? Also, do the same garbage collection rules apply to static objects as they...

Can Java be faster C++ in any situation?

Is it possible for a Java application to be faster than a program written in C++? Also, what is release mode in compilation ? ...

Large amount of data - what is the best way to send them?

Hi, we have this scenario: A server which contains needed data and client component which these data wants. On the server are stored 2 types of data: - some information - just a couple of strings basically - binary data We have a problem with getting binary data. Both sides are written in Java 5 so we have couple of ways.... Web Se...

Quick Java Question: Instantiating a given class only from another?

My problem is thus: I need a way to ensure only one given class can instantiate another. I don't want to have to make the other a nested inner class or something dumb like that. How do I do this? I forget offhand. ...

In Java, why do people prepend fields with `this`?

When referencing class variables, why do people prepend it with this? I'm not talking about the case when this is used to disambiguate from method parameters, but rather when it seems unnecessary. Example: public class Person { private String name; public String toString() { return this.name; } } In toStr...

Integration testing an external library?

I am using an external library in a java project but I am not sure how can I integration test it with my code. For example: Let us say I am using a string encryption library to encrypt passwords. Please enlighten. Thanks ...

problem while reading length of the file java

Hi i'm begginner in java i'm reading characters from file(FileReader) but when i read length of the i'm not getting correct result, its displaying less size compare to correct one.plz reply wat is the problem. thanks for reply ...

Split packages in plain java

OSGi has a problem with split packages, i.e. same package but hosted in multiple bundles. Are there any edge cases that split packages might pose problems in plain java (without OSGi) ? Just curious. ...

Problems with Matlab javabuilder and memory

I'm experiencing some issues regarding my javabuilder-compiled matlab-code. My application is basically split up like this: GUI: Java Calculations: Matlab The main problem is that when compiling my matlab-code with the javabuilder in Matlab (R17, 2007a), I have less memory available than I have when I compile the same code to an exe-...

Pom Dependency

Which dependency should be added in pom file to import org.apache.tiles.controller? ...

Can Java Enumerations be merged (like Bitwise in C#)?

Is there a way in Java to declare an enumeration whose values can be used together? For example: enum FileAccess { Read, Write, ReadWrite } Is it possible to define ReadWrite as Read | Write (or anything that would yield the same result)? ...

How to display java applet inside GWT page?

Hi, I'm probably missing something simple here, but I can't find the answer elsewhere. I just want to display an applet in my GWT code. OS: Windows XP Java: JDK 1.6.0_10 Other: GWT, GWT-Ext 2.0.5 Here is the applet (obviously simplified for testing): package foo.applet; import javax.swing.JApplet; import java.awt.Graphics; public c...

Do you look "under the covers" of libraries that you're using when developing?

While reading this interview with Bjarne Stroustrup on education. He had this to say: I’m not sure how much of the problem is Java itself and how much is the emphasis on using libraries, though. The trouble is that Java has in many places been used to dumb down the curriculum while at the same time increasing the apparent level of de...