Tag Info

New answers tagged

0

Relative Paths You could define some environment variables in windows. For linux users, this should feel familiar. C:\> SET VARIABLE_NAME="path\to\dir" sets the environment variable VARIABLE_NAME to that path. Windows will then replace %VARIABLE_NAME% with whatever you put in the quotes, whether it's valid or not. (If it's not, it'll throw an error.) ...


0

I would use a multi-threaded approach, but without an unbounded number of threads: i.e., not one thread per device. First, I would construct a queue that contains one object for each device that needs to be polled. Java provides a synchronized queue which is thread-safe. This object represents one device and contains data such as the last time it was ...


-1

Short answer: design always for multi-thread as it will scale. I also designed and develop a similar tool, from my experience I advice you to get acquaintance with the following design patters: Singleton Multiton Factory you'll see that depending which module you use, you'll need to tackle with one of those patterns. It can be that you need other ...


1

To be a normal developer (by normal I mean someone who just takes requirement from senior developer/architect, and do according to instruction), you will not need deep knowledge in algorithm. However to advance further in technical side, I believe (my opinion only) that understanding of various algorithms, data structures is necessary. You may not need to ...


0

I've found that for the most part, in an everyday business setting, the programming you do isn't really complicated. Usually no where near the difficulty of problems found in text books or competitions. Most of the complicated algorithms you need are provided for you in libraries. That being said, it is also true that most generic business problems are ...


2

Yes, many developers, especially in challenging fields such as video games or avionics, have to solve challenging logical and computing problems all day long. If this does not suit your taste or if you tend to have lesser logical capacities than people of your age with equivalent experience, then programming may not be for you. You could still run a modest ...


3

If I were to be a programmer, would I have to be able to solve extremely difficult algorithms, or not? Maybe, maybe not. There are many professional programmers who do nothing noteworthy, yet are still employed (and horrible). I understand Computer Scientists would have to, but a back-end game developer, or application developer for large aviation ...


4

With internal libraries, you don't need to distribute them at all. The end user will have their own copy in their JRE. You only distribute code you own so you doesn't have any constraints. If you distribute code using GPL libraries, your code would need to be compatible with the GPL license which includes making all the code of the combined work available. ...


1

Sockets, RMI, Protocol Buffers, Thrift, CORBA, DCOM, ... the number of RPC systems is long and extensive. They all have a similar goal though: provide a system to allow a client process and another server process talk to each other. Today the possible best practice is to use a standard communication system, one where you can change the client to a different ...


0

Visual Basic does not get as much respect as C#, despite being almost identical in terms of functionality. For that reason alone, I would recommend C# over Visual Basic, even if the Visual Basic code editor is a little more advanced in Visual Studio. C# also seems to be more widely used, at least in my experience, but some usage statistics must be easy to ...


-1

Why don't you just use Timer.scheduleAtFixedRate(TimerTask task, Date firstTime, long period) If you set firstTime to currenttime rounded up to next minute, the timer will run at 12:00 if you set period to 60000


1

So if you're having problems getting it to run at an exact time, give it an interval to run, say from 12:00:00 -> 12:05:00 and once it runs inside that period, set a flag. Then, in another period, say, from 12:05:00 -> 12:10:00 check for that flag and clear it so that you can run it again in 24 hours. you can change these periods or move them to make them ...


2

1. Is the problem identified above valid or do I lack understanding of the builder pattern? Should we not reuse builder objects to created multiple instances? It can be, depending on your situation. Here you've identified that you have mandatory fields that are unique, therefore making them parameters to your build method allows you to reuse the same ...


0

The Command pattern is usually used in these situations. You can easily create an implementation for each SQL command. I would suggest to look into CLI frameworks like Spring Shell or Commons CLI.


0

How do you test your code should not influence any design decision. It's better to ask yourself the question - would I ever provide at least two different implementations for the service? If the answer is yes, then define an interface for it. Usually you provide an interface, when you want to easily interchange two or more implementations (like PnP).


6

You are asking about Java, but in your question you also mention C#, so I will answer with a significant project in that language: Project Roslyn, Microsoft's from-scratch rewrite of the C# and VB.NET compilers in C# and VB.NET uses immutable datastructures throughout. In particular, all the parse trees and semantic trees are immutable, and every operation ...


10

You're asking for examples from the wrong programming language. Java is one of the unfriendliest languages for immutability, both from a development culture and from a language feature perspective. To work with immutable objects on a large scale without going insane, you need functional-style language features, which Java didn't even start to consider ...


0

