[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
It is a bit of a disappointment if you forget to give it any command‑line arguments And SingleFile is a really misleading class name, I know.critchie@localhost directoryXXX]$ java SingleFileDemo.java Campbell Jeanne Liutauras Bear
SingleFile object with field = Campbell
SingleFile object with field = Jeanne
SingleFile object with field = Liutauras
SingleFile object with field = Bear
[critchie@localhost directoryXXX]$ javac -version
javac 13
[critchie@localhost directoryXXX]$ java -version
openjdk version "13" 2019-09-17
OpenJDK Runtime Environment (build 13+33)
OpenJDK 64-Bit Server VM (build 13+33, mixed mode, sharing)
/somePath/otherDirectory/java/jdk-11.0.2/bin/java SingleFileDemo.java Campbell Jeanne Liutauras Bear
SingleFile object with field = Campbell
SingleFile object with field = Jeanne
SingleFile object with field = Liutauras
SingleFile object with field = Bear
Dinkar Joshi wrote: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?
I got the same error when I removed the path to JDK11 and used my default (Java13).pluma SingleFileDemo.java SingleFile.java &
...
/somePath/otherDirectory/jdk-11.0.2/bin/java SingleFileDemo.java Campbell Jeanne Liutauras Bear
SingleFileDemo.java:7: error: cannot find symbol
new SingleFile(s).run();
^
symbol: class SingleFile
location: class SingleFileDemo
1 error
error: compilation failed
In teh fourth paragraph,
The java command probably both compiles the XYZ.java file and executes the compiled bytecode. But it doesn't store an XYZ.class file anywhere.Dinkar Joshi wrote:. . . We can run our SingleFileZoo example without actually having to compile it. . . .
Yes, that sounds correct I said so on Friday.This feature is called launching single-file source-code programs. . . .if your program has two .java files, you still need to use javac. . . .
Is that what you are saying yourself, or a quote from the book? Whichever, it isn't correct.Dinkar Joshi wrote:. . . you cannot use this new feature for a single-file program with two classes in it. . . .
Mikalai Zaikin wrote:It might be a proper place to report errata on errata 8)
The link
https://www.selikoff.net/ocp11-1/
says:
In teh fourth paragraph,
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Campbell Ritchie wrote:
Is that what you are saying yourself, or a quote from the book? Whichever, it isn't correct.Dinkar Joshi wrote:. . . you cannot use this new feature for a single-file program with two classes in it. . . .
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
JEP330 wrote:In source-file mode, the effect is as if the source file is compiled into memory, and the first class found in the source file is executed.
99 little bugs in the code, 99 little bugs in the code.
Take one down, patch it around, 117 little bugs in the code.
Frank Mi wrote:For example, the following code works.
Carey Brown wrote: Note that this is only true if this code is in a file named "Class1.java". If the following code is in a file named "Class1.java" it will not work. So, not only does the first class need to contain main() the class name must also match the file name.
99 little bugs in the code, 99 little bugs in the code.
Take one down, patch it around, 117 little bugs in the code.
Frank Mi wrote:
Carey Brown wrote: Note that this is only true if this code is in a file named "Class1.java". If the following code is in a file named "Class1.java" it will not work. So, not only does the first class need to contain main() the class name must also match the file name.
That is not true. The name doesn't matter.
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Jeanne Boyarsky wrote:Is it ok if I include your name in the thank yous?
99 little bugs in the code, 99 little bugs in the code.
Take one down, patch it around, 117 little bugs in the code.
Campbell Ritchie wrote:DJ: Welcome to the Ranch
I don't know whether things are different on JDK13 but I had no difficulty getting this file to run:-
critchie@localhost directoryXXX]$ java SingleFileDemo.java Campbell Jeanne Liutauras Bear
SingleFile object with field = Campbell
SingleFile object with field = Jeanne
SingleFile object with field = Liutauras
SingleFile object with field = Bear
"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
It is programmed to look for the first class in the file, I think, regardless of its access. If you use the old way of compiling code, with javac and java, there is no requirement for the class with the main() method to be public, either.R K Singh wrote:. . . how can JVM run without class being public ?? . . .
It is programmed to look for the first class in the file, I think, regardless of its access. If you use the old way of compiling code, with javac and java, there is no requirement for the class with the main() method to be public, either.
"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
Campbell Ritchie wrote:What do you think, MS?
Monica Shiralkar wrote:
Campbell Ritchie wrote:What do you think, MS?
I have seen that at times and have wondered why were these kept in a single file instead of multiple. To me having 1 file per class looks more readable.
"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
I think I'll just lie down here for a second. And ponder this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|