r/javaTIL • u/scientecheasy • Dec 27 '18
r/javaTIL • u/dohaqatar7 • Feb 22 '15
System.out.println(new char[] {'R,'e','d','d','i','t});
To day I learned you can print a char[] in a user friendly format without using Arrays.toString().
Executing my little code snippet in the title will result in the output Reddit instead of the usual hex memory location ([I@15db9742 or something). The snippet is functionally the same as the code in this subreddits banner.
The truly curious part of this JTIL is that this only works on char[], not int[] or long[] or anything. In addition, this does not work if you call toString() on the array; however, it does work if you call String.valueOf().
Edit: I found this on Java 1.8.0_20 and would appreciate if people using older versions would test this.
r/javaTIL • u/scientecheasy • Nov 02 '18
Programs on ArrayList in Java for Practice
r/javaTIL • u/scientecheasy • Jan 19 '19
Inheritance in Java | Uses & Advantages
r/javaTIL • u/[deleted] • Mar 25 '15
TIL Strings have a toString() method that returns themselves
So while I was looking around on the docs for the String (what else am I supposed to do in class?), I noticed that there's a toString() method. Wondering what this does, I messed around with it a bit. I have determined that it does basically nothing special except what it says on the docs: return the string itself. Anyone know a use for this?
TLDR: There's a toString() method for strings that returns the string in question. Any use for this?
EDIT: I was trying to ask if the method had any use for strings in particular. I'm aware (very, in fact) of the main uses for it (namely other things like numbers and error messages and other things of the sort).
r/javaTIL • u/scientecheasy • Sep 27 '18
Collection Hierarchy in Java | Collections class
r/javaTIL • u/scientecheasy • Oct 20 '18
Iterators in Java | Types & Example Programs
r/javaTIL • u/javinpaul • Mar 23 '15
TIL:You cannot delete directory in Java without deleting all files inside it
r/javaTIL • u/Shilpa_Opencodez • Nov 20 '19
Simple Step by Step Guide to be a Full Stack Developer
r/javaTIL • u/scientecheasy • Aug 30 '18
Return type in Java with Example | Basic & Project Level
r/javaTIL • u/scientecheasy • Dec 07 '18
Java LinkedList Example Programs
r/javaTIL • u/Ameridrone • Aug 29 '13
You should know that "args[]" means that you can send arguments to the program via the command line and reference the position like "args[0]". Examples inside.
I have always been told that the whole:
public static void main(String args[])line was literally always required, however until recently I didn't know the "args" part, and to be honest...it seems like many don't.
So here is the deal: args are what are sent the program, and you can send them command line.
You will need to of course compile your .java file. Personally, I enjoy doing it the old fashioned way (makes me feel smarter than I am), and I use the command line.
If you are unfamiliar with how this is done, all you do is navigate to where ever the .java file is, and type:
javac filename.javaANYWHO, here is an example program which uses args:
public class addition
{
public static void main(String args[])
{
int num1 = Integer.parseInt(args[0]);
int num2 = Integer.parseInt(args[1]);
System.out.println(num1 + num2);
}
}In my example, once compiled, you can change directory to where the .class file is, an execute the program.
The example I have provided takes exactly two arguments.
java addition 1 2This will return the number 3!
r/javaTIL • u/Scrofulout • Oct 28 '19
Difference between throw and throws in java
javahungry.blogspot.comr/javaTIL • u/scientecheasy • Sep 18 '18
Static Block in Java | Example Program & Advantage
r/javaTIL • u/scientecheasy • Jan 16 '19
Final Keyword in Java | Final Variable Method & Class
r/javaTIL • u/lurker_level_53 • May 18 '14
TIL that Java does support Lambda functions
docs.oracle.comr/javaTIL • u/scientecheasy • Sep 15 '18
Static Method in Java with Example & Programs
r/javaTIL • u/scientecheasy • Feb 15 '19
Type Conversion & Casting in Java with Example
r/javaTIL • u/javinpaul • Jun 15 '15
JTIL : You can compare Enum constants using == and equals both, btw == is better.
r/javaTIL • u/stevemann2705 • Dec 10 '16
TIL The args array in the main method signature is not null is no arguments are given
In public static void main(String[] args){ ... } The args array is never null(under normal execution). If the program is run without any arguments, args points to a String array of length 0. It was quite amazing for me to when I came to know about this, but it now seems more logical.
The args array can only be null if the main method is manually called and a null reference is passed to it.
r/javaTIL • u/cdman • Dec 01 '15
TIL JavaAdvent will publish one article/day for the next 24 days about JVM related topics
r/javaTIL • u/scientecheasy • Jan 22 '19
Types of Inheritance in Java | Single,Multilevel,Multiple,Hybrid
r/javaTIL • u/MillionStrength • Mar 17 '20
Type safe hashmap in java
I have created type safe hashmap in Java. The hashmap can store any type of object and retrieve the object without explicit cast:
http://millionstrengthknowledge.com/resource/java/programming/typeSafeMap.html