Without limiting the scope to Java, I'd say Cocoa is one of the big projects out there. It's used by iOS and OS X applications and I bet many of the programmers would stumble on how NSString (the basic string class) is immutable and learn to use NSMutableString. Same with data structures (NSArray, NSDictionary, etc.) I'd also say many are using them ...


3

Will be there a difference? Yes. How much difference there is will be highly dependent on your application. In the unrealistic case where the application consists of N thread that do independent (i.e. no share data structures) CPU intensive computations with small memory working sets, no garbage generation and no I/O, then you can expect close to ...


1

Assuming that your four threads are capable of utilizing the core at 100%, your load is approximately equal on all threads, and there is no threading overhead, the application will run twice as fast on the dual core as the single core, and four times as fast on the quad core. It never works out exactly that way, of course. How close your application comes ...


3

AOP is good approach to solve your problem. But I advice you to examine your class. Twenty small methods quite different between each other in a class is a little code smell. I think your class probably violate single responsibility principle. http://en.wikipedia.org/wiki/Single_responsibility_principle


1

Why not have a separate CoverSheet object? Then you can cleanly do CoverSheetInfo coverInfo = null; if(theDocument.hasCoverSheet()) { CoverSheet cover = theDocument.getCoverSheet(); coverInfo = cover.getInfo(); } Sorry, I'm not familiar with PDFBox, so I don't know if this introduces more complexity than it solves, but (IMHO) it's a much cleaner ...


1

As far as I understood, the cover page is an important property of a document in your application. Then I'd represent it with a getter. The business classes dealing with renaming the document then only need the Document object and have no dependency to a parser which they do not care about. How that getter is implemented is a different question. You could ...


7

The text you quoted has good advice, although I will replace “data structures” by “records”, assuming that something like structs is meant. Records are just dumb aggregations of data. While they might be mutable (and thus stateful in a functional-programming mindset), they don't have any internal state, no invariants that have to be protected. It is ...


3

The fact that handleTrade() and updateRun() always happen together (and the second method is actually on the visitor and calls several other methods on the data object) smells of temporal coupling. This means that you must call methods in a specific order, and I would guess that calling methods out of order will break something at worst, or fail to provide a ...


0

From my point of view a class should contain "values for state (member variables) and implementations of behavior (member functions, methods)". The "unfortunate hybrid data structures" emerges if you make class state member-variables (or their getters/setters) public that should not be public. So I see not need to have seperate classes for data data ...


0

If you want to start experimenting with client/server communication with Android and a web service you don't need to develop a fully blown RESTful API to do it (though there are very good reasons why you might want to use a RESTful API eventually when you've had enough experience to think about how to design it well). The first recommendation is to use ...


0

~10,000 textured quads is on the order of ~1MB. While max buffer size varies by GPU, 1MB should be no problem. On the other hand, while repeatedly uploading geometry data to the GPU generally isn't advisable, you could easily get away with it in this case, with only ~200 quads visible at a time. So I expect either approach would be fine, unless you're ...


0

I would say data structures exist at least one level of abstraction below the programming language level, if not everywhere. That's because compilers and interpreters create data structures out of whatever source code you give them. If you're more interested in whether one of these hidden intermediate steps (compiler, interpreter, etc.) use data structures ...


3

Linked lists and arrays are very simple, but they are also real data structures. They're the simplest way to deal with a list of items, with linked lists simpler for lists whose size we don't know ahead of time, and arrays simpler for lists whose size (or maximum size) we do know. You don't have to dip down into a different, lower-level language (like ...


2

The answer is both. Data Structures are implemented at all levels of abstraction as far as languages go. For a reasonably high level language like Java where memory allocation is automatically managed, you'd define the data structure in terms of Java classes and methods. In C, you'd define structures (or arrays) and the functions that operate on them. ...


-2

Java should be fine for a game. But a good book for Android games is "Beginning Android Games" by Mario Zechner and Robert Green. The book has a great data structure for OpenGL 2.0, they even show development of 3 different games. One is 2D without OpenGL, the second one is 2D with OpenGL, and the third is a 3D game. Check it out, I found it very worth the ...


2

Referential integrity and other constraints should be managed by the database and not the application that uses it. In the case of default constraints, I would have the UI pass in NULL for those fields or simply do not specify them at all in the INSERT query. The database will then supply the default value. The benefit to this is that SQL is designed for ...


0

Doing both should be considered an option. There are instances where the logic is too complex and relies on data from so many other tables, that the database code is just a bad place to handle it. If the goal is to consistently put them in the same place(s), you may not want to violate this, so keep it all on the form. On the form, you can prepopulate ...


