java

How to test file system manipulation in Java

I'm writing a program that creates and edits directories and files in a file system. I want to write a test that does things like (1) check if the given directory exists and (2) create a directory within the existing directory. What is the best way to test functionality like this? Is there a way to fake a file system (e.g. in m...

Java Program Structure Advice

Hi, I am building and sort of RSS reader in java as my first object-oriented program and would love some OO design tips. I have a Reader class with a list of Feed objects for RSS feeds, and each Feed downloads news items into Article objects in an Articles list. What I want to do is find a way to relate articles from multiple sources....

Advise in AspectJ to change control flow

I'm just starting to learn AspectJ, and I have use-case for say, User login. If a user's session data (cookies) doesn't match the stored data on the server, I want to change the function called. Say I have two operations: class HttpServlet { public function() { } public function2() { } public doLogin() { } } ...

How to instantiate (inside a method) different classes that implement the same interface?

Hi all Just wondering if you're able to help me with my problem. This has probably come about by my not knowing the right keywords to search for. This is not homework, just anonymised... I have an interface and a bunch of implementing classes: interface Fruit Banana implements Fruit Apple implements Fruit .... I have a Fruit ...

Hierarchical object model with property inheritance and event bubbling?

I'm writing a document-based client application and I need a DOM or WPF-like, but non-visual model that: Is a tree composed of elements Can accept an unlimited number of custom properties that get/set any CLR type, including collections. Can inherit their values from their parent Can inherit their default values from an ancestor Ca...

JSP syntactical error in scripting

I don't understand why the first program in JSP is working, but the second program is giving an error: <% for(int i=0;i<10;i++){ out.print("hello"); } %> <% for(int i=0;i<10;i++){ <%= "hello" %> } %> ...

Java (6) Hash & Array alternatives that behave more like their Ruby counterparts

Having been spoiled by ruby for so long, I now find myself having to do some Java development (Eclipse RCP). I'm wondering if anyone knows of alternatives to HashMap & ArrayList that have some of the sugar of ruby. The verbosity of dealing with an ArrayList of HashMaps drives me bonkers. I'm also interested in finding other Ruby langua...

About Constructors in Java

Are constructors allowed to throw exceptions? ...

When do @SessionAttributes in SpringMVC get removed? (With code sample)

Under what exact circumstances do @SessionAttributes get cleared? I've discovered some confusing behaviour when trying to use two models in a page. When I do a GET followed by a POST using this controller... @Controller @RequestMapping("/myPage*") @SessionAttributes(value = {"object1", "object2"}) public class MyController { @Reque...

Getting Java JDK to compile on ubuntu

I'm trying to start working with Java, but so far haven't been able to get it on my machine properly. I'd really like to be able to compile from command line. After following the instructions here with no errors I can't compile with javac. Here's what I have so far: When I enter: $ java -version I get: java version "1.6.0_16" Java...

Completely Shut Down Java Application

In my standalone GUI application, I will install a Windows Closed handle on the application formWindowClosed within the closed handle, I will perform necessary clean up, and did a final System.exit(0) at the every last code. This works well, until I receive a complain from customer that the program is not able to shut down properly. M...

Should we need to differentiate between Interface class and abstract class, in terms of naming convention?

Hi, Is that important to differentiate between Abstract class and interface class? Abstract class is merely an interface class, with some concrete methods. If the abstract class shares the same prefix "I" with Interface class, we can easily upgrade our interface class to abstract class, by introducing new logic etc. UPDATE The reaso...

Running a Jar file alone

Hai I have an application which is designed in netbeans6.0.1 where i need to display an image as an logo.My coding is as below mLogo = new JLabel(); URL lUrlLogo = getclass().getResource("/com/images/image.gif"); Image lLogoimage = Toolkit.getDefaultToolkit().getImage(lUrlLogo); ImageIcon licon = new ImageIcon(lLogoimage); mLogo.setIco...

How to handle PermGen space exception in Tomcat?

I am getting a PermGen Space Exception whenever I deploy my web application. I tried some JVm option in NetBeans but still unable to resolve the issue. ...

Call Scala code from Java?

I'm using Netbeans to write Scala and Java. Netbeans generated a .jar file for the Scala project. I tried importing that file in the Java project. But I couldn't import any class from that .jar file into my Java project. I also tried importing scala-library.jar to the java project, and could import classes from that jar. I want to wri...

Debugging java obfuscated code

We are going to obfuscate our project but don't want to lose the ability of remote debugging and hotswapping. Is it possible? Which tools can handle this? I'd be happy with simple obfuscation - just renaming classes/methods/variables. [Edited] We're using Intellij IDEA but wasn't able to find any plugin for this task. ...

find pom dependencies by classname

How can I found the dependency by classname? In particular, I want to include this class org.mortbay.jetty.testing.ServletTester in my project, how do I do that? And how did you find the answer? ...

Java gridlayout with empty cells

I want to show the status of some files in a Java GUI. Each file has a label and a button, the colour of the button represents the status of the file and clicking performs various operations. All this is working, the problem is that they are not showing correctly. I want it to appear as [Label 1] [File 1] [File 2] [Label 2] [Label 3] [F...

How to do this using java expression language

Let just say i have the following java object that I wish to read in my jsp using el: class A { Map map = new HashMap(); int count; String getAttribute(String attrName) { return map.get(attrName); } String getCount() { return count; } } I can call count ...

Meaning of new Class(...){{...}} initialization idiom

What does {{...}} block mean in the following code? class X { private Y var1; private X() { Z context = new Z(new SystemThreadPool()) {{ var1 = new Y(); }}; } } ...