Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!

henry leu

Ranch Hand
+ Follow
since Apr 23, 2016
Cows and Likes
Cows
Total received
2
In last 30 days
0
Total given
0
Likes
Total received
7
Received in last 30 days
0
Total given
11
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by henry leu

Paul Clapham wrote:

henry leu wrote:I'm running Windows command prompt and IntelliJ IDE all on the same Windows system. Why do they show different result?



Why not? You're probably the first person to care about that for the last 25 years. I'm not entirely joking... when Windows 95 was released, command-line programs became obsolete.



Sorry, I mean I'm using Windows PowerShell, now Windows command prompt window.

I just realized one thing.

Different results appear on IntelliJ's RUN window and IntelliJ's TERMINAL window.

See screenshot.


2 weeks ago
Hi,

Thanks guys for all the suggestions.

However, I'm just testing it out the way the carriage return \r really works under Windows. I'm learning it.

I'm running Windows command prompt and IntelliJ IDE all on the same Windows system. Why do they show different result?

See the screenshot.

Thanks!
2 weeks ago
Hi,

My carriage return displays different output on IntelliJ IDE and my Windows command prompt window.

Here is the code.
System.out.println("Happy birthday to \r you.");

My IntelliJ IDE prints:
you.

The cursor goes back to the beginning of the same line and erases all the content. I don't think this is correct.



On my Windows command prompt, it prints correctly.
you. birthday to

Cursor moves to the beginning of the same line and overrides from the beginning of the line.

Please advise.

Thanks!
2 weeks ago

Jj Roberts wrote:It may be worth mentioning that javac does search the classpath for other classes which your class depends on:

javac docs wrote:The compiler needs type information for every class or interface used, extended, or implemented in the source file. This includes classes and interfaces not explicitly mentioned in the source file, but that provide information through inheritance.
...
When the compiler needs type information, it searches for a source file or class file that defines the type. The compiler searches for class files first in the bootstrap and extension classes, then in the user class path (which by default is the current directory). The user class path is defined by setting the CLASSPATH environment variable or by using the -classpath option


Say I have two classes
main.java:Greeter.java:
From the '.' directory I can compile them like this (it might be better to use -sourcepath instead of -cp for clarity):
To run I have to have all of the classes on the classpath:



Hi JJ Roberts,

What does the colon ":" between java -cp dir2:dir1 do?
1 month ago

Jj Roberts wrote:It doesn't seem to be explicitly stated in the docs but javac expects the file path for the source files you are compiling. As Knute noticed, putting the source file's directory on the classpath doesn't work. Campbell's second and third examples won't work because of that. The java command expects <package>.<mainclass> as the argument, though, so we have to use -cp to run it from another directory.
Instead of
you would have to do

and if you want to use set CLASSPATH you would still have to pass javac the path of your .java file



JJ Roberts   THANKS!!!
1 month ago
I still cannot run it in command prompt.
My Netbeans 11 uses these properties to successfully compile and run my Java program.
process-classes org.codehaus.mojo:exec-maven-plugin:1.6.0:exec

exec.args=-classpath %classpath ${packageClassName}
exec.executable=java


However, I just don't know how to type those in the command prompt using Maven.
I want to run it using mvn exec:exec,not exec:java.

What exactly is %classpath and ${packageClassName} in Netbeans?
1 month ago
I have my mother.java and mother.class in directory
C:\Name\Henry

How do I compile and run when my cursor is at this directory
C:\Name

Thanks!
1 month ago
Hi,

I'm new to Maven and Netbeans 11.

I want to run a Java class using mvn exec:exec in command prompt.

Questions 1:
In Netbeans 11, my POM has no user-defined plugins. Just the default Netbeans POM.
I'm able to hit "Run" in Netbeans and it compiles and runs my program successfully.

Now I want to run the same Java class in command prompt. How do I do that?
I see that Netbeans has this set up in its Properties->Actions-Set properties like this: See attached file.

process-classes org.codehaus.mojo:exec-maven-plugin:1.6.0:exec
exec.args=-classpath %classpath ${packageClassName}
exec.executable=java

I don't know how to put that into a complete command prompt.

Thanks!
1 month ago
Hi,

I realize that Java 13 just released recently. How did you manage to write this book based on Java version 13?

Thanks,

Henry
3 months ago

Carey Brown wrote:"EventHandler" is a standard class, not an interface, nor abstract.



To Carey Brown, EventHandler is indeed an interface. See this link.

EventHandler Java 9
1 year ago
Hi,

From my knowledge, abstract class and interface class cannot use "new" key word to instantiate an object, right?

The following is an example of using anonymous class for the EventHandler.

Why does setOnAction() method take on a new EventHandler interface object? I know setOnAction() takes EventHandler object.



Thanks,

Henry
1 year ago

System.out.println(super.toString())



Actually, the above code that you mentioned compiles.
1 year ago
Hi Albert,

Thanks for the reply.

However, I have "this" in super class, not in sub class. And also, I'm not overriding print() in sub class.

So my understanding of polymorphic is when I use sub class variable to call print(), program will see that in my sub class, I don't have any print() or overridden print(). So program will go see the super class's print(). Now it ACTUALLY calls the print() in super class. But when it calls the "this", it will print the sub class information, not the super class object information?
1 year ago

henry leu wrote:When sub class inherits from super class, it automatically inherits super class's method.
I try to test it out the "this" functionality. I try to print out the super class object information from the sub class. Why doesn't "this" refer to SuperClass object, but it refers to SubClass object?








Output:

SubClass@1d251891



and the output is also the same for the Super Class to be like this...



1 year ago