Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!

John Pacuta

Ranch Hand
+ Follow
since Nov 21, 2015
John likes ...
Android Scala Java
Being part of the Java Community gives me a good feeling. I always say to myself in those challenging moments: code is the answer.
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by John Pacuta

Thank you for your replies.

The following code does not compile:



The compiler gives the following clue:

C:\Users\johnp\code>javac HandlingCash.java
HandlingCash.java:8: error: <identifier> expected
bd = bd.multiply(new BigDecimal(x));
 ^
1 error


Why do I need an identifier on line 8? I thought I identified the variable on line 6!
Any help is much appreciated.
2 years ago
C:\Users\johnp>echo %CLASSPATH%
C:\Users\johnp\code

it looks like a classpath was set during my troubleshooting
2 years ago
C:\Users\johnp\code>java -cp C:\Users\johnp\ code.Begin
Java packages confuse me.


That was it! The CLASSPATH has to be in the root folder and the class must be referred to by its full name including the package. Thank you all for your help!
2 years ago
Yes, Begin.class is in the code folder. Maybe I am not understanding how to create a package. I'm not using an IDE, just Notepad and the command line. How do you create a package? Because I declared but I don't think I ever created one.
2 years ago
I tried the following commands:

1. In the folder above \code with package name then class name.
C:\Users\johnp>java code.Begin
Error: Could not find or load main class code.Begin
Caused by: java.lang.ClassNotFoundException: code.Begin

2. in the \code folder with package name and class name.
C:\Users\johnp\code>java code.Begin
Error: Could not find or load main class code.Begin
Caused by: java.lang.ClassNotFoundException: code.Begin

3. Similar conditions but with classpath.

C:\Users\johnp>java -cp C:\Users\johnp\code code.Begin
Error: Could not find or load main class code.Begin
Caused by: java.lang.ClassNotFoundException: code.Begin

C:\Users\johnp\code>java -cp C:\Users\johnp\code code.Begin
Error: Could not find or load main class code.Begin
Caused by: java.lang.ClassNotFoundException: code.Begin
2 years ago
I am compiling the following code:



The code compiles and creates Begin.class in the folder. Here is the structure on the file system:

C:\Users\johnp\code.

I tried running Begin.class with the following command:

>java -cp C:\Users\johnp\code Begin


My question is: Why does the code compile but not execute?

Here is the error I get:

Error: Could not find or load main class Begin
Caused by: java.lang.NoClassDefFoundError: code/Begin (wrong name: Begin)


As a note, the code compiles and executes without the package statement.

Thank you for all your help, I am truly grateful.
2 years ago
Hi All,

I'm facing 2 options.

1. Buy this course: http://www.informit.com/store/oca-java-se-8-programmer-i-1z0-808-complete-video-course-9780134498287?WT.mc_id=Social_YT

2. Sign up for the JavaRanch Cattle Drive

Which one do you think will be better prep for the 1Z0-808?

Thanks
Ya I was looking for something I can print but also something that is very inline with the exam objectives...I don't mind purchasing them if that is necessary I just want something that I can physically hold so I can use Leitner System
Hi!

I'm looking for an online repository of flash cards for the Oracle Certified Associate exam, 1Z0-808. Do you know any good sources? I looked on Google and didn't find any that seemed very good. I was just wondering if someone out there on the ranch knows of some great flash cards.

Thanks so much!
Prateek,

So how exactly would one successfully convert an array of Integers to an array of primitive ints?

4 years ago
Prateek,

I stepped through your code and renamed some variables. It seems like the underlying question is: How do I cast an Integer into the primitive type int?



For more information about unboxing look here: The Collection Framework
4 years ago
Thanks to Ganesh for explaining abnormal method completion. Great answers all around (especially the nitpicking, the compiler knows no mercy).
Hi,

The following code is taken from Sybex page 250 (some methods are omitted). Specifically, why would Reptile.hasLegs() compile? It doesn't have a return type! Am I missing something?



Hi Ekte!

You have this public method "getSKos(Vehicle[] pin)" that accepts a Vehicle array called "pin". For every element of pin, the another method "getKSOxis()" is called and an integer is returned and added to "ks". About the "+=" that is just a way to add a value to itself, in other words 1 += 2 is the same as 1 = 1 + 2. I hope that helps!
4 years ago
Ekte,

I was examining your code and I think only a "while" loop should be used because the user's first entry could be "escape". If you use a do{}while(x) the thing inside will be executed at least once without checking for escape. I see that the user makes a choice, either 1,2 or 3 and then actions occur until they type "escape". I would check for "escape" first in case they want to exit without executing code, like the case where they choose the wrong menu item.



I looked for "UserInput" in the Java SE 8 API but I did not see it listed between UserException and UserPrincipal. Is this another class you created? Maybe consider utilizing the built-in Scanner class to collect user keystrokes.


Sources

1. Java SE 8 API, https://docs.oracle.com/javase/8/docs/api/
4 years ago