0

Preferably, you should construct your workflow so that new records are initialized in the GUI only and not from the database. That will ensure that front-end and back-end don't need to agree about the default values, because the DB defaults never become visible to the user. If you must process adding just like editing, i.e. the front-end is loaded with ...


1

For maximum efficiency, use your set of keywords to create a Pattern, e.g. Pattern p = Pattern.compile("circle|ellipse|parabola|hyperbola|conic\s*section"); Matcher m = p.matcher(text) while (m.find()) { ... } This is about as fast as you can go in Java.


3

This is not only bad practice, this is unnecessary complicated. Why do you use inheritance in general? When you use inheritance, you have a common set of behaviour, which you want to make available for many different carriers. This includes class inheritance as well als interface inheritance. The heir, so to speak, is oftentimes a specialization of the ...


1

Use lookup of capabilities instead. Give no access to the child classes, consider them implementations of the Parent class. Then define interfaces specifying some capability, feature. interface Child1Specific { void child1SpecificMethod(); } Usage: Parent parent = ... Child1Specific specific = parent.lookup(Child1Specific.class); if (specific1 != ...


2

Your feeling is right to consider it a bad practise. Imagine your example code a little different: Parent p = createObject(); ((Child1) p).child1SpecificMethod(); How do you know, that the value of p is really Child1? You don't and this can cause a ClassCastException at runtime. If you need to call child1SpecificMethod() in your code you have to make sure ...


7

A declaration (whether a return type, an API comment or a contract) is a promise that you will deliver some good or perform some service. Declaring a specific return type is a greater promise than declaring a general type that is good enough for the caller, because it ties you down do a more specific action. If that is really what you are doing and always ...


4

Implementation of the generics is night and day: In java the compiled code removes all references to the generic type and adds casts where necessary. This is called type erasure and lets you do List<String> list; ((List)list).add(new Object()); which will only throw an error when you try to get the value as a string. All java generics actually are is ...


2

Taken from http://stackoverflow.com/questions/14028198/jpa-why-the-annotations-are-applied-on-getter-or-field, if you apply the annotation to the field, the jpa provider directly sets the field. If you annotate the getter, the JPA provider uses the accessor methods. See Chapter 2.3.1 of the specification here. I prefer field access for a couple of reasons: ...


0

The statement File f = null; is valid and useful (I don't think I need to explain why). It is likewise useful to have a collection of files, some of which may be null. List<File> files = new ArrayList<File>(); // use my collection of files // .... // not using this one anymore: files.set(3, null); The usefulness of collections that may ...


0

If I understand you correctly, you have two kinds of state-objects: The @Entity which is used in the persistence-context (Hibernate) The "viewmodel", which deals with user input and as you describe: »which uses MyOjectService« So your dataflow is from the user to the viewmodel and from the viewmodel to the Entity - we could neglect the persitence for ...


0

I won't write a java program without catching Throwable at the top level of every process. The caught error is (by definition) unexpected, and is a bug that needs to be logged and fixed. The errors you catch this way will surprise you, and you will never learn of them unless you make every possible attempt to get the word back from the real world to your ...


1

In general, you should NEVER catch things like Exception, Throwable, or Error, but only those specific subclasses of those that your application can reasonably be expected to handle and survive (or at least log something useful about before crashing). Exception handling is supposed to be just that, handling error conditions and dealing with them in such a ...


3

You have two sets as and bs. You want to calculate the set cs such that it contains all the elements from set A which have an ID which is the same as that of any object in set cs. You are currently using this nested loop: Set<A> as = ...; Set<B> bs = ...; Set<A> cs = new HashSet<>(); for (A a : as) { for (B b : bs) { if ...


0

I would suggest you to take a look at Spring Boot. It can save you a lot of configuration. They have a lot of archtypes with different technology stack combinations out of the box. Such app lightweight can be deployed anywhere. You can still switch from embedded Tomcat/Jetty to hosted alternative at later stage. It is new opinionated way to build Spring ...


2

In my humble opinion, the best approach here is to have an internal and external configuration. The internal configuration contains all your defaults and will be contained in your resource folder. The external configuration is a properties file deployed with your program that gets read afterwards and overrides any defaults. For testing, it is nice since ...


3

When you encounter an Error, it typically means your program is now in an undefined state: a .class file is corrupted, or memory is completely full, or you've run into an internal bug in the JVM, or something of similar severity. Ask yourself: even if you catch the Error to prevent an immediate crash, is it meaningful to continue running under these ...



Top 50 recent answers are included