All Questions
Tagged with java programming-languages
78
questions
12
votes
5answers
2k views
How can I simulate a “negative” type system?
In my experience, all languages I know have a sort of "positive" type system. What I mean by "positive type system" is that when you are writing the source code, you always specify ...
0
votes
1answer
229 views
Have the inventors of Java ever publicly expressed regret about hashCode and equals in class Object? [closed]
I was talking to a colleague recently about hashCode and equals being methods in class Object in Java (among other languages). I am from a more theoretical background while my colleague is more of a ...
53
votes
11answers
12k views
Why does C++ have 'undefined behaviour' (UB) and other languages like C# or Java don't?
This Stack Overflow post lists a fairly comprehensive list of situations where the C/C++ language specification declares as to be 'undefined behaviour'. However, I want to understand why other modern ...
1
vote
1answer
130 views
Why doesn't Comparable<T> include any type bound? [closed]
Why do you think the definition of Comparable<T> lacks an upper bound on T?
That is, why is it not defined as:
Comparable<T extends Comparable<?>>
or
Comparable<T extends ...
2
votes
1answer
1k views
Why did Java and C sharply dip in popularity around 2017 in the TIOBE index? [closed]
The TIOBE Programming Community Index shows Java and C dramatically falling in popularity between late 2016 and mid 2017 before rebounding by mid 2018. What is the cause of the volatility?
Source: ...
2
votes
3answers
8k views
Why doesn't Java automatically initialize local variables with its default value like it does with arrays, class variables, etc.?
public class A {
public static void main(String[] args) {
boolean[] test = new boolean[1];
System.out.println(test[0]);
}
}
prints false, as specified by the Java spec.
...
2
votes
4answers
5k views
If C++ is generally faster than java, why most data analysis / ETL tools are developed in java? [closed]
I've read in a lot of forums, a lot of users agree C++ is faster than Java (even if it leads for a microsecond, it is important), so why are the majority of data mining software or software tools ...
295
votes
16answers
28k views
Grokking Java culture - why are things so heavy? What does it optimize for? [closed]
I used to code in Python a lot. Now, for work reasons, I code in Java. The projects I do are rather small, and possibly Python would work better, but there are valid non-engineering reasons to use ...
50
votes
9answers
23k views
Why does Java have `void` methods?
Does / why does Java need to have void methods? Reference:
Any method declared void doesn't return a value.
As far as I can think, every use of void would be better served by returning a status ...
1
vote
2answers
229 views
How come language designers don't upgrade their global functions?
For example, when working with arrays there are methods like indexOf() that works like this:
if (array.indexOf("something")!=-1) { // do something or nothing }
Why hasn't someone made a contains ...
69
votes
10answers
18k views
Why do languages require parenthesis around expressions when used with “if” and “while”?
Languages like C, Java, and C++ all require parenthesis around an entire expression when used in an if, while, or switch.
if (true) {
// Do something
}
as opposed to
if true {
// Do ...
4
votes
1answer
116 views
The bound mechanism by generics for a type variable to appear in its own bound
From Programming Languages: Principles and Paradigms
By Maurizio Gabbrielli, Simone Martini
The bound mechanism for type variables is fairly sophisticated and
flexible. In particular, a type ...
-1
votes
1answer
174 views
Rotate a matrix in place, moving elements? (How to write a part of flow/logic after understanding the problem?)
Following is a java solution of the classic question of rotating a nxn matrix in place clockwise by 90 degrees.
public void rotate(int[][] matrix, int n) {
for (int layer = 0; layer < n / 2; ++...
3
votes
2answers
988 views
Is a linked list considered a collection of objects?
Sedgewick's Algorithm 4ed says
Several fundamental data types involve collections of objects.
Specifically, the set of values is a collection of objects, and
the operations revolve around ...
4
votes
2answers
692 views
Java Design Philosophy
I was reading through design philosophy of java and this line struck me:
"The VM checks whether the signature of the Java code is valid and would refuse to interpret if any change of the code is ...
-2
votes
1answer
253 views
What is an efficient way to implement 'Stack' without generics?
Today I was reading a lot of articles complaining about Java Generics or C++ Templates. Now, my question is: How can someone implement a collection data structure like Stack without using them?
0
votes
1answer
787 views
What algorithm or program does Java use for arithmetic?
I was looking at bitwise ways to multiply and add numbers without using * or + operators. But I want to know that it might be possible that java may already be using a better approach underneath. I ...
8
votes
5answers
1k views
Composable concurrency in Java or any other programming language
While I was reading a research paper on concurrency named Software and the Concurrency Revolution (html version). I came across following lines:
Unfortunately, although locks work, they pose ...
2
votes
3answers
486 views
Why do most language's definition of substring allow substring(“abc”, 3) => “”
I've seen most languages have it be the case for their substring method that using the length of a given string in the method as the start index will give you an empty string. It is most definitely ...
0
votes
2answers
472 views
Why doesn't Java implement a better way of handling getters and setters? [closed]
Getters and setters are everywhere in Java, but they are managed in a horribly outdated way.
Simply put: Why doesn't a newer version of Java enable a simpler syntax for managing it? Even if this ...
36
votes
9answers
15k views
Why do schools teach arrays over List? [closed]
Most of the assignments in my school for the initial programming classes required me to use arrays. I work full time now, and I never used an array for any project that I have worked on. Even in the ...
-2
votes
1answer
136 views
What is the purpose of Deprecation? [closed]
Is it just giving different names to previously named method? Does it change with the language you use? Is it essential? I have noticed different APIs having deprecated methods, which actually seem ...
1
vote
2answers
199 views
If there's no problem treating a statement as an expression, why was there a distinction in the first place in some programming languages? [duplicate]
Why do we have the distinction between statements and expressions in most programming languages?
For example, in Java, assuming f and g return ints, this still won't compile because it's a statement ...
-3
votes
1answer
448 views
Why is the JavaScript-language different in different programs/sites? [closed]
I'm kind of new to programming and i have a question that's been bothering me for awhile.
Why is the JavaScript-language different in different programs/sites.
I've used Codecademy to practice and i'...
0
votes
3answers
3k views
How to get an image or rectangle to detect collision with another image
Can someone please explain to me how to detect collision with another image? The tutorial I was watching explained how to detect if a collision occurs between two rectangles but I would like to use ...
109
votes
5answers
92k views
Why were default and static methods added to interfaces in Java 8 when we already had abstract classes?
In Java 8, interfaces can contain implemented methods, static methods, and the so-called "default" methods (which the implementing classes do not need to override).
In my (probably naive) view, there ...
1
vote
1answer
1k views
Creating a very basic compiler using Java
I want to try and create my own very basic language, with it's very basic compiler. All using Java.
For now, it will only need to enable to 'programmer' to print things to the screen.
I had an idea ...
1
vote
1answer
307 views
Pythonic version of Java interfaces
I fully acknowledge that Python and Java are different programming languages and should be used differently. That said, "Program to an interface, not to an implementation" is good language-agnostic ...
0
votes
3answers
186 views
High-Level SQL Interoperability
In a server -> client scenario, wouldn't it be simpler and faster to grant a public user access to a Stored Procedure rather than using web services (XML, REST, SOAP, etc) and other interoperable ...
6
votes
4answers
1k views
What's the reason exceptions are heavily used in managed (C# and Java) languages but not in C++? [closed]
AFAIK, a lot of C++ projects don't allow exceptions and deny them in coding guidelines. I have a lot of reasons, for example, exception is hard to handle correctly if your binary needs to be compiled ...
-1
votes
2answers
16k views
how to write good programming logic? [duplicate]
recently I got job as a java developer,
and now I have assigned project too.
I want to know what is a good logic?
when I check in the code my team lead is saying that
its a good code.
But when it ...
4
votes
1answer
31k views
Why would one prefer C# (ASP.NET MVC) or Java (JSP) instead of PHP for web applications/projects [closed]
I'm wondering, why would one (consider it not just a single developer, but a company) prefer C# or Java for web applications? What's their considerations regarding the question. I mean, a company, has ...
6
votes
3answers
543 views
From an execution perspective is an interpreter the same as the JVM / or the .net Framework
I've recently started two introductory level courses - one using Python, the other Java.
I've read the answers to this Question but still have difficulty understanding how each ends up with machine ...
1
vote
2answers
2k views
Access JSON object in different Languages
I have a Java code which is writing some data in string format to Messaging queue. Now any one can subscribe to this queue and fetch this data. Here the client fetching this data can be written in any ...
0
votes
1answer
3k views
Is Java still king of cross-platform compatibility? Is the answer still Swing? [closed]
So basically, my company is looking to create an app that can be distributed on Linux, Mac OS X, and Windows. We are hoping for a cross platform solution. I have experience working with Java Swing ...
6
votes
2answers
3k views
Java naming conventions vs. C++/C naming conventions
I am a Java developer who is starting to pick up more and more C++/C (yes I know they're different, bear with me). One thing that struck me as odd was the different naming conventions used by these ...
18
votes
5answers
3k views
What makes JVM so much versatile to support so many JVM languages?
JVM supports so many languages other than Java like Groovy,Clojure,Scala etc which are functional languages unlike Java(I am referring to Java before Version 8 where Lambda's are not supported) that ...
33
votes
5answers
5k views
Why do C# and Java use reference equality as the default for '=='?
I've been pondering for a while why Java and C# (and I'm sure other languages) default to reference equality for ==.
In the programming I do (which certainly is only a small subset of programming ...
3
votes
3answers
297 views
MVC seems to create dependencies that just “don't feel right”
I might be misunderstanding MVC, so forgive me if that is the case.
This is my program structure (Java/Swing): I have a JTable (View) that is pointed to by a custom linked list (Model). When the user ...
81
votes
11answers
33k views
Why is String immutable in Java?
I couldn't understand the reason of it. I always use String class like other developers, but when I modify the value of it, new instance of String created.
What might be the reason of immutability ...
40
votes
5answers
22k views
Is a lambda expression something more than an anonymous inner class with a single method?
There is a new hype with the long awaited lambda expressions in Java 8; every 3 day another article appears with them about how cool they are.
As far as I have understood a lambda expression is ...
50
votes
9answers
17k views
Why didn't == operator string value comparison make it to Java?
Every competent Java programmer knows that you need to use String.equals() to compare a string, rather than == because == checks for reference equality.
When I'm dealing with strings, most of the ...
7
votes
2answers
58k views
What is the maximum value of index of an ArrayList?
I was thinking about it. You may have access to endless memory (one computer with lot of RAM) so that you can keep on adding more and more elements to your ArrayList.
But, I think that you can only ...
41
votes
9answers
6k views
Is memory management in programming becoming an irrelevant concern?
Background
I revisited an old (but great) site I had not been to for ages - the Alioth Language Shootout (http://benchmarksgame.alioth.debian.org/).
I started out programming in C/C++ several years ...
45
votes
5answers
17k views
Why does Java not do type inference?
I have always wondered why Java does not do type inference given that the language is what it is, and its VM is very mature. Google's Go is an example of a language with excellent type inference and ...
5
votes
2answers
886 views
Asking people to disable Java for security - what's next for developer?
I don't know what best to give as title to this so pardon me if it sounds weird.
I saw this question asked on IT Security and another site asking people to disable Java from their system or browser ...
9
votes
8answers
816 views
Past If statements Arrays, loops… Now what?
I gave up on programming a little over a year ago when I kept hitting this wall. I am revisiting the subject because I want to create basic Android application. But I feel that my limited knowledge ...
8
votes
2answers
16k views
How to execute a Ruby file in Java, capable of calling functions from the Java program and receiving primitive-type results?
I do not fully understand what am I asking (lol!), well, in the sense of if it is even possible, that is. If it isn't, sorry.
Suppose I have a Java program. It has a Main and a JavaCalculator class. ...
13
votes
2answers
2k views
Advantages and disadvantages of structuring all code via classes and compiling to classes (like Java)
Edit: my language allows for multiple inheritance, unlike Java.
I've started designing and developing my own programming language for educational, recreational, and potentially useful purposes.
At ...
1
vote
1answer
728 views
How can you become a real programming polyglot? [closed]
I work as a Java programmer, but C and C++ were always my favourite languages during studies. Unfortunatelly I don't have an opportunity to work with them as often as I would like to. As a result I ...