Avatar of gudii9
gudii9
Flag for United States of America asked on

java package issue

Hi,
I am running below example
http://www.avajava.com/tutorials/lessons/what-is-the-transient-keyword-used-for.html
I created the TransientDemo.java file under below folder


C:\Users\Desktop\gpfolder\gpmy\SampleCode\Online\avajava\stuff  


The TransientDemo.java file has package called cakes.

package cakes;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class TransientDemo {

  public static void main(String[] args) {




I opened command prompt in my windows laptop went to below folder
C:\Users\Desktop\gpfolder\gpmy\SampleCode\Online\avajava\stuff

so now I gave compile below command
javac TransientDemo.java  (i see class file generated at C:\Users\Desktop\gpfolder\gpmy\SampleCode\Online\avajava\stuff)
and run command at same location (C:\Users\Desktop\gpfolder\gpmy\SampleCode\Online\avajava\stuff)
java TransientDemo
I got error message saying the class not found.



when I  comment the package statement everything works perfect.



//package cakes;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class TransientDemo {

  public static void main(String[] args) {



so now again I gave compile below command
javac TransientDemo.java  (i see class file generated at C:\Users\Desktop\gpfolder\gpmy\SampleCode\Online\avajava\stuff)
and run command at same location (C:\Users\Desktop\gpfolder\gpmy\SampleCode\Online\avajava\stuff)
java TransientDemo
I got output without error.

Can you please advise what is the issue with package statement.


what is meaning of  file extension of mydemo.ser.
what are practical uses of the transient

 please advise
Any links resources ideas highly appreciated. Thanks in advance
Java EEJavaJSP

Avatar of undefined
Last Comment
gudii9

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
girionis

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
gudii9

ASKER
>>java cakes.TransientDemo
you mean below statement instead of above to compile it
javac cakes.TransientDemo.java

Or you mean the run statement itself when you say second statement as below.


>>The second statement tells java to find the class called TransientDemo in the cakes folder.

Please advise
gudii9

ASKER
If cakes folder is not there then does javac command creates it for us or just complains saying cakes folder is not there or it simply puts class file at C:\Users\Desktop\gpfolder\gpmy\SampleCode\Online\avajava\stuff

Please advise
gudii9

ASKER
when i gave

javac TransientDemo.java -d .


it created
cakes folder under
C:\Users\Desktop\gpfolder\gpmy\SampleCode\Online\avajava\stuff



then
it created two class files as below and put them under C:\Users\Desktop\gpfolder\gpmy\SampleCode\Online\avajava\stuff\cakes
TransientDemo.class
TransientDemo$1MyDemo.class

what is the purpose of TransientDemo$1MyDemo.class


Also what is the use of -d . as in the command
javac TransientDemo.java -d .

please advise
Your help has saved me hundreds of hours of internet surfing.
fblack61
gudii9

ASKER
instead of javac TransientDemo.java -d .

when i gave
javac TransientDemo.java  

it did not give error. Instead it created  class file in folder below C:\Users\Desktop\gpfolder\gpmy\SampleCode\Online\avajava\stuff
which i feel wrong. I wonder why it happened like that. please advise
SOLUTION
girionis

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
gudii9

ASKER
If cakes folder is not there then does javac command creates it for us

Yes.


But in below case it did not create cake folder. Why?



instead of javac TransientDemo.java -d .

when i gave
javac TransientDemo.java  

it did not give error. Instead it created  class file in folder below C:\Users\Desktop\gpfolder\gpmy\SampleCode\Online\avajava\stuff
which i feel wrong. I wonder why it happened like that. please advise

what is the significance of  '-d ' at end as below
javac TransientDemo.java -d .
gudii9

ASKER
It means that you have another class called MyDemo inside the TransientDemo class.
I see inner class as belw but i wonder what is the purpose or practial use of inner class here.
public class TransientDemo {

      public static void main(String[] args) {

            class MyDemo implements Serializable {
                  private static final long serialVersionUID = 1L;

Please advise
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
girionis

The -d means "destination", it is the destination of the compiled classes.

For your second question, read an extensive answer at javaworld and stackoverflow.
gudii9

ASKER

If cakes folder is not there then does javac command creates it for us

Yes

Does it create cakes folder in which of below scenarios (with or without -d.)
Scenario A: javac TransientDemo.java  


or

Scenario B : javac TransientDemo.java -d .


i am assuming below flow

I created the TransientDemo.java file under below folder


C:\Users\Desktop\gpfolder\gpmy\SampleCode\Online\avajava\stuff  


The TransientDemo.java file has package called cakes.

package cakes;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class TransientDemo {

  public static void main(String[] args) {




I opened command prompt in my windows laptop went to below folder
C:\Users\Desktop\gpfolder\gpmy\SampleCode\Online\avajava\stuff

gudii9

ASKER
so what happens when

I created the TransientDemo.java file under below folder


C:\Users\Desktop\gpfolder\gpmy\SampleCode\Online\avajava\stuff  


The TransientDemo.java file has package called cakes.

package cakes;(here with or without package statement cakes)
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class TransientDemo {

  public static void main(String[] args) {




also javac command with or without -d

javac TransientDemo.java -d .


javac TransientDemo.java

In what case cakes folder created with which javac command. please advise
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck