This week's book giveaways are in the Angular and TypeScript and Web Services forums.
We're giving away four copies each of Programming with Types and The Design of Web APIs and have the authors on-line!
See this thread and this one for details.
Win a copy of Programming with Types this week in the Angular and TypeScript forum
or The Design of Web APIs in the Web Services forum!

Dinkar Joshi

+ Follow
since Jan 02, 2020
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Dinkar Joshi

I have tried again, please find below:

C:\Users\DJ\OCP>jar -cvf myNewFile.jar C:\Users\DJ\OCP
added manifest
adding: Users/DJ/OCP/(in = 0) (out= 0)(stored 0%)
adding: Users/DJ/OCP/OCP1/(in = 0) (out= 0)(stored 0%)
adding: Users/DJ/OCP/OCP1/pack1/(in = 0) (out= 0)(stored 0%)
adding: Users/DJ/OCP/OCP1/pack1/Classa.class(in = 192) (out= 161)(deflated 16%)
adding: Users/DJ/OCP/pack1/(in = 0) (out= 0)(stored 0%)
adding: Users/DJ/OCP/pack1/ = 46) (out= 44)(deflated 4%)
adding: Users/DJ/OCP/pack2/(in = 0) (out= 0)(stored 0%)
adding: Users/DJ/OCP/pack2/ = 165) (out= 130)(deflated 21%)
adding: Users/DJ/OCP/thi.jar(in = 140885) (out= 140834)(deflated 0%)
adding: Users/DJ/OCP/ = 410) (out= 216)(deflated 47%)

There seems to be a lot of confusion, let me elaborate: The below excerpt is from the OCP guide, which I am using to study for the certification. I have marked the line bold which was the source of confusion. This has been identified as an errata already.

Running a Program in One Line
Starting in Java 11, you can run a program without compiling it first—
well, without typing the javac command that is. Let’s create a new class:
public class SingleFileZoo {
public static void main(String[] args) {
System.out.println("Single file: " + args[0]);
We can run our SingleFileZoo example without actually having to
compile it.
java Cleveland
Notice how this command passes the name of the Java file. When we
compiled earlier, we wrote java Zoo. When running it as a one-liner, we
write java This is a key difference. After you first
compiled with javac, you then passed the java command the name of the
class. When running it directly, you pass the java command the name of
the file. This feature is called launching single-file source-code programs.
The name cleverly tells you that it can be used only if your program is one
file. This means if your program has two .java files, you still need to use
javac. By contrast, you cannot use this new feature for a single-file
program with two classes in it.
In fact, you can’t refer to any .class files
that didn’t come with the JDK.

Hope this helps: Much Ado about nothing.
2 weeks ago
I believe there is a syntax mistake in the following while specifying the path for the jar file creation, there should be no hyphen before the drive path, just simple space.
I have tried on the command prompt on windows 10. Maybe I am wrong please confirm, I just learning, so I may be wrong.

This is chapter 1.

Creating a JAR File

jar -cvf myNewFile.jar .
jar --create --verbose --file myNewFile.jar .
Alternatively, you can specify a directory instead of using the current
jar -cvf myNewFile.jar -C dir . <<--- the extra hyphen throws error.   ": no such file or directory"

jar -cvf myNewFile.jar C dir   <<-- removed hypen, creates jar successfully.

Thank you for your efforts, however, It seems you mistook what I meant. I am on the same page with you, the code compiles just fine.  The initial discussion was, because in the guide book for Oracle certification, it was stated otherwise. i.e the code should NOT run, This has already been addressed and now been added to the errata as mentioned above.. Follow the link:
Thanks again.
2 weeks ago
What a pleasant message, yes it was your book. Thanks, I have been scracthing my head , why I was able to add more than 2 classes!!!
2 weeks ago
I am using Java 11, and just read in a book, that Single File Source code you cannot use this new feature for a single-file. program with two classes in it
Single File Source Code: I am able to have more than 1 class in the same file, yet the program runs.
Can  anyone explain? Help?
2 weeks ago