lainchan / λ

(untitled)

Guthrie · 2020-02-12 04:36
I see a lot of discussion about other languages like C++, but I haven't seen a Java board at all. What does this board think of Java?
James Gosling · 2020-02-12 07:48
Without running the following code, can you correctly guess what it will print? java abstract class Eggs { abstract void m(); Eggs() { m(); } } class Toast extends Eggs { private Integer x = 2; Toast() { x = 3; } public void m() { System.out.println("x = " + x); } public static void main(String[] args) { new Toast(); } }
x<->y · 2020-02-12 08:02
>>16865 You got me, I'm not quite sure. Then again, I am still technically still learning the language and are not familiar with anything beyond the basics. Why do you ask?
Cat Mother · 2020-02-12 08:35
>>16865 i'm a bit rusty with java, but here goes. i think it should print 2, because when a constructor of a subclass is called, the constructor of the superclass must be called. if the said constructor has no arguments, it's implicitly called as the first statement of the subclass constructor. if it had arguments, it would have to be an explicit first statement. please someone correct me if i'm wrong. Also some thoughts about java. I live in a developing country, and almost all of the people in my uni use .net for webdev at their jobs, it's quite rare to find a java guy. is java dying? i don't think so, but this fact seems a bit weird to me. java and c# are very similar, not counting syntax differences and linq probably. both have lambdas, similar exceptions etc. is it just a temporary meme?
Nanashi No Gombe · 2020-02-12 09:31
>>16865 I think if it's time to either add comments or refactor. I'm not going to deep dive into the java spec just to determine the output of your program THAT DOESNT EVEN DO ANYTHING
James Gosling · 2020-02-12 09:56
>>16866 > Why do you ask? Because it's a fun gnarly puzzle that someone showed me once, and this is the Java thread. >>16867 Have you run it? Does it match your expectations? If not, can you speculate as to what's happening?
Yamaoto Toshi · 2020-02-12 10:14
>>16870 i have just now. turns out it prints null. i put the m() call into the subclass constructor, and the it finally made sense. when m() is called, it is called in the superclass context, so to speak. there's no x defined in the superclass, hence the null value.
Lukasiewicz · 2020-02-12 10:19
>>16871 furthermore, i tried defining x in the superclass with value 1, still null. fuarrrking weird. maybe the defined method refers to that specific variable in the subclass, which, when called from the subclass context, doesnt exist?
Delilah · 2020-02-12 10:21
>>16872 i meant superclass context, oops
Kay · 2020-02-12 14:36
>>16872 I don't think it's that m is run in the superclass context. "Virtual" tells it that the method is only implemented in the subclass. Furthermore there isn't really a "superclass context" because the superclass isn't actually instantiated. I don't know much about Java but in a lot of OO languages initializing member variables happens in an implicit "pre-constructor" that in this case runs after the superclass constructor (because x isnt defined in the superclass). I would guess that initializing x in both super and sub classes would return null but initializing only in the superclass would return its value. I'll have to check this when I have some time and get back to you.
queue · 2020-02-12 14:43
>>16875 >virtual abstract I mean... as you can tell my OOP experience comes from C++ and C#
Bobby Newmark · 2020-02-12 23:35
Kotlin is an amazing jvm language and the multiplatform support will be game changing. Started using it professionally around two years ago. I don't dislike Java but it would be annoying to have to go back to it now.
Judge Fang · 2020-02-13 04:53
Clojure is a Lisp for JVM, complete with interop. You'd be better off learning that than java.
Nobody special · 2020-02-13 18:00
>>16880 Could you elaborate on why you think this is the case?
Tequila · 2020-02-14 02:01
>>16894 >why LISP has significantly more power than java. This is more than expressiveness, it treats everything as a first-class construct that can be manipulated and transformed. Macros are a thing of magic. This means you can embed custom DSLs into your code with minimal effort. Java can do none of these things (and given its arcane syntax, I doubt you would want to work with it in such manners). LISP skills also transfer to other LISP dialects. The nice thing about clojure interop in particular is you get all the standard library of java without the hassle.
Sipho Nkosi · 2020-02-14 14:59
>>16879 >Kotlin is an amazing jvm language and the multiplatform support will be game changing. Are we talking "multiplatform" in the marketing-drone sense of the phrase, "android and ios!!!"? Or are we talking "multiplatform" as in the real sense of the phrase, "windows/macos/linux/bsd/android/ios/etc/etc/etc"?
HELIOS · 2020-02-14 17:34
>>16912 >JVM >multiplatform I think this answers itself.
Faye Valentine · 2020-02-14 18:21
I use java in one of my projects but im not a fan of it. Its ok as a language and has its uses but i cant understand why some people love it so much.
Hagbard Celine · 2020-02-14 18:36
Out of all the languages I've used it has been by far the least enjoyable. I truly hate it. I didn't get good at it but it just wasnt enjoyable to try to understand it. Other languages like Rust and C++ are difficult but also not suicide-inducing to learn. I don't really know why this is. Perhaps because it enforces OOP in places where I don't want to use it
DEBUG-CONTENTS · 2020-02-14 20:03
Everybody loves to hate it. But it's really not that bad of a language. It's just a little boring. But the tooling and library eco system are pretty good.
John Titor · 2020-02-14 20:04
>>16917 If you think C++ is not "suicide inducing", then you clearly have not spend enough time with it.
x<->y · 2020-02-14 20:25
>>16919 or we're not plebs.
Torvalds · 2020-02-14 20:58
>>16916 I think java fans appreciate the ridiculous amount of standard libraries. I think that it's also just the first thing a lot of people learn. I love LISP but I also acknowledge that the LISP people got to me first, before I even set foot in a college programming class. When they taught us Java in college, that was the first pogramming experience for a lot of my classmates.
null · 2020-02-15 11:24
Member javastation? I member
Milner · 2020-02-16 19:19
>>16918 I think it is that bad. The type system is weak. It has checked exceptions but without a strong enough type system to handle them. Lack of operator overloading makes many types disgusting to work with, including basic ones like BigDecimal etc. Annotations make it really non-obvious what code is even running or why something is failing. It makes you repeat yourself over and over again for basic things, like defining getters and setters for each private variable in each class even though they all look the same. This is code duplication, but it's considered 'best practice' cause there's no other way to maintain type safety and hiding. >>16921 >ridiculous amount of standard libraries What are the libraries for? I'm always annoyed at how much basic stuff is missing from the Java libraries. There was no join function till version 7.
let · 2020-02-17 05:07
>>16929 I dunno. I never used Java for anything but homework, but I always assumed that java users just imported libraries for everything and only wrote the bare minimum required to hook everything together.
Delilah · 2020-02-17 18:10
I like a lot of things about it, but as a whole I just can't get behind Java. The big issue is how it forces a very complex and unintuitive form of OOP for more or less everything. It puts a very firm limit on the flexibility and expressiveness of the language, and makes what should be simple tasks unnecessarily difficult.
Junichi Fujiwara · 2020-02-17 19:14
>>16935 I remember trying to port sicp's hardware description language over to Java. It was a really weird experience. I ended up making a completely empty "Component" class that had void methods and did nothing, then all the logic circuits and half adders or whatever were extensions of the "Component" class.
The Phantom Phreak · 2020-02-19 18:11
>>16937 Congratulations, you invented abstract classes/interfaces
XERXES · 2020-02-19 18:21
>>16972 feelswrongman
The Oracle · 2020-02-23 18:14
>>16865 1. the statement "new Toast();" calls Toast's constructor 2. before Toast()'s constructor body is processed, "extends Eggs" means Toast needs to first inherit everything from the Eggs abstract parent class and run Eggs' constructor 3. "m();" calls m() method in Eggs which is abstract meaning it must be defined in a subclass 4. Toast's m() method is called and prints the line x = null because x has not been assigned anything yet, it only gets assigned a value after the Toast constructor body is processed (3, which overrides the default 2)
hash table · 2020-03-16 08:17
>>16855 In my experience, people who prefer text editors to IDEs hate Java I really like Eclipse, so naturally I like Java >>16865 never call non-final methods in a constructor this extends to methods called by those methods >>16901 LISP curse, http://winestockwebdesign.com/Essays/Lisp_Curse.html
JARGON · 2020-03-21 16:35
>>16855 i get PTSD when i see that logo
Neo · 2020-03-21 16:36
>>16879 No, it's soykaf. I bet you like Ceylon too. Or Vala(Elaborate on your opinions rather than just spilling the soykaf.)
Turing · 2020-03-23 21:19
>>16879 Kotlin is crap. They turned each an every Java bad practice into a language feature, and added syntactic sugar for it. The selling point is that the present day Java and Android devs are too retarded to write in Java, which is true, but still what they offer is crap.
Miho Iwakura · 2020-03-23 21:48
>>17544 To elaborate on this. Utility classes, a procedural anti-OOP practice is a common pit fall of Java. They made it a feature called extension classes, an arbitrary Kotlin project has tons of them. Kotlin itself wraps pretty much every JDK class with an extension. Violating LSP (which is something only a complete retard would do in Java) is okay (advertised as delegation), and a syntactic feature also ("by" keyword in a class definition). Kotlin's data classes are DTOs from early Java, proven to be a poisonous way to handle data. They even brought multiple inheritance back.
↑ · 2020-03-24 00:44
I have been learning programming for the past couple of years, first python, then C. A couple of months ago I was forced to use windows for a bit, and tried out C#, and it left this weird tingle in the back of my head for "true OOP" now I have been looking into Java and I find it quite interesting. I really like the fact that I can run my programs on any computer with JVM on it and Jshell has got me covered on the "Tab to browse methods" department. Also I have not needed to import a single third party lib jet, which is a big plus in my eyes. So to conclude, I really like Java as an exploration tool in OOP land.
Judge Fang · 2020-03-25 13:58
>>17546 ooooooooooooof i hope this is fake i feel sorry for this d00d. >True OOP >Java wut. it's basically the same thing as C# (t 15 years of programming, including lots of java and C# once in a while) >I really like the fact that I can run my programs on any computer with JVM on it every language and their mom are portable. "java is portable" is a big meme. it's basically just as big of a pain in the ass to get any java program to compile and run than any other program even C. because there's still always some random system-dependent crap, even in most java code
Debbie Charteris · 2020-03-26 22:14
I find old java disgusting and ungainly but modern java begins to look like a proper language. We already have javarx and java streams By java 14 we'll supposedly have: - true record types - type case matching - potentially fibers - lightweight virtual threads. So the features are great as well. I still prefer writing in Clojure as there's less ceremony when talking to the damn JVM, at other costs, but hey, I get a lisp on a SECD machine which is constantly improving. No complaints as of now. >>16901 The Clojure community has figured out that DSLs are actually a bad idea, and there's a preference now to separating data models from execution models (which macros complect). The idea is that you spec your problem out as data, Clojure's data literals being way richer than other lisps, then analyze it and emit the most efficient/optimized code you can. A good example is reitit, a routing library which chooses between 5 different routing algorithms when analyzing the routes. The analysis is done at compile time, not run time. Pretty cool imo.
Rick Deckard · 2020-05-20 18:27
Any of you guys want to make some Java project with me? I thought about writing REST api, for some sort of RSS reader - thats actually simple enough for one person, but we can make login functionality so every person can make own account, and share RSS reader with other users or whatever. If you have other ideas, please share, i am open to hear them! I like Java and its popular in job posting, but i rarely work in it, i do most of my projects in Python.
x<->y · 2020-05-20 18:59
>>16855 Java was my first exposure to learning a programming language. So many more lines required than an equivalent c++ program usually.
Mitnick · 2020-05-20 20:37
>>18679 Never learned much about java and don't have an IDE. Sounds like fun! How do I contribute?
cond · 2020-05-21 12:05
>>18683 Hi! Here is how you consume bbc RSS feed in PHP: $feed = simplexml_load_file('http://feeds.bbci.co.uk/news/world/rss.xml'); foreach ($feed->channel->item as $item) {echo $item->title . '<br>';} similiar with description. So backend is REST API that looks like: /post : you can add new RSS feeds to list /get : you choose RSS feed with certain ID and then you get resource in form: Title, Description. Thats all backend should do for now - its doing request to xml resource, it parses xml and returns result in humand readable form. Backend is correct if you can use it from command line with curl like that curl http://localhost:8000/post --x URL curl http://localhost:8000/get/id/1 Then another person write frontend: application that is doing requests to backend and just displaying data. For example it displays list of Title + Description of RSS feed like that <ul> <li> <h1>{title}</h1> <p> {description|}</p> </li> .... <li> <h1>{title}</h1> <p> {description|}</p> </li> </ul> You can write it in Vue pretty easily. So what you feel you want to make? Frontend or backend?
Unidentified · 2020-05-21 13:20
I feel I am in the minority that actually enjoys java for personal projects, although I don't think I'd use it professionally, I've seem some of the practices and they are sure as hell weird, but the object system when making cute little programs that do what you want can actually render into nice abstractions at times, although yeah shoving everything into classes does get kind old and you end up with a `Util` class with a bunch of random methods there quite often.
Boole · 2020-05-21 14:15
It was the first programming language that I learned how to use. I'm a bit sentimental for this language. It's OK I guess.
Davis · 2020-05-21 22:12
>>18694 I just got the first snippet to work (added "<?php" and "?>"). Neat! Adding RSS feeds should ideally try to scan a URL addition and see if the XML is actually at <website>"/feed/" and similar patterns... Or see if an RSS/Atom link is referenced on homepage. Shouldn't there be user accounts if everyone has own feed. What if someone doesn't check-in for 6 weeks? Some blogs post multiple times a day and some once in a long while... I think the XML sometimes has a recommended fetch update period, or just do all feeds on the same scedule. Sounds like it should store XML in between fetches... I'm afraid I don't know how to MySQL.
Jean Dupont · 2020-05-21 22:36
>>18714 >>18694 Forgot to add, not all RSS feeds provide a <description> and most that do just dump an article's whole HTML (without comments). Very few provide a brief <description>. Online magazines sometimes have authors different than the publisher on as a whole, and smaller blogs may have guest post authors not specified by XML tags... Podcast RSS feeds may have a download link different from description... It really is a mess! But if common issues get worked out then a system should cope 90% of the time. :/ Wait a moment, you want the frontend to request data peicemeal?
string · 2020-05-30 11:34
What's a simple book that gets straight into teaching you how to program in Java?
() · 2020-05-30 20:29
>>18909 Books never simple https://github.com/yfain/Java4Kids/blob/master/thewholebook.adoc This free book Not read, just wanted good choice to you Please post the books are not good for you and why? I need understand better
Ivan Horvat · 2020-07-03 21:34
>>16855 >What does this board think of Java? I don't want to hurt anyone's feelings who has good experiences with Java, but I so dislike it that just seeing it on the board reduces my perception of λ's aesthetic value.
Morpheus · 2020-07-03 23:00
>>19469 Cool story, but explain why you feel that way.
Torvalds · 2020-07-04 03:06
it's the best example we have of what happens if you take what everyone says they think they want, and you try to emulate an abstract composite of those opinions by taking a hocus-pocus derivative of dice-rolls and p-values. Based on that derivative, you hire a group of high-functioning down-syndromers to perform their interpretation of that abstraction, in exchange for ice-cream, to an audience of prisoners on death row, and guantanamo perpetual torture victims, and tinfoily 4chan alt-right /x/ers. Record their laughs, their sobs, and their sighs; if pitch > avg of pitch bring it down and speed it up and if pitch < avg pitch bring it up and slow it down. Mix those, layer them 3 deep, put that track on loop and record your dreams and the dreams of others on the development team. Ask children to interpret those dreams with drawings. Layer upon layer upon layer upon layer of nonsense: if we pile on more nonsense will it bring us back to something sensical? No. It's like that person in a discussion group who gets everyone's attention and gets off track with his conversation. He realizes that he's off track, and he can tell by the looks in everyone's eyes that they are totally lost. Does he keep talking, hoping to find some common thread and regain coherence, or just throw it all up in the air and say "I dunno wtf i was talking about anymore" ? what people (in general, not just programmers) think they want is often different than what they actually want. Some things are better left in the "want to want" so we can focus on what's "better to have." that being said i've spent quite a bit of time reading java code and have never been able to fully understood much of anything. there are just too many layers of bullshit and it never seems to go anywhere. I find an interesting function, but it's one line. All of the elements of that function are related to a method included in one of the fifty million imports specific to that file. I dig through the imports looking to see functionality, and, guess what? more references to other files.
Knuth · 2020-07-04 16:43
>>19469 lol, get a job smh
Zhora · 2020-07-06 15:38
>>18918 Not necessarily a good first book but Effective Java is a book I wish every professional Java developer would read.
Random · 2020-07-13 13:53
>>19477 Thanks, that was the reference I was looking for.
Terzibashjian · 2020-08-14 14:52
>>19558 So I am going with it, but first of all, I just ordered pic related, as it is recommended by Joshua Bloch. What am I in for ?
Judge Fang · 2020-08-15 00:12
Java is getting a lot of hate in this thread. It was the first language I learned and I make a pretty good living off using it. It’s unparalleled in integration space (except maybe for C#, which I haven’t used but I understand is basically the same thing from Microsoft) which is what I use it for. I don’t think it’s ugly or difficult to read, but it does have a lot of boilerplate code - I’m stuck on Java 8 for the foreseeable future but I think this has been reduced somewhat in the most recent versions. People don’t like it, that’s cool. It’s not aesthetic, but it’s ubiquitous and well-supported, with decent build and CI tools. I’ll never understand people who turn away from it because it has a lot of third party libraries - all that means is I can focus on actually building my application rather than building the library first.
over · 2020-08-15 07:29
>>17545 Valid criticisms if you drink the koolaid of OOP. As a non-Java programmer, I never bought into the whole "inheritance is the hammer to use on everything" mentality. Kotlin makes Java a little more tolerable to me.
Agent Smith · 2020-08-15 16:45
Java is my favorite language. It is very simple and is definitely made with producing serious programs in mind. The jvm is nice for a couple of reasons, one being that it is easier to set things up. I wish C++ was like Java with managed memory. Use it with lombok to reduce a lot of the boilerplate.
fsociety · 2020-08-15 17:39
Having worked with Java for a past employer I can say that it's not that bad as people make it out to be. What makes it bad is trying to work through code that an underpaid H1B worker made with no documentation, tests, or any consistency. I think most of the hate from Java comes from the surge of Indian developers that are trained to use it poorly from DurgaSoft or other similar companies. >>20262 Have you given Clojure a try? I've recently gave it a try and it's been great working with the JVM and Lisp.
Apoc · 2020-08-16 02:13
>>20278 > wish C++ was like Java with managed memory. You might want to try D, then.
Wirth · 2020-08-18 09:45
>>20278 I am learning it, and for now I like the feel of it. Very comfy, very straightforward. It is verbose, yes, but I don't mind it. I prefer writing and reading Java than C# with all its syntactic sugar, just because of its annoying way of wasting a line for each bracket.
Project 2501 · 2020-08-18 13:19
>>20282 GP poster. I’m really, really intrigued by Clojure. I gave it a shot about a year ago and found it nice, but I also found functional programming very confusing at the time. This was just as I was starting to look at the functional interfaces introduced in Java 8 (I use Java professionally everyday but I work for a pretty old school integration software consultancy, we’d probably still be on Java 6 if it it was supported - never had any need to look into functional interfaces until I discovered the streams API while searching for a way to make my code less verbose and reduce boilerplate code). I feel a little bit more comfortable with functional programming now, so I might start looking into Clojure again. It definitely has the benefit of having Java libraries available - I use Apache Camel and am not aware of another EIP implementation with as much tooling (and I think they’re all Java anyway). Though I do quite like OOP, so it would take some time and adjustments to get used to having it taken away from me. I’ve thought of looking in Scala for this reason, but it looks like it’s waning in popularity compared to Clojure, and learning a lisp properly would be neat.
St. IGNUcius · 2020-08-25 18:20
>>17545 Kotlin doesn't have multiple inheritance. Delegation doesn't violate LSP. It's just syntactic sugar for passing method calls to another object. It encourages composition over inheritance. https://kotlinlang.org/docs/reference/delegation.html Data classes are not DTOs, they are POJOs with automatically generated hash and equals. They are intended to be immutable and have a copy method to help with that. DTOs on the other hand are a design pattern with a specific use-case https://martinfowler.com/eaaCatalog/dataTransferObject.html Extension functions are great for writing clean code - they take static methods in Java and provide syntactic sugar for improving readability and use. Particularly useful when working with 3rd part dependencies. It isn't anti-OOP, if anything they make static methods more OOP friendly. https://kotlinlang.org/docs/reference/extensions.html I personally love Kotlin atm. We switched to Micronaut with Kotlin at work and it has really improved productivity and developer joy. I don't usually reply to devs who dismiss others as retarded. I only replied because your comment is poorly written and paints a very misleading picture of the language. You should feel bad.
if · 2020-08-26 01:43
>>16865 Shit like this gives me PTSD from taking the comp sci AP in highschool.
typedef · 2020-08-26 03:42
>>20464 does Kotlin really work that well with GraalVM? last I checked the performance was absolutely atrocious, far worse than Kotlin Native, but that was a year-plus ago.
Ivan Petrov · 2020-08-26 08:27
>>20474 We've noticed performance drops related to GraalVM both in Java and Kotlin, though it wasn't major. It's in our backlog to try out the profile guided optimisation trick, but it hasn't been causing us enough pain to prioritize it. I've only built toy apps with Kotlin Native. It's more limited than GraalVM and doesn't look production ready just yet. Very promising for iOS development though.
Erik Johansson · 2020-08-26 13:17
The biggest feature of Java is making me able to buy food and pay my rent. Other supposedly better designed languages such as Haskell do not possess this feature.
John Rain · 2020-08-27 04:53
>>19471 I'm not Ivan Horvat, but i might as well be. One thing that annoys me about Java is how illegible it is. Compare the following Java and not-Java lines. if( item.getValue().subtract( price.multiply( amount ) ).compare( cash.getValue().add(collateral.getValue()) ) > 0 ){ if( item.value - price * amount > cash.value + collateral.value ){ return Arrays.asList( father.getName(), mother.getName() ).contains( person.getName() ); return person.name in [ father.name, mother.name ];
Zero Cool · 2020-08-28 00:45
>>20490 What's the other language?
Hong, Guil Dong · 2020-08-28 14:17
>>20505 Looks like some pseudo-python.
Anamika · 2020-08-30 07:38
>>20505 >>20509 >pseudo-python basically ya, i guess i should've used colon instead of brace in the first one. The first example would be basically the same in any language that supports operator overriding though.
Tomohisa "Tom" Kanezaki · 2020-08-30 21:46
>>16865 I'm pretty sure it will print nothing, as you overrode the constructor for Eggs.
queue · 2020-09-08 01:42
Anyone want to check out my sieve of Eratosthenes? public static boolean[] sieve(int n) { int limit= (int)Math.round(Math.sqrt(n)); boolean[] checkList= new boolean[n+ 1]; //Initialize the checklist with all true for(int i= 0; i< checkList.length; i++){ checkList[i]= true; } //Run the sieve for(int i= 2; i<= limit; i++){ if(checkList[i]){ int k= 0; for(int j= i* i; j<= n; j+= i){ checkList[j]= false; } } } return checkList; } So far it works, but I would liek some tips on how to improve it.
car · 2020-09-08 07:05
>>20716 Why initialize everything to true, instead of writing it so that it uses the default value (false) tge way you use true?
drop · 2020-09-08 17:17
>>20719 No reason other than I didn't think at the time, it can absolutely be done the way you said with minor changes and I coded it, thanks!
Koichiro · 2020-09-09 06:09
how can i find an introduction to java text? i know some basic python
Stallman · 2020-09-09 08:59
>>20719 I personally prefer to explicitly initialize things. I think it's better to have stuff written down concretely, so I don't have to remember any rules to know what's going on. It's all just right there in the source with no ambiguity. I think most of the time I've spent "stuck" has been dealing with bugs caused by implicit operations.
t · 2020-09-09 11:55
could you guys rate my solutions to assigment tasks i got? I got ghosted, i wonder if its because code is spaghetti and bad, i dont write Java that much 1. Find first non-repeating character in string, import java.util.ArrayList; import java.util.HashMap; public class Solution1 { public static String nonRepeating(String str) { HashMap<Character, ArrayList<Integer>> hashMap= new HashMap<Character, ArrayList<Integer>>(); int index=0; int minIndex=str.length(); for (char c : str.toCharArray()) { if(hashMap.containsKey(c)) { hashMap.get(c).add(index); } else { hashMap.put(c,new ArrayList<Integer>()); hashMap.get(c).add(index); } index += 1; } for(ArrayList<Integer> value : hashMap.values()) { if(value.size()==1) { if(value.get(0)<minIndex) minIndex=value.get(0); } } return String.valueOf(str.charAt(minIndex)); } } 2. Find if string can be turned to palindrome by deleting at most 2 characters. If its not possible return "not possible". Return "palindrome" if string is already palindrome import java.util.ArrayList; public class Solution2 { public static String PalindromeCreator(String str) { // code goes here ArrayList<Integer> changes=isPalindrome(str,new ArrayList<Integer>(),0); if (changes.size()==0) return "palindrome"; if(changes.size()<=2) { String changedChars=""; for (int i : changes) { changedChars+=str.charAt(i); } return changedChars; } return "not possible"; } public static ArrayList<Integer> isPalindrome(String s, ArrayList<Integer> indices, int index) { if(s.length()<=1) return indices; if(s.charAt(0)==s.charAt(s.length()-1)) { return isPalindrome(s.substring(1,s.length()-1),indices,index+1); } else { indices.add(index); if(indices.size()>2) return indices; return isPalindrome(s.substring(1,s.length()),indices,index+1); } } } 3. Reverse Polish Notation calculator import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Deque; public class Solution4 { public static String ReversePolishNotation(String str) { // code goes here Deque<Integer> stack = new ArrayDeque<Integer>(); int i=0; int second=0; int first=0; while(i<str.length()) { char c= str.charAt(i); switch(c) { case '+': stack.push(stack.pop()+stack.pop()); break; case '-': first=stack.pop(); second=stack.pop(); stack.push(second-first); break; case '*': stack.push(stack.pop()*stack.pop()); break; case '/': first=stack.pop(); second=stack.pop(); stack.push(second/first); break; case ' ': break; default: String number=""; while (str.charAt(i)!=' ') { number+=str.charAt(i); i+=1; } stack.push(Integer.parseInt(number)); } i+=1; } return String.valueOf(stack.pop()); } }
Yu-ichi · 2020-09-09 12:01
>>20746 i think first task can be make faster by using orderedhashmap or something like that, i probably did it like that on assignment site, but forgot to copy it into IDE
Demeere · 2020-09-10 10:11
>>20746 >nonRepeating You do not need a growing ArrayList<Integer> with all the positions of c. It is sufficient to keep the first position and the count, in fixed storage per c like new int[2]. >isPalindrome >else { This else branch needs a little more thought. Think about "rotors". >ReversePolishNotation >while (str.charAt(i)!=' ') { This will run over operators if they are adjacent to numbers, like "1 2+". >number+=str.charAt(i); Get the number once with substring after the loop using indices, instead of building a new immutable String at each step of the loop.
Church · 2020-09-14 02:06
I'm working my way through a book. I'm almost done with the recursion chapter, one of the exercises asks to do develop a recursive method that finds the largest double in an array and return it. I hacked this together in emacs and so far it works: public static double maxInRange(double[] array, int lowIndex, int highIndex){ if(lowIndex== highIndex){ return array[lowIndex]; } double rec1= maxInRange(Arrays.copyOfRange(array, lowIndex, highIndex/ 2+ 1), 0, highIndex/ 2); double rec2= maxInRange(Arrays.copyOfRange(array, highIndex/ 2+ 1, highIndex+ 1), 0, highIndex/ 2); if(rec1> rec2){ return rec1; } return rec2; } However, I don't feel like it's good or it makes for a good answer to the exercise, please critique my code and/or correct it
Dujour · 2020-09-14 02:08
>>20812 I should add, it's the largest double in an array between indexes lowIndex and highIndex, included.
if · 2020-09-14 11:21
>>20812 def max2(arr,m=-math.inf): ... if len(arr)==0: ... return m ... if arr[-1]>m: ... m=arr[-1] ... return max2(arr[0:-1],m)
drop · 2020-09-14 13:57
>>20812 The copying is pointless and your index computations are wrong. Try it on lowIndex=7 and highIndex=9.
Ein · 2020-09-18 17:19
>>16855 Really excited for new stuff coming in Java's future >Records (Java 15, now GA) >pattern matching (see https://cr.openjdk.java.net/~briangoetz/amber/pattern-match.html) >Project Loom will make Erlang on JVM viable. Available as preview.
Wintermute · 2020-09-18 20:13
>>16855 Do lainons use Java for bioinformatics?
Neo · 2020-09-19 01:51
>>16855 It is like kicking dead whales down the beach,
Wirth · 2020-09-20 02:18
It basically doesn't matter what language you use. Everything there is to say about Java (or Python, or Rust, or Scheme etc.) is just worthless trivia. All that matters is what you build. Having a bunch of threads about different languages shows that Lainchan is unenlightened.
The Plague · 2020-09-20 03:26
>>20920 How clearly you can express a computation isn't what I would call worthless trivia. It's true that you can do basically anything in basically any language and there's a lot about solving high level computing problems that is outside the realm of any one language's features. However, the language that you use will affect how you typically think about solving a problem. If someone uses a specfic language, then their world of thinking usually gets restricted to what's convenient to express in that language. And what's convenient to express in a language is almost always dictated by how easy it is to implement a language's features. If a good solution to a problem happens to be convenient for the features of a language, then there isn't a problem if the designer can find that solution. It's not just what features a language uses though, it's also how well those features are put together. For example, javascript and scheme both have some conception of promises and closures, but we'd be living in a different world if netscape had gone with scheme instead of javascript. It probably wouldn't be all that different though, because people would just write scheme in the style of whatever language they used before. What the designer makes is more important than what language they use, but a designer that uses a well designed language has a greater chance of putting out something well designed themselves. So I tend towards the idea that discussing the advantages and disadvantages of different languages is good as long as people bother to put thought into their analysis and bother to keep solving problems in whatever language they use.
Eldon Tyrell · 2020-09-21 04:18
>>20920 Give me an example of an enlightened thread then.
John Rain · 2020-09-29 00:15
>>20936 IDK about enlightened, but perhaps a better board would have threads about different project and fields instead of threads about languages containing mainly people doing homework and toy projects. But imageboards have a young audience, and >>20920 is being kind of a soykafhead.
Unspecified · 2020-09-29 03:40
Is JavaFX free software? The website says it's open source, but wikipedia says otherwise.
drop · 2020-09-29 06:02
>>21030 Just your friendly reminder that >free software != open source But as for JavaFX, I believe there is the oracle implementation of it that came with Java 8 (up to some version number?) and then there is openjfx, the open source version of javafx. Similar to how there is the java sdk from oracle and the openjdk, that is open source.
stack · 2020-09-30 03:18
Is evasion of the word filter allowed to everyone or is it a violation? ѕ U+0455 Ll CYRILLIC SMALL LETTER DZE h U+0068 Ll LATIN SMALL LETTER H i U+0069 Ll LATIN SMALL LETTER I t U+0074 Ll LATIN SMALL LETTER T h U+0068 Ll LATIN SMALL LETTER H e U+0065 Ll LATIN SMALL LETTER E a U+0061 Ll LATIN SMALL LETTER A d U+0064 Ll LATIN SMALL LETTER D
sage · 2020-09-30 05:25
>>21027 I was hoping for a new or existing example though, so me, the ѕhithead, and others could enjoy whatever interests the ѕhithead.
dictionary · 2020-09-30 08:52
i have job interview for Java EE position, hope il get it, i dont know much about it, i am python programmer
Netrunner · 2020-09-30 15:19
>>21043 I don't think so. The filter is only there to detect new users >muh censorsheep, why can't i say f-u-c-k >i hate this site, it is full of name users
Wirth · 2020-09-30 18:46
>>16865 I find it kind of funny, I find it kind of sad, I found soykaf like this in production and wanted to make the dev team hang
Crash Override · 2020-09-30 19:00
>>16855 Java is eternal, the demiurge that rules over our operatin systems, our databases, and our lives! The foolish do not fear Java and suffer its wrath! Java is the judge, jury, and executioner. Blessed be to Java, and to the JVM! Before the universe existed, Java was there. In the beginning was the JVM, and the JVM was with Java, and the JVM was Java. ... and Java hovered over the chaos in the servers, and saw that it was not verbose enough. From the waters of that chaotic deep rose gradle, blessed be to OOP! Victorious over procedural langs! From dust our crappy systems were born of the JVM, and to the dust of the JVM they shall return! OOP is the problem, but OOP is also the solution. OOP is the dependency quine, an eternal ouroboros that rules over our systems! That defines our corporate hell heaven! Blessed be, BLESSED BE OOP, BLESSED BE JVM, BLESSED BE JAVA, BLESSED BE ITS CHILDREN, BLESSED BE! In the name of the JVM, Java, and OOP. Amen.
Special Agent Bob · 2020-09-30 19:28
>>21043 Just stick a zero width space anywhere in the word.
Mitnick · 2020-10-12 15:37
>>21046 i got this intership, its one month long and then they will decide if they want to hire. They also said they will have more interns so probably they will hire 1 or 2, and rest will remain jobless. I spend this 2 weeks left to internship creating own simple imageboard with rest api/hibernate, simple login system. I dont know how to test it yet. And i am bad is JSP/JSF i made frontend in JS. I am afraid i will never make it bros
Delilah · 2020-10-14 12:46
>>16865 Pretty sure it’s two, the eggs constructor gets called first, which calls its implementation of m, which is implemented in toast, where x hasn’t been set to 3 yet, so 2 will print them x gets set to 3 and then the program ends
Dujour · 2020-10-24 22:46
I generaly use java to make programs, since most of them should be graphical, swing is really easy to use. I would prefer other language like python or someday c/c++ but in them is not that easy to get a graphical application up and running
Haruyoshi · 2020-10-29 03:14
>>16865 It doesn't print anything because the super constructor is not invoked inside the child class. Also this kind of soykaf is what makes me throw up, and I use Scala.
Agent Jones · 2020-10-29 03:42
>>21709 https://docs.oracle.com/javase/specs/jls/se8/html/jls-12.html#jls-12.5 12.5. Creation of New Class Instances [...] 3. This constructor does not begin with an explicit constructor invocation of another constructor in the same class (using this). If this constructor is for a class other than Object, then this constructor will begin with an explicit or implicit invocation of a superclass constructor (using super). Evaluate the arguments and process that superclass constructor invocation recursively using these same five steps. If that constructor invocation completes abruptly, then this procedure completes abruptly for the same reason. Otherwise, continue with step 4. https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.8.7 8.8.7. Constructor Body [...] If a constructor body does not begin with an explicit constructor invocation and the constructor being declared is not part of the primordial class Object, then the constructor body implicitly begins with a superclass constructor invocation "super();", an invocation of the constructor of its direct superclass that takes no arguments.
J.C. Denton · 2020-11-05 01:34
>>16855 >What does this board think of Java? C# has deprecated Java. Indians BTFO!
Davis · 2020-11-05 10:40
>>21851 how easy is it to develop/deploy C# code on anything that isn't windows? on paper it seems like it'd be just fine, but nobody seems to do it.
Roger Pollack · 2020-11-05 15:54
>>21856 Its fuarrrking awful, almost worse than Mono. t. linux laymo
hash table · 2020-11-08 12:59
>>21856 Steadily improving but still awful to the point when I had to do something a C# project at my day job I ended up just installing a Windows VM purely for that project and the company was happy to pay for it with other devs having similar experiences.
byte · 2020-11-10 03:47
>>21851 >C# has deprecated Java Why do C# devs always show up in Java threads like this? Is it because nobody was interested in a C# thread and you're lonely? What would C# even offer over Java? It's basically a knockoff with fewer libraries, a license that isn't GPL, and no cross platform support. I can't think of any reason why I'd ever want to even try it because I can't stand Windows.
Jane Doe · 2020-11-10 14:00
>>22074 C# allows for manual memory management, which makes it way more suitable for things like gamedev that require consistent performance.
Dox · 2020-11-10 15:14
>>22080 If you want performance and manual memory management, and you don't mind giving up the JVM, then why wouldn't you just use Go, or even C++? Java is better than C# in the one and only way that would make you use either of these languages at all: the cross platform universal binaries thing.
Erik Johansson · 2020-11-10 16:30
>>22083 C# is used in Unity and Monogame, so people who use those also use C#.
Neo · 2020-12-06 12:30
Hey /lambda/, I don't know anything about programming but I found out about the nature of Java and its Java Virtual Machine about a year ago or so and my first impression regarding it was that it was very impressive. I didn't know people came up with such a solution. Unfortunately, I also hear very negative things regarding Java. My issue, while I haven't looked into the issue, is that it seems you cannot use the Java VM without paying Oracle for it. This is unfortunate because I think there's a lot of potential with the idea of a VM to increase portability. What I want to know is, are there any free alternatives to the JVM? A GNUVM, perhaps? And, how good are they? I like the idea of creating a videogame that, due to it running on a VM, has increased portability and longevity (you don't have to update the game to keep it compatible with the newer OSs although I suppose one would have to update the VM instead) so that's the reason for my interest in this topic. I'd like some feedback from people willing to impart knowledge in this area.
setq · 2020-12-06 12:47
There's a lot of such alternatives. Most mainstream ones are listed here: https://adoptopenjdk.net/
Ein · 2020-12-06 13:19
There's OpenJDK, but if you're not married to Java and just want to make a write-once-run-anywhere video game, there's also things like pygame and love2D, which are libraries for interpreted languages and therefore only need the interpreter to be ported. The Godot engine also works on a similar principle: there's a single executable per platform per engine version, and the game-specific data is platform-agnostic. I'd also recommend Godot just for ease-of-use reasons.
Rick Deckard · 2020-12-06 13:24
>>22973 JVM is an specification - you can build a "true" JVM, or you can make a VM that is compatible with such specification. The Reference Implementation code of the JVM has been open-source for quite a few years now. Oracle also makes built versions of the Reference Implementation, the Oracle OpenJDK. The thing is: Oracle only provides support or makes patches/fixes for the newest versions of the OpenJDK. The LTS releases, which are the ones most commonly used (Java 11, which is the most recent LTS release), are not actively supported. They do, however, provide support for their non-FOSS build of the Reference Implementation, the Oracle JDK. The paid one you probably heard about. It has a few proprietary components along with the base open-source code. You don't need these to use a "based on the Reference Implementation" JVM - there are many non-Oracle community-supported builds of the OpenJDK which provide support for LTS releases. I recommend the AdoptOpenJDK https://adoptopenjdk.net/ - but steer clear of using OpenJ9 as the VM, unless you know what you are doing (OpenJ9 is not a Reference Implementation JVM [such as HotSpot], but a different VM that strives to be compatible with a JVM specification and run the things that a JVM can run).
push · 2020-12-06 13:29
>>22975 Thank you. I have to say though, I'm a bit confused by the language displayed on this website. HotSpot and OpenJ9 are both listed as JVMs. That means they're both Java Virtual Machines, right? I thought the JVM was something proprietary which only Oracle owned which you had to pay to use. If there are multiple JVMs then which one is the one you'd have to pay for? What's that one called? Overall, thanks. I guess I'll adopt HotSpot as the VM for my game development in the future.
Jim Hilger · 2020-12-06 13:37
>>22978 Thanks for the clarification. So there's an Oracle OpenJDK (FOSS) and there's an Oracle JDK (non-FOSS). Got it, thanks. And then, outside of the Oracle-bubble of the Oracle JDK and the Oracle OpenJDK, there are community OpenJDKs! Ignore my previous post, the page had yet to refresh before I saw your post.
cond · 2020-12-06 13:58
>>22978 I just wanted to say: it's a bit weird that the JVM has the word "Java" in it. I mean, isn't "Java" itself a company? It just seems like referring to toothpaste by its product name (for example, "Colgate") rather than simply what it is: toothpaste. I mean, I guess it is true that sometimes people do actually do that like I was recently surprised to learn here in Britain that "Sellotape" is actually a product name and the product itself is called "Adhesive Tape" but nonetheless, that brings me to another question: If a JVM, despite the presence of "Java" in its name, is merely a type of thing then what's a VM? But I suppose for now, this question isn't something I need answers to. What matters is: I can make use of the portability this kind of software offers and I think that's great. Thanks to everyone.
Shogun · 2020-12-06 14:15
>>22982 Java is a programming language, not a company. The JVM is a program which runs code written in Java. More specifically, it's an interpreter for Java Bytecode, which is a sort of pseudo-ISA that Java compiles to.
Joey · 2020-12-07 03:53
>>22984 Alright, thanks.
Joey · 2021-01-05 18:03
>>22973 >This is unfortunate because I think there's a lot of potential with the idea of a VM to increase portability. The "VM" in this case isn't any different to most language interpreters combined with libraries that abstract the OS away for you. Solutions like this have existed for a long time and will exist for even longer. Look into for example CHIP-8 and SCUMM/scummVM, as well as more modern things like Love2D and the web browser you're probably reading this in. Hell, emacs lisp or Guile could be considered equivalents, so in a sense we already have this GNUVM.
Agent Richard Gill · 2021-01-06 10:57
>This is unfortunate because I think there's a lot of potential with the idea of a VM to increase portability. bytecode is a fuarrrking meme and was never anything more. even [[[Go]]] gets it right by not having one.
Ein · 2021-01-07 01:40
>>23753 The portability argument is legitimate. There's no reason one cannot make a language with a standardized bytecode which is then, on a per-case basis given an optimizing native compiler to the platform as dev-time allows.
Drifter · 2021-01-07 15:12
>>23769 Bytecode is also good for pure compilers (although in this context it's usually called an intermediate representation). If a language can be compiled to an IR, it can also be compiled on every system that has an implementation of the IR.
Just another Random Lainon · 2021-01-07 17:58
>>23753 A lot of compilers use a bytecode or another type of intermediate language for portablity reasons which it then compiles to the target language. This is meant to reduce the work needed to compile to a new target platform.
Noodle Soup -1/7 · 2021-03-21 08:35
I'm trying to figure out how to get a BufferedImage from the request.getParameter of a JSP form (the form that's on the JSP has an input field for uploading a .png image) what i need is something like //Servlet: doPost(request,response){ BufferedImage image = request.getParameter("imageInputField"); //here, i need to figure out how to transform the String to BufferedImage type
Lunch · 2021-03-21 14:34
>>25001 You get a BufferedImage from an InputStream with ImageIO.read. https://docs.oracle.com/javase/8/docs/api/javax/imageio/ImageIO.html#read-java.io.InputStream- To get an InputStream for a file upload, either: (1) parse the request with ServletFileUpload https://commons.apache.org/proper/commons-fileupload/apidocs/org/apache/commons/fileupload/servlet/ServletFileUpload.html then get your FileItem and from it getInputStream or (2) use getPart https://docs.oracle.com/javaee/7/api/javax/servlet/http/HttpServletRequest.html#getPart-java.lang.String- and from it getInputStream. Tutorial: https://docs.oracle.com/javaee/7/tutorial//servlets011.htm Another source: https://wideskills.com/jsp/jsp-file-uploading
Ivan Horvat · 2021-03-23 05:25
>>20490 You don't need to do .getValue(), right? You can just use .value if it's set to a public variable inside the class. And you can use operators instead of stuff like .multiply()
Nanashi No Gombe · 2021-03-30 06:14
>>25039 >You don't need to do .getValue(), right? If each class exposes value as a public member variable, you could, but the classes would be locked into storing the values as members forever for backwards compatibility. If you later want to only calculate or get from database only when needed, you wouldn't be able to without breaking existing code. As such, it's usually considered best practice to always use getter and setter methods, especially on larger projects. >you can use operators instead of stuff like .multiply() If all the values are primitive integer or float types, you could, but if they are anything else, you have to use methods because Java does not provide for operator overloading. If you even just need exact numbers or arbitrary precision or size, for example, you'll have to use an object type like java.math.BigDecimal without operators.
J.C. Denton · 2021-04-02 02:25
Can somebody explain the connection between RTTI and Polymorphism to me? These seem to be treated as different concepts, but doesn't Polymorphism use RTTI to do its thing? From my understanding they do pretty much the same thing, but Polymorphism works automatically, while RTTI is explicit. But I'm not sure if that's correct.
Noodle Soup -1/7 · 2021-04-03 07:15
>>25007 I forgot that i asked this here, thank you for the complete Answer! :D
synchronized · 2021-04-03 08:02
>>16855 Garbage language. The entire thing is a fuarrrking joke, it feels like a bunch of people sat down one day, and brainstormed what would make programming language a pain in the ass to use, and then created a new language based on that. At every step there are retarded anti-user features that make your life harder, for the sake of the designer's delusions about safety or whatever. It has not a single good GUI toolkit. >swing There's a reason why every program that uses swing looks like dogshit. The amount of effort you need to put into it not looking like crap is insane. >fx Slightly less crappy (better support for css at least). What do we do with the less crappy toolkit? Obviously remove it from the newer version, because we are anti-user and fuarrrk you. >bindings Both Qt bindings are trash. Jambi requires you to jump through 50 hoops to set it up, then you realize that you need to compile it yourself for it to work with non cutting-edge Java environments. Javacpp-presets is not even focused on Qt bindings, and has laughably little features (not even a goddamn QMainWindow). It's coupled tightly with fuarrrking IDEs, because its build and dependency system is a goddamn clusterfuck. I am not surprised in the least that webshit was pushed so aggressively. Even Javascript is better than this soykaf. The single positive thing I can say about Java, is that knowing it will make it easier to learn C#.
SHODAN · 2021-05-08 16:22
Java is nice for stuff like games back in the days of j2me where it truly shined although competitive games built from it are impossible due to hax but these days it's just a giant corporate blob that's on life support (and exists since companies depend on it the same way there's companies that still use windows XP along with activeX, or otherwise it's just something guaranteed to land you a java-based job for companies that somehow possibly infiltrated your schools curriculum the same way they teach proprietary crap like Microsoft tools and then fuarrrking keep students in the black by removing or never going in-depth with anything related to FOSS/linux/BSDs in a fuarrrking IT/CS course). Other than that maybe android jvm stuff but that might change too.
string · 2021-06-03 03:36
>>26073 (me) Oh yeah, I forgot: I hate Maven. I wasted countless hours of my time on Earth because it.
Moore · 2021-06-03 05:46
>>26074 >>26073 Agreed on most of this, except for Maven, Spring, and Hibernate. Maven makes life easy 95% of the time, and those times it doesn’t it’s because there is no alternative and the user should really get to building a plug-in which will do what they want (and give it back to the community if they’re nice). Never used Gradle so I have no point of reference here, but I hear it’s good too. I don’t need to use Spring much, but Spring Boot gives you everything for free. In fact I need to use more Spring Boot than I currently do. Everyone also seems to have moved on from using XML-driven configuration to using annotation-driven configuration, as it should be. Hibernate is not the tool for every job, but it’s the best way I know of to do type-safe object-relational mapping. jOOQ is not a one-size-fits-all solution, and I’m not using vanilla java.sql and SQL statements on anything but small projects. Everything else you’ve said I’m on board. I’ve also been very guilty of over engineering applications with unnecessary design patterns … I’m currently debating spending a few days removing all my interfaces and renaming impl classes in a reasonably sized project where they’re just not needed.
Dr. X · 2021-06-03 06:40
>>26073 >>26076 I don't understand why Spring is the way it is. Would it make more sense to create a new language?
↑ · 2021-06-03 06:49
>>26078 It’s a DI/IoC framework with scope creep, it doesn’t even have a DSL. I don’t think you could make a Spring language, Java fits the bill as well as any other statically typed C-like language.
Lukasiewicz · 2021-06-03 06:53
>>26078 >>26079 XML-driven declarative configuration was a mistake and the maintainers of Spring seem to have acknowledged that. It was in vogue at the time and it ended up sticking. One of the major pain-points with languages like Java is you get everyone - *everyone* - writing it, so you get a hell of a lot crap code and a hell of a lot of crap, dated tutorials and walk throughs on the Internet. It’s also a very stable language, and so is Spring, so it’s not going to stop supporting XML-driven configuration any time soon … which means you will have the same mistakes being made over and over, forever. But if you can look past the mistakes, you can write code which does what you need and leave the scaffolding to Spring, without some insane XML config which is a pain to maintain.
Lord Nikon · 2021-06-03 07:34
>>26079 >>26080 > scope creep yeah, that's what I'm talking about. I think it has something to do with the way java ecosystem works. It used to create top-down overly-engineered, overly-planned, overly-centralized solutions (like EJB), and Spring being part of this ecosystem couldn't evade this fate. In a sane ecosystem Spring would be a little library that parses an xml file and initializes some classes and invokes constructors or setters - that's all it would do, in accordance with the single responsibility principle. And even the use of this mini-library would be optional: you could just instantiate classes in main. But if you fundamentally change how objects work, if you wrap every object with a proxy, why don't you just create another language?
Koos van der Merwe · 2021-06-03 14:12
>>26073 I like Java and I don't mind using enterprise code practices, but this is very true: >I hate Spring, Hibernate, and their stack traces. Everyone soykafs on C++ templates for this, but it's the same really. I hate Lombok, it's useless, the IDE can declare the setters and getters for you already, what's the point? I hate all those "smart" libraries who do Lain knows what behind the scenes and are inherently undebugabble. fuarrrking hate it how every project I work on makes use of those. Spring supposedly reduces boilerplate, but what's the problem with boilerplate? If it is truly boilerplate then you can simpkly copypaste what you need. Spring always makes the project unreadable for me and I just go with it and the documentation. It unnecessarily forces you to do things a certain way. I hate it. Hibernate is ok, but not necessary.
x<->y · 2021-06-03 15:20
It has some decent libraries and ABCL makes it a usable platform. I'm okay with it.
Chan Siu Ming · 2021-09-24 11:00
I'm not very familiar with JAVA but I remember main() should be static. Does this code make sense?
HELIOS · 2021-09-24 11:32
did you write this? why not just run it and see? I believe all of the functions have to be static. The variables might be too, but I haven't used java in a hot minute. Main, at least, definitely does. It should have the signature of ``` public static void main(String[] args) ```
nibble · 2021-09-24 11:34
>>27635 Nope. I didn't write this but I have problems with main not being static. It has a pretty cannonical form that's supposed to be kept that way. I tried running it and it didn't work
Special Agent Bob · 2021-09-25 12:09
>Static in Java - How to use the Static Keyword https://www.youtube.com/watch?v=yn9cDLVr_wk
drop · 2021-09-26 03:37
>>27635 Given that the code is in class Test perhaps the intention is to call a particular instance's test.main() ? Actually reading the code though it seems nonsensical in terms of what it's doing and that's probably not the intention at all. Is this perhaps supposed to be example code? It seems to go out of its to show the difference between this.x and a locally defined int x and a private function defining int x yet again as a parameter.
Masami Eiri · 2021-09-26 16:15
"main" in this case is a method of the "Test" class so no, if doesn't have to be static. it has to be static when we're speaking of the "main" method of a console application. if you're trying to get into object oriented programming I'd reccomend you to read "the yellow book", you can download it for free online and it's meant for absolute beginners. it treats c# rather than java but they're basically the same language really, there are barely any differences.
Morpheus · 2021-09-28 01:13
Lainanons, which Java GUI toolkit would you use and why? Swing,JavaFX,AWT,SWT or something else?
Wirth · 2021-11-11 07:42
its pretty good if you have dumbass colleagues, refactoring is very easy and reading their bad code is easy too.
Mentat · 2021-11-12 00:56
>>21851 C# is way too bloated now. Too much syntax sugar added each year for no reason. And unfortunately, while miles better than Spring Boot, post-2013 .NET never got very popular, at least in the US
array · 2021-11-12 01:04
>>21851 >C# has deprecated Java. >>22074 >Why do C# devs always show up in Java threads like this? C# is (clone of) Java! But Java has better ecosystem of free/open-source libraries, tools and JVM languages. also DotNeet Core tools have telemetry https://wiki.archlinux.org/title/.NET_Core#Telemetry >>27711 Swing because it comes with the JDK. OpenJFX is perhaps better.
McCarthy · 2021-11-12 11:16
>>16855 A lot of boiler plate code, not a fan of JVM, garbage collector is cool I guess. Ummm not a big fan of OOP and a lot of Java is built around the paradigm. Overall not a fan of it but it's more of a subjective preference thing for me.
Joe Bloggs · 2021-11-18 04:56
>>16865 either Toast's constructor overrides Eggs' and so it prints nothing or it doesn't and then it prints 3
John Doe · 2021-11-18 06:27
>>20278 > I wish C++ was like Java with managed memory. managed C++ is a thing AFAIK, it runs on .NET and on the CLR, which is basically Microsoft's clone of the JVM.
fsociety · 2021-11-21 09:43
>>26076 >>26076 >Everything else you’ve said I’m on board. I’ve also been very guilty of over engineering applications with unnecessary design patterns … I’m currently debating spending a few days removing all my interfaces and renaming impl classes in a reasonably sized project where they’re just not needed. Dont do it. If every class has interface than its trivial to create unittests for it, you dont need to use mocks at all, instead you create fake implementation and then verify on its state instead of method signatures. It really helps with refactoring because you dont need to change tests on every method signature change
Sabo Engle · 2022-01-23 11:42
>>20905 one of my prev companies use it, Eclipse platform
Elliot Alderson · 2022-01-23 11:46
>>26080 not mistake, they did XML confs cos annotations did not exist at that times
CyberAnon · 2022-02-05 12:09
How come JavaFX isnt used more for mobile dev? I am used to swing for some desktop application but its very limiting. How long will it take me to learn it? I am mediocore at learning things on my own but from what I have seen its more of the same with swing.
Joe Bloggs · 2022-02-06 00:08
>>29972 >How come JavaFX isnt used more for mobile dev? Probably because it is not supported for mobile? If you are talking about Gluon/JavaFXPorts, then those are relatively new and small time open source projects. Most mobile development frameworks and libraries have massive businesses supporting them. On the contrary, Oracle has basically dropped supporting JavaFX. Even more so, businesses seem to prefer having a single stack to work on, that supports both web and mobile. JavaFX does not offer it.
nibble · 2022-02-25 07:13
Hi, lainons, I want to build a VPN app, what resources should I read?
Sabo Engle · 2022-03-20 21:39
Hello, lainons! Why would anyone use Java over Kotlin? In what scenario? What should I learn between Java and Kotlin if I want to get into Android development?
McCarthy · 2022-03-22 07:17
>>30468 Kotlin is a lot more niche. Even though they both target the JVM, Java receives much more attention, and more importantly more support. This is also true going forwards, so code written now in Java will be much more likely to still be understood in the future. I would strongly recommend using Java for Android development because Android is hell to develop for and you won't have much time left over to dealing with Kotlin quirks.
Motoko Kusanagi · 2022-03-22 07:38
>>30490 Thanks for the reply. I don't know either of them, so I just wanted to know which one to learn. I have always disliked Java syntax to be honest, just because how verbose it is. Therefore I am more inclined to Kotlin. >Android is hell to develop for and you won't have much time left over to dealing with Kotlin quirks Didn't google announce Kotlin as the preferred language for android development? >Java receives much more attention, and more importantly more support Why should the support matter if Kotlin can interop with Java? I would like to know where Kotlin can't replace Java.
Jens Hansen · 2022-03-22 22:48
Which IDE is best for a student of Java using Windows?
roll · 2022-03-23 08:40
>>30502 > Best Java IDE Intellij idea community edition: https://www.jetbrains.com/idea/ I also recommend you try (and perhaps dual-boot) GNU/Linux at some point: >>>/Ω/52003
Sipho Nkosi · 2022-03-24 19:10
>>30502 Either eclipse or as >>30513 said Intellij. I personally prefer Netbeans. There honestly isn't a huge difference between the three. Sure, the keybinds and ui layout are slightly different, but the code Java IDE experience is the same. It's not something to worry about.
Colmerauer · 2022-03-25 06:52
>>30491 Not him, but learn Kotlin, if you want to get into Android dev. Use IntelliJ.
Jet Black · 2022-03-25 08:15
>>30553 Thanks, lainon. Can you answer my other question? >I would like to know where Kotlin can't replace Java. I just want to know what I might miss in Kotlin other than the fact that "it's not Java".
Joe Bloggs · 2022-03-25 09:15
>>30491 >Why should the support matter if Kotlin can interop with Java? If your main concern is Java interop, you can do Android development in Clojure or Scala. I, and assume others, expect Kotlin to be yet another still-born programming language, like Dart, that has little use outside of where corporate fiat props it up. On the other hand, the actual design of Kotlin looks fine and some of the FOSS apps are written in it. YMMV.
limited · 2022-09-30 12:41
Any idea on where to find excercises that help put in use specific java features? In particular i'm looking for excercises that push me to use one of these features: -generics -custom annotations -enums Also, this thread needs some love! on what java/jvm projects had y'all been working recently, Lainons?
Terzibashjian · 2022-10-07 21:10
>>30502 I recently took a 'babies first compsci' course in java and found the hand holding of intelliJ VERY helpful and easy compared to eclipse, which I got frustrated with trying to set up the first time without any knowledge. The built in java course in intelliJ was also helpful for me. I'm sure high IQ/People not rushing without reading find eclipse very useful, but I would recoment intelliJ for fellow newbs.
Terzibashjian · 2022-10-07 21:13
>>32989 eclipse is like kicking dead whales down the beach its not you
Boole · 2022-10-07 23:32
>>32990 >kicking dead whales down the beach Why does everyone here use that phrase?
Junichi Fujiwara · 2022-10-08 21:21
>>32991 >Why does everyone here use that phrase? idk but it's pretty lame at this point. >>32990 not really. i've been using it for years and it's always been great except for some outdated plugins that don't get updates anymore
Acid Burn · 2022-10-10 10:53
>>32991 >>33001 It's an automatic word replacement like soykaf. >>32884 I've been learning JSP and Servlets with Tomcat, and it's been surprisingly pleasant. Especially with WAR contexts and it being designed around detaching external resources from your code. Ended up making a simple frontend for my IP crawler to search through indexed addresses. Hopefully soon I can begin rewriting the crawler itself in Java.
Acid Burn · 2022-10-11 10:03
>>33012 hi, I am surprised someone else is learning JSP and Servlets too. To learn working with them manually. I would like to talk to you about them and we can share our progress working on our projects with JSP/Servlets, and Spring too if you use that. If you would connect to irc.oftc.net and join #java we could discuss our projects
word · 2022-10-11 16:49
>>16919 That's your problem. You're probably going to be in the 41% anyway.
⍕ · 2022-10-13 07:27
>>33012 Any book to get started with servlet and JSP?
↑ · 2022-10-13 07:40
i'm >>32884 >>33012 >I've been learning JSP and Servlets with Tomcat, and it's been surprisingly pleasant. Ah, the good old JSP/Servlets/A.Tomcat combo! i've been using it for years for personal projects... it's pretty comfy, but problems arise when i have to debug scriplets with a lot of nested ifs/ switch statements, or start from an html file someone else wrote :s Supposedly JSF fixes these problems and it's even better than JSP because of it's modulerity/reusability, but i'm more into backend so i'm not learning a new frontend framework for now. >>33021 > I am surprised someone else is learning JSP and Servlets too it seems like there's 3 of us now :D >Spring And i'm about to start learning Spring.
Case · 2022-10-13 08:31
>>33046 I ask if you will arrive at #java oftc or rizon or another network to discuss personal projects in JSP/Servlets with Tomcat, list our books that we have, discuss Spring/Thymeleaf and others.
John Rain · 2022-10-13 10:51
>>33021 >>33046 Awesome to see others also learning JSP and Servlets! I may join #java at some point, however I have had to put my projects on hold for the time being in order to prioritize other projects of mine, that are not Java related. Once I can allocate time to them again, I would love to discuss them as well as your projects.
Junichi Fujiwara · 2022-10-14 12:12
Java is nice. The amount of boilerplate in the average java application is pretty stupid. Java is all about portability but you'll find yourself running into issues if you actually want to publish a java application running a recent version. Java has a smorgasbord of features that don't fit together in a logical way; it's mostly object-oriented, but it's also more and more going the functional route, it has a bit of everything, and it's not really good at most of it. Still, there's no language in which I could get a basic video game with graphics built from scratch on the screen faster than java. Not that that's important but I do like it for that.
hash table · 2022-10-16 06:58
>>33056 >Java has a smorgasbord of features that don't fit together in a logical way I've been thinking about this. Java for a long time didn't grow much. I wasn't using it, but I did think this was a good thing. More recently it's grown a lot. Is it going down the C++ path of cancer-like growth where you will need to choose a subset of language features?
Cereal Killer · 2022-10-16 11:50
>>33071 in my experience, it's less language features and more the standard library that is bloated.
Unspecified · 2022-10-18 09:08
>>33050 its amazing that anyone would want to learn that braindead tedious rube golberg footgun laden bullshit all pointlessly formalized (as this is a big domain full of idiots that formalization is not a match for) to send and receive a paragraph of text over the internet, aside from security auditors, yes
Apoc · 2022-10-20 09:10
>>33094 That's just the tragedy of the web. A lot of people don't even know that HTTP is just a way to format text going over a TCP socket. It's really sad how much abstraction we have over such simple ideas.
Void · 2022-10-21 12:07
>>33101 thats an insult to HTTP, right?
Yuki Nagato · 2022-10-21 16:08
>>33104 It's an insult to the web, most schools, and the average web "developer"
renames · 2022-10-24 12:49
>>33056 >Java is all about portability but you'll find yourself running into issues if you actually want to publish a java application running a recent version. no. Why? You just need mvn exe and java directory. Then you do mvn clean install then you do java -jar yourbuildapp.jar and you expose in some way on which app is running. If you can use cloud its even simpler. You write simple Dockerfile with above mentioned steps, you deploy image to some private registry, then you create some boilerplate yaml file for kubernetes which references your image. And you deploy this soykaf on any kubernetes cloud service like AKS. Make this entire process automated by some CI/CD tool (may be even free jenkins) and voila. Now you are serious software engineer
Haruyoshi · 2022-10-25 17:10
>>33101 >>33108 The web's initial simplicity was its ultimate downfall. You can scream "NOOOOO! YOU'RE ONLY SUPPOSED TO USE IT FOR TEXT!" all you want, but the reality is that that is not how most people use or have ever wanted to use the web. By not being robust enough upfront, the wen necessitated a bunch of slapdash hacks be introduced to compensate for its shortcomings, and then for more slapdash hacks to fix the shortcomings of the earlier ones.
Yamaoto Toshi · 2022-10-27 07:30
>>33151 They should have made a new protocol instead of using HTTP l In such unholy ways. The early days of Web2 we're fine. Rails, PHP, etc.
Project 2501 · 2022-10-27 13:26
>NOOOOO! YOU'RE ONLY SUPPOSED TO USE IT FOR TEXT!" all you want, but the reality is that that is not how most people use or have ever wanted to use the web I think its still being used mainly in the ways that it was invented to be used for, the problem is that there was market forces to build things quickly rather than well. No surprise that everything is just building crap on top of crap now.
x<->y · 2022-11-01 11:48
Anyone know the color theme used by default here on lainchan? Picrel. Also, code color theme thread, what's your favorite?
Lunch · 2022-11-01 13:46
>>33241 monokai asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf
Rick Deckard · 2022-11-02 06:43
>>33241 Gruvbox Dark theme, it looks pretty good. I personally use the Tango-Dark for my emacs.
Leto Atreides I · 2022-11-10 10:40
i'm trying to figure out a way to find out, given a certain Class that has a method, from where that method is inherited from. I'm thinking maybe using reflection may help, but idk, i can't figure out how to do this.
Hong, Guil Dong · 2022-11-10 10:51
>>33300 Inheritance is the bane of all evils. Try to favor encapsulation to avoid running into problems like the one you're having.
Splicer · 2022-11-10 14:37
>>33300 Method::getDeclaringClass is what you're looking for. But as >>33301 said, you should be looking for a more encapsulating approach. class Foo { public void pony(){} } class Bar extends Foo {} Bar.class.getMethod("pony").getDeclaringClass() == Foo.class https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Method.html#getDeclaringClass--
Donna Hawthorne · 2022-11-10 14:50
>>33301 I meant root of all evils. Sorry bad english :>
Eldon Tyrell · 2022-11-11 07:11
>>16855 i think the problem with it has to do with the fact that if it weren't in oracle's hands, it would've been just fine, just another language to add to the trough. Except for the part where you have to put everything into classes. In my opinion, classes are for objects that hang around in the main thread/job/whatever, not to 'be' the main thread/job/whatever.
Roy Batty · 2022-11-25 12:30
>>33305 Thanks you!
word · 2022-11-27 09:22
>>33312 >In my opinion, classes are for objects that hang around in the main thread/job/whatever, not to 'be' the main thread/job/whatever. Can I ask what your reasoning is for this?
Arisu Mizuki · 2022-11-27 13:58
>>33495 Because there's only one (usually) and because the main job of handling toplevel logic and objects is a quite vague and changing concept that can easily become a chore when put into a class for no reason.
Crazy Jake · 2022-11-27 14:08
>>33497 In general, I follow the rule of name. If you have to name your class 'ThreadProcessor' or whatever, something that clearly describes a process and not an entity, there may be a design problem. It can happen when the language lacks the proper tools like namespaces or closures.
Frank Garza · 2022-11-27 16:15
>>33497 >the main job of handling toplevel logic and objects is a quite vague and changing concept that can easily become a chore when put into a class for no reason How so? Is there a meaningful, practical difference between freestanding functions, and, say, static functions inside of a Main class? Say you have this: class Main { public static void main(String[] args) { // main stuff here } public static void func1() { // doing stuff here } // more methods here } and then if you were to mentally ignore the top and bottom lines, you get this: public static void main(String[] args) { // main stuff here } public static void func1() { // doing stuff here } // more "functions" here In other words, it seems to me that having the main thread inside of a class is fairly transparent. However it could be that I lack the experience to see where the chore comes in. In that case, can you elaborate on that?
setq · 2022-11-27 23:25
>>33499 In your example, it's annoying boilerplate. You never needed a class but had to make one because "Objects™!!1!".
Lain Iwakura · 2022-11-28 14:27
>>33502 That doesn't really describe any kind of chore like you mentioned. I suppose it then boils down to whether one is annoyed by this as a matter of principle rather than practice.
t · 2022-12-06 10:00
So, why isn't any Java user posting in the AoC thread? Is this just Entreprise^tm larping?
Hagbard Celine · 2022-12-06 10:40
>>33646 Why are no C++ users posting there? No SML, Ocaml, ruby, etc?
Drifter · 2022-12-06 14:49
>>33647 Why do you think this is a justification? Indeed, why do people who wage slave languages fail to see that simple examples are the best way to do so.
Anonymous · 2022-12-07 02:35
>>33650 Why do you think everyone that know programming are supposed to enjoy AOC? Do you think every mathematician enjoy math olympiad?
Roy Batty · 2022-12-07 18:24
>>33646 Java is ill suited to do small problems like that. The runtime is more than capable but the langauge is designed to be so verbose that is cumberstone. That's ok for Java's intended use case but not for competitive programming. Something like Babashka or Groovy could do the trick.
Cowboy · 2024-04-24 08:44
Why is it foo bar = new foo(); rather than new foo bar = foo(); I feel like the latter would make it way easier to make anonymous objects.
monoe · 2024-04-24 23:05
>>38935 fairly sure its to be consistent with c++'s new operator syntax
藤原純一 · 2024-04-25 17:57
You know what? I don't have a problem with Java, in fact I sort of like it. I fuarrrking hate Spring and how much it is like kicking dead whales down the beach the fun out of programming though. I was OK with understanding Spring, Spring boot, even learning Spring Security. I had to get a couple of books to get the hang of it because the Spring Docs are terribly soykafty at explaining to you the general architecture, despite Spring-cultists in their cargo cult telling you that the "Docs are great". You try to deviate slightly from what Spring allows you to do and you find yourself having to work through the Spring docs, Indians on youtube, a bunch of blogs, source code, and the only thing everywhere, is just a bunch of DSL-ish Java configuration that magically gets things done, and guess what? That's now deprecated, have to use spring-boot-clusterfuck-starter. Java is fine, it truly is, it's verbose yeah, but the biggest problem seems to be Java developers . They're obsessed with not writing code, re utilization to unhealthy levels, the result is Spring, Lombok, the unnecessary abstractions.
Special Agent Bob · 2024-04-26 06:55
>>16865 It prints nothing. You forgot to call super() in your constructor.
Y.T · 2024-06-02 19:21
Less soykaf than it used to be.
Unidentified · 2024-06-24 14:08
>>16855 I hate Java with a passion, mostly due to university lecturers being hilariously incompetent. Thankfully, I was able to get away for a student exchange and get to know C# instead. Everything that Java does it does better. The only reason my Java professor dislikes C# is because it's >muh Microsoft ,and not an actual reason to dislike the language(speaking of, Oracle is infested by glowies, anyway, and since the Sun takeover, the language isn't really free as in "freedom"). Having felt in love with C#,I am willing to give it another chance. I heard that "Think Java" is a good Java book for beginners, can someone recommend me something good to read? I'm feeling like getting good and overcoming my weaknesses. >>16865 At first, it looked like a clusterfuck to me. Java's obtuse syntax aside, what happens is pretty logical, as the base class calls its Eggs method, and this method happens to be abstract prototype. Hence, it does nothing. jshell> abstract class Eggs { ...> abstract void m(); ...> ...> Eggs() { ...> m(); ...> } ...> } ...> ...> class Toast extends Eggs { ...> private Integer x = 2; ...> ...> Toast() { ...> x = 3; ...> } ...> ...> public void m() { ...> System.out.println("x = " + x); ...> } ...> ...> public static void main(String[] args) { ...> new Toast(); ...> } ...> } | created class Eggs | created class Toast I hate how my lab lecturer laughed at me for using jshell, even though having an Interpreter shell ready for your language of choice is a blessing. Then again, I'm a P*thonite subhuman, I'm biased.
Yuki Nagato · 2024-07-20 07:30
Does anyone have any recommendations for how to learn Spring? It's not difficult for me to work with Java at all, even though it's very verbose at times, but it's simple. Spring, however, I feel that there are too many things that I don't know what they do and I can't find good documentation either. Sometimes I think about moving to C or Rust (which I know as much as Java) but in my country there is a lot of work with Java :/
Nguoi La · 2024-07-20 13:53
>>39633 Spring Start Here published by Manning
Cat Mother · 2024-07-20 15:53
>>39408 >I hate how my lab lecturer laughed at me for using jshell, even though having an Interpreter shell ready for your language of choice is a blessing. it's good for exploring an api or testing small things. as long as you're not treating it as a code editor. i wish my coworkers would use it (and the docs) instead of going through the full build process for our project 30 times when they're trying to figure out how to use some built-in java api.
Nanashi No Gombe · 2024-07-21 01:24
>>39636 Even if you don't have a prompt available, what you should do in such a situation is: 1. Write a small program for the API you want to use. 2. When it works as you want it to, put it in the "big program". 3. Put the small snippet in your notebook to find it at a later date. Learning to do things twice is another waste of time.
Lain Iwakura · 2024-07-30 16:58
>>39408 Honest question, why do you like C# over Java? I've worked with both professionally and and personally and I personally detest C#. It doesn't really do much of anything better than modern Java in my experience and it does what it does in an infinitely worse syntax. The lowest common demominator for C# code is much, much lower than Java in my honest opinion. I stand by my use of Scala as a quintessential "better Java", but I still go back to Java every now and again as it is just an insanely simple language, with a simple syntax to complement it (Still excited for reified generics though).
Cereal Killer · 2024-11-19 06:01
>>16879 I used it at work recently and I like it too. There are some things with its design that I don't entirely agree with (eg. if you don't add a return, methods still return a Unit type... why not void? :/). But writing it is a breeze compared to java. And having explicit nullable types and mutability is great, it makes your code show the intent you had while writing it. I don't know what other lainons are complaining about
Koichiro · 2024-11-19 06:23
>>39636 i dont remember the name for this feature but java allows to modify code while the code is already running. Its what i loved most about coding java compared to c++. Saw it originally by accident watching notch code and got really mad university never even mentioned it.
Judge Fang · 2024-11-20 06:51
>>40453 I think it's called "hot swapping". Some other languages that support it are Lisps, Smalltalk, Erlang and Elixir.