Why I Love Java

I would dwelve into python lands if there were more job offers, but people around here focus too much on java. I’m kinda fascinated by machine learning.

I’m something of a gnu/linux man myself (I think this was a meme back then, but not with linux), but I’m pretty sure it’ll be fairly difficult to stay away from winblows when I get to have a programming job.

My problem is with not having a compiler reading the syntax and telling me “oy a$#wit this is illegal” beforehand

1 Like

Grab the jetbrains software package for private people, cost very little, ~$25/month, and you’re covered with a series of well developed IDEs for close to all languages. Pycharm works very well for debugging, can step, set breakpoints and it also has built in intellisense for just about everything.

1 Like
import java.util.Random;
class Main {
  public static void main(String[] args) {
   	Random random = new Random();
		String frase = "a";
		for (int cont = 0; cont < 64 ; cont++)
		{
			char b = 'a';
			if (cont == 0)
			{
			b = (char) (random.nextInt(26) + 'a');
			frase = String.valueOf(b);
			}
			else
			{
			b = (char) (random.nextInt(26) + 'a');
			frase += String.valueOf(b);	
			}
		}
		System.out.print(frase);
		
  }
}

So here we have the first string… when I get some time I’ll try to sort them…

2 Likes

Here’s creating, sorting and dumping to file using python 3.5.3 on Debian 9. There is also a faster sorting function in numpy, don’t have that installed on home pc, so just used standard one. File is around ~65MB, took 42.53 seconds with sorting, and 42.096 seconds without sorting using 1 core on 5930K.

#!/usr/local/bin/python3
import random, string

a = []

def mk_file(ff):
    with open(ff, "w+") as f: f.write("\n".join(a))

def sort_arr():
    a.sort()


print("creating array")
for j in range(1000000):
    a.append(''.join(random.choice(string.ascii_letters) for i in range(64)))

print("sorting array")
sort_arr()

print("dumping array to file")
mk_file("1m.sorted.lst")
3 Likes

Node is on the server side… and at least Javascript (on the client) doesn’t require installation of the Oracle (or other, shitty) Java runtime as well.

You still need a bloated browser that can run the JS code. The fact that it is not a different application is of no concern.

Java is big gay if its not on sparc. You inherently need a VM to emulate a native system.

Therefore it is stupid.

i rest my case.

1 Like

Well it kinda is… because name a modern graphical browser that doesn’t include javascript?

You get it by default.

Debian 10 comes with node preinstalled, don’t know how other server-oriented distros come out of the box.

The thing is:

Most if not all languages except from Assembly, C/C++ and some other ancient godlike ones are kinda bloated, we can’t deny it.

I had a big let-down with Java this week, I compiled it on my laptop with openjdk 11(on buster) and the stupid bytecode didn’t run on the even more stupid W10 running oracle’s jre 8… it’s not backwards compatible.

That is pretty easy to achieve. When you target java11 its only gonna work on 11+ (you can target lower java version than what you use to compile, then it will work normally). When you use modules its only gonna work on java 9 and above. When you use openjfx its only gonna work on java 11 and above. If you use any platform specific library, you also either have to package in the packages for all operating systems into a big fat jar. Or make multiple of them. There are many reasons why it might not run.

Java 8 is a huge roadblock to get past to java 9+ for many project. 9/10/11/12 usually is easy going afaik. But breaking down your program into modules is kinda a pain to have to do. And yes you absolutely have to do that at some point as it looks now. Witch is why you will see many programs, libraries, frameworks still stuck on java8.

Their module system really seems to me as if they primarily made it to make their own life easier developing the JDK. Especially, since other JVM languages like kotlin have no support what so ever for modules, they just compile to java8 bytecode. Witch there is usually no problem running that on java 9/10/11/12, until you use libraries that depend on newer features that you cannot just recompile to java8 bytecode.

3 Likes

Don’t think the 100.000 rows limit is because of JavaScript tbh. Think it’s the browser part that runs it.

1 Like

He’s probably running it on node (v8 based), which is multithreaded… I still don’t understand why he isn’t achieving 100,00

so it is backwards compatible, but just in a different way?

I ran it in Firefox console lol

2 Likes

I don´t know why, but the firefox console seems to be MUCH slower. Though, I get to 999999 putting your code snipped into the console too. (This is not your code snipped I tried to make it faster).

For the first number I just put it into a .html file.

<meta charset="utf-8">
<script>
    (() => {
        const p = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        const AMOUNT_TO_GENERATE = 999999;
        const STR_LEN = 64;
        let strBuffer = [STR_LEN] 
        let start = performance.now();
        function randomString(len) {
            for(let i = 0; i < len; i++) {
                strBuffer[i] = Math.floor(Math.random()*p.length);
            }
            return strBuffer.join('');
        }
        let arr = [AMOUNT_TO_GENERATE];
        for (let i = 0; i < 999999; i++) {
            arr[i] = randomString(STR_LEN);
        }
        console.log(`Took ${performance.now() - start}ms`);
        console.log(arr);
    })();
</script>

Note: <meta charset="utf-8"> is not it. The only reason I put that there is so that firefox does not complain that I don´t have my charset set.

3 Likes

I know I already posted a lot here, and even the forum told me to stop (I will soon enough).

But just now I discovered there are optimization paths on gcc… yeah… also argc and argv are pretty new to me, I’m not very proficient in C, but it’s ok.

So later I’ll bring my laptop to work to try and optimize the compilation and bring some real numbers to the table.

^ this is what I’m talking about… later I’ll have news, perhaps…

hey I make my bread on java teams cleaning up after those guys. Can’t fire the one guy who knows how to write a deploy script.

1 Like

Yeah. It seems to me that Java is really good at building the bullshit part of applications. By bullshit I mean what makes it “different” or “value-adding” part. Don’t get me wrong this isn’t a small thing, it’s not a microservice language, it’s built for apps with large amounts of bullshit.

Whereas a substantial number of the major components/needs already exist - SQL, Webservers, reverse proxy, networks, operating system, jvm, email servers, etc.

They just need to write the bullshit part of the app, and have it use the provided interfaces/ libraries with the above listed items.

And then again, java has great libraries so if you know your data structures and algos and can architect the app it’s pretty much know your libraries and it’s snap and play.

It’s also “garbage collected.” Like no one has ever seen a leaky java app lol.

Cloud native application may save us from a lot of these bullshit applications, but there will always be local apps running bullshit. Much of which will be java.

2 Likes

I know this is an older post, but that’s not what backwards compatability is. Compiling in JDK 8 and attempting to run in JRE 11 would be supporting backwards compatability (on the part of JRE 11). Compiling on JDK 11 and attempting to run in JRE 8 would be… forwards compatability I guess lol.

And perhaps a follow up, some legitimate backwards compatability was broken in JDK9 (and its a major point of contention between Java developers), but I think its unlikely (though quite possible) that you’ve run into that issue here.

I would recommend keeping both OpenJDK 8 and 11 on your machine. Most everything new should generally be compiled with JDK11 (unless you’re contributing on a project that hasnt made that switch yet), and 8 is handy for running legacy code. Most IDEs will let you change your JDK on the fly in the project settings (I personally believe that IntelliJ is the easiest for this, but that is entirely personal preference).

2 Likes