r/javaTIL • • Dec 27 '18

Java Set Interface | Example & Programs

Thumbnail
scientecheasy.com
0 Upvotes

r/javaTIL • • Feb 22 '15

System.out.println(new char[] {'R,'e','d','d','i','t});

0 Upvotes

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 • • Nov 02 '18

Programs on ArrayList in Java for Practice

Thumbnail
scientecheasy.com
0 Upvotes

r/javaTIL • • Jan 19 '19

Inheritance in Java | Uses & Advantages

Thumbnail
scientecheasy.com
0 Upvotes

r/javaTIL • • Mar 25 '15

TIL Strings have a toString() method that returns themselves

2 Upvotes

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 • • Sep 27 '18

Collection Hierarchy in Java | Collections class

Thumbnail
scientecheasy.com
0 Upvotes

r/javaTIL • • Oct 20 '18

Iterators in Java | Types & Example Programs

Thumbnail
scientecheasy.com
0 Upvotes

r/javaTIL • • Mar 23 '15

TIL:You cannot delete directory in Java without deleting all files inside it

Thumbnail
javarevisited.blogspot.com
1 Upvotes

r/javaTIL • • Nov 20 '19

Simple Step by Step Guide to be a Full Stack Developer

Thumbnail
opencodez.com
4 Upvotes

r/javaTIL • • Aug 30 '18

Return type in Java with Example | Basic & Project Level

Thumbnail
scientecheasy.com
0 Upvotes

r/javaTIL • • May 25 '19

Java Collection - Deque

Thumbnail codeforjava.com
0 Upvotes

r/javaTIL • • Dec 07 '18

Java LinkedList Example Programs

Thumbnail
scientecheasy.com
0 Upvotes

r/javaTIL • • 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.

2 Upvotes

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.java

ANYWHO, 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 2

This will return the number 3!


r/javaTIL • • Oct 28 '19

Difference between throw and throws in java

Thumbnail javahungry.blogspot.com
3 Upvotes

r/javaTIL • • Sep 18 '18

Static Block in Java | Example Program & Advantage

Thumbnail
scientecheasy.com
1 Upvotes

r/javaTIL • • Jan 16 '19

Final Keyword in Java | Final Variable Method & Class

Thumbnail
scientecheasy.com
1 Upvotes

r/javaTIL • • May 18 '14

TIL that Java does support Lambda functions

Thumbnail docs.oracle.com
1 Upvotes

r/javaTIL • • Sep 15 '18

Static Method in Java with Example & Programs

Thumbnail
scientecheasy.com
1 Upvotes

r/javaTIL • • Feb 15 '19

Type Conversion & Casting in Java with Example

Thumbnail
scientecheasy.com
0 Upvotes

r/javaTIL • • Jun 15 '15

JTIL : You can compare Enum constants using == and equals both, btw == is better.

Thumbnail
javarevisited.blogspot.sg
0 Upvotes

r/javaTIL • • Dec 10 '16

TIL The args array in the main method signature is not null is no arguments are given

3 Upvotes

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 • • Dec 01 '15

TIL JavaAdvent will publish one article/day for the next 24 days about JVM related topics

Thumbnail
javaadvent.com
0 Upvotes

r/javaTIL • • Apr 25 '19

Interface Default Methods in Java

Thumbnail codeforjava.com
2 Upvotes

r/javaTIL • • Jan 22 '19

Types of Inheritance in Java | Single,Multilevel,Multiple,Hybrid

Thumbnail
scientecheasy.com
2 Upvotes

r/javaTIL • • Mar 17 '20

Type safe hashmap in java

4 Upvotes

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