Tag Info

New answers tagged

-5

Personally I like services and functionality of dating website https://kovla.com/datings/us/ . Feel free to visit it and enjoy your time:)


1

Without computer code, every machine could only do the thing that it was explicitly constructed to do and never anything even slightly different. Your washing machine could run one sequence of rinsing, shampooing, tumbling, drying, etc., but nothing else. If you wanted a different temperature, or insert a step into the washing regime, you'd have to build a ...


-2

For me, learning by doing projects always worked out better than laboriously going through books from beginning to end. That said, here are a couple of books you might like: http://introcs.cs.princeton.edu/java/home/ - covers the basics of programming in Java, you might want to browse the site to see if you need it http://algs4.cs.princeton.edu/home/ (and ...


1

Visitor classes should strictly follow SRP (Single Responsibility Principle) so using visit as common naming convention would be the most appropriate. As far as entity classes are concerned, they will usually do more than allow visitor classes to visit them, so name accept can introduce naming conflict if entity class would have accept method that serves ...


1

There is no need for using subclasses here, Dog and Cat should not be derived from Database (in fact, this would result in a typical example of how to not to use inheritance). Instead, you could have the Create/Read/Update/Delete methods of the classes Dog or Cat just have a parameter of type DataBase (or IDataBase, an interface, if you want to be able to ...


0

I suggest you study Inversion of Control and the dependency injection pattern. Take a look at this Martin Fowler article on dependency injection. Using an IoC container will help you break up your class into more manageable components and make your solution less brittle than it is now.


2

The only thing I see inelegant about your implementation is intertwining the file listing work, the zip file opening/closing work, and the counting work. (Do you have another issue with it?) Solution 1: Use Java's try-with-resources block to automate the file closing work thanks to ZipFile being AutoCloseable: ... try (ZipFile zf = new ZipFile(file) { ...


1

If you define a constructor with a parameter, then there must be a valid reason in doing so. Maybe this parameter is so important to your class that without it the object state is invalid. That is why the Java does not make a no-argument constructor for you when you already define one. If you decide that it would be handy to have no-arg constructor, then ...


10

Lots of people have listed good things about Haskell. But in answer to your specific question "why does the type system make programs more correct?", I suspect the answer is "parametric polymorphism". Consider the following Haskell function: foobar :: x -> y -> y There is literally only one possible way to implement this function. Just by the type ...


1

Packages on the JVM have a very important job – to provide a globally unique namespace for all your classes. It doesn't matter whether you write your code with Scala or Java or Clojure; in the end all get compiled to .class files or JAR archives. Note that Scala is not the Anti-Java, instead interoperability with Java was a primary design goal. So the ...


2

Scala package best practices are generally the same as Java conventions, according to the Style Guide. // wrong! package coolness // right! package com.novell.coolness // right, for package object com.novell.coolness package com.novell /** * Provides classes related to coolness */ package object coolness { }


43

Here's an unordered list of type system features available in Haskell and either unavailable or less nice in Java (to my knowledge, which is admittedly weak w.r.t. Java) Safety. Haskell's types have pretty good "type safety" properties. This is pretty specific, but it essentially means that values at some type cannot wantonly transform into another type. ...


1

What you are trying to do cannot be achieved. In the first case the error is self-explanatory on the limits of the Generics Framework (primarily erasures). In the second case it is wrong - consider this analogy - if your method could return Person class - can you return Person? No, you would return new Person() i.e. an object representing the class or type ...


21

a :: Integer b :: Maybe Integer c :: IO Integer d :: Either String Integer In Haskell: an integer, an integer that might be null, an integer whose value came from the outside world, and an integer that might be a string instead, are all distinct types - and the compiler will enforce this. You cannot compile a Haskell program which fails to respect these ...


47

Full type inference. You can actually use complex types ubiquitously without feeling like, "Holy crap, all I ever do is write type signatures." Types are fully algebraic, which makes it very easy to express some complex ideas. Haskell has type classes, which are sort of like interfaces, except you don't have to put all the implementations for one type in ...


12

A related SO question. I assume you can do the same in haskell (i.e stuff things into strings/ints that should really be first class datatypes) No, you really can't - at least not in the same way that Java can. In Java, this sort of thing happens: String x = (String)someNonString; and Java will happily try and cast your non-String as a String. ...


1

Here's a barebones generic implementation for two alternatives: public abstract class Either<A, B> { private Either() { /* prevent outside subclassing */ } public static Either<A, B> ofA(A a) { return new OptionA<A, B>(a); } public static Either<A, B> ofB(B b) { return new OptionB<A, B>(b); ...


1

This depends entirely on how your encryption method works. There is a well-known way to serialize and deserialize a class instance in java to its byte form, however you shouldn't mistake this for encryption. Encryption would be an operation to be performed on the byte array itself to transform it into something difficult to reverse without a proper key of ...


2

The type of the exception that is thrown should not be specific to the human language domain. Throw some exception that's named in English, and look up an internationalized string for the exception description.


0

A bank account system is essentially not different from any other accounting system. Recommended read : Accounting Patterns (Martin Fowler)


0

Opening a connection performs a similar function to performing a ping. It will only succeed if you have connectivity. You will need to use an open port on each destination you wish to connect to. Port 80 may well be open. For faster response you will want to timeout failed connections fairly quickly.


0

The serialization API makes a specific promise: If you save the bytes created by a serialize() call, you can later feed them into a deserialize() call, and your object will be reconstructed. That is all it does. You are doing something different: you are feeding a different stream of data to the deserializer. That isn't in its job description, so ...


2

You're under a bit of misconception here. First, divorce the @Resource annotation from javax.ejb.TimerService. Now read the following excerpt from the JavaEE api: The Resource annotation marks a resource that is needed by the application. This annotation may be applied to an application component class, or to fields or methods of the component class. ...


0

You cannot meld three classes so that an instance of this chimeric class can be used as an instance of either of the three types (as in LSP). You can make an umbrella class that, unlike an empty interface, gives you real type-checking. class AppleBookCar() { final Apple apple; final Book book; final Car car; private AppleBookCar(Apple a, Book ...


0

Well, all objects extend from the Object class, so maybe you could try to create a generic class and pass in as parameters each of the types. But I am not sure how or why they would all be related because as you said, they have nothing to do with each other. Interesting.


2

Do you make a new empty interface and implement it in all the types? Yes. I think that means that there will be compile time type checking available, which is nice, but is there another solution with annotations or similar? Nothing that gives you compile time type checking. (Or at least not >>Java<< compile time type checking.) The ...


0

In general, you will encounter value types and reference types. With a value type, you don't care about the object that represents it, you care about the value. If I give you a value, you expect that value to stay the same. You don't want it to change suddenly. The number 5 is a value. You don't expect it to change to 6 suddenly. The string "Hello" is a ...


-1

Yes, remember, you will probably not the only one to edit a Class/Code.. Also, use a descriptive name, don't make it a Magic Number!


0

The idea behind test-driven development is that your tests are written in the form of scripts, running through the flow that a user or client package would take if they made use of the software you are about to write. Obviously at first your test classes will be full of errors which complain that the classes and methods don't exist (or they do exist but ...


1

This is the driving motivation behind Test-driven development, with the principles being thus: You do not write code without tests. You write just enough code for the test to pass. You refactor the code that you have written and ensure that tests pass. I think I understand what you're getting at - you don't know if you can/should write tests for objects ...


6

There is a test for whether a language is pass-by-reference: can you write a swap function, such that after swap(a,b), the caller finds that the values of a and b are reversed? You cannot do this in Java, not even for objects. Note that you cannot achieve this goal by swapping the internals of the two objects - while the data may change, the identity of ...


0

You're being confused by constructor chaining. Inheriting from an existing class means that when you construct an object of the subclass, the superclass constructor is called automatically. But that only works for constructors, not for inherited normal methods, and the constructor only runs when you apply new to the subclass. As it is, you're just ...


2

You may need to consider some re-factoring. So it looks like we have [Client] -message-> [Server] and Message (and all derivatives of) are stored in the [Common] package. In your comment you explain that the Message contains a function which gets called by either the Server or the Client depending on which received the message, which in turn calls a ...


2

Constants are things given values that are known before or during compilation. What you've declared is a variable because its value is determined at runtime by invoking a method. The fact that it's final is really just a convenience for letting the compiler know that once the value is set, it won't be changed.


11

The code and naming conventions for Java are fairly well established. In particular, this one (or its mismatch) can be seen in Section 9 - Naming Conventions The names of variables declared class constants and of ANSI constants should be all uppercase with words separated by underscores ("_"). (ANSI constants should be avoided, for ease of debugging.) ...


0

We did this at my current company, and we're very happy with the results. Our expressions are written in js, and we even use them to restrict the results the users can get from querying ElasticSearch. The trick is making sure that enough info is available to make the decision, so that you can really write whatever perms you want without code changes, but ...


4

What you have written is really a lexer. Parsers give you the nested structure from your input, whereas lexers just give a sequence of symbols. You've probably spent a lot of time reinventing the wheel, when you could use a parser generator like antlr to do most of the work. For example, it only took me around 5 minutes to come up with the following basic ...


0

You should return a 4xx error with a detailed description of the reason the request failed in the response body. Can't help with the Java implementation. In many Python frameworks you would throw a 4xx exception as soon as your code has determined that the HTTP request is going to fail and this is caught by the framework and returns a 4xx HTTP status ...


1

Yes, it is quite possible, and I have done such myself. The situation I was in was deployment of a large .war file. The web application part of it was not that big - but it also contained within it a Java Web Start application. The combined size of all of this was a few hundred megabytes. This posed a problem for deployment - when pushing all of this down ...


0

If the apps are distinct in terms of data, and purpose, I think modularizing them - making a number of smaller, separate pieces is better. If they do not share data, and if they do not have strong coupling in terms of how the user uses them, I would strive to keep them separate and small. It all depends on the coupling between the fairly unique apps. If ...


2

Yes. It is possible to patch a JAR file using jar -u. It is also possible to patch a WAR file the same way. But I would NOT recommend it. The JAR or WAR file should be the unit of deployment / management. If you start patching JAR / WAR files on production servers, it is hard to track what is actually being used where. If you are not careful, chaos and ...


1

The type of unit testing you need to do to find bugs in existing mostly-working code is very different from the type used as a scaffold while creating or modifying the code. Only the latter is TDD/BDD. And, as it is somewhat newer, it tends to be the one that gets discussed in articles and blogs. Sometimes to the point where people get the impression that ...


1

It may take you longer to write code complete with unit tests. In fact it probably will. What makes it a more productive way of working for the organisation as a whole is all the things that don't happen further down the line, and in particular don't happen to other people, when you have your code armed with a full battery of tests. Fewer manual testers ...


11

One thing to remember about testing is that you're going to do it either way. Whether you're printing application variables to the screen, using a debugger to inspect your application's state or just visually verifying the final output of the application's input, at the end of the day, you'll have spent quite a bit of time commenting out code, perhaps ...


13

If you first test things manually through a user interface, until you do not find any bugs any more, and write unit tests afterwards, it is not very surprising that those unit tests do not reveal many bugs. You are probably just automating things you already have done manually, but do not code many test cases which were not already part of the manual tests. ...


7

Why are my unit tests so expensive? For the same reason divorce is so expensive: It is worth it. In my experience (bizdev, C#/Java over more than a decade now), writing unit tests for code takes about half the time as writing the code itself - so 33% of your total coding time. Some things will be more. Some things will be less. When you're just ...


1

The key is to test the intention of your code. This way even if you refactor the way your intention is being implemented you will still be able to have valid unit test because it is still the same intention. As you have mentioned yourself, if you have limited resources, then do what is most important and that would be business logic. Also don't forget ...


3

A typical "MVC for the web" program might look something like this: RDBMS <--> ORM <--> DAL/SL <--> Controller <--> ViewModel <--> View RDBMS - Your database, usually something like SQL Server, Oracle or Postgresql. ORM - An Object-Relational Mapper, like Hibernate. The ORM converts tables to class objects, and vice versa. ...


1

First, there is really no need to worry about the space used by local variables. In one line I can allocate an array of 100,000 integers which will take more space than all the local variables that you are ever going to use. Second, your code is compiled by a compiler which is likely to be clever. If your variable isn't initialized, it isn't used (because ...


4

What is the difference between a variable assigned to null and others not assigned in memory? There is no such thing as an unassigned variable in Java. Class data members that don't have an explicit assignment are assigned the default value for the type, null for an object, or something akin to 0 for primitive types. Local variables live on the stack. ...



Top 50 recent answers are included