[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

java package issue

Posted on 2014-01-10
11
Medium Priority
?
717 Views
1 Endorsement
Last Modified: 2014-02-07
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
1
Comment
Question by:gudii9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 3
11 Comments
 
LVL 35

Accepted Solution

by:
girionis earned 2000 total points
ID: 39773607
If you define a package then your class should be within this package. So the class file generated at C:\Users\Desktop\gpfolder\gpmy\SampleCode\Online\avajava\stuff should actually be in C:\Users\Desktop\gpfolder\gpmy\SampleCode\Online\avajava\stuff\cakes. You can solve it by doing:

javac TransientDemo.java -d .
java cakes.TransientDemo

The first statement tells the compiler to output the class in the current folder, so you will see a new folder called "cakes" created, and inside it there is your class.

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

what is meaning of  file extension of mydemo.ser

This is the serialised version of your output.

what are practical uses of the transient

If you don't want to serialise some fields you define them as transient.
1
 
LVL 7

Author Comment

by:gudii9
ID: 39786467
>>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
0
 
LVL 7

Author Comment

by:gudii9
ID: 39786475
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Author Comment

by:gudii9
ID: 39786501
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
0
 
LVL 7

Author Comment

by:gudii9
ID: 39786528
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
0
 
LVL 35

Assisted Solution

by:girionis
girionis earned 2000 total points
ID: 39789412
If cakes folder is not there then does javac command creates it for us

Yes.

what is the purpose of TransientDemo$1MyDemo.class

It means that you have another class called MyDemo inside the TransientDemo class.
0
 
LVL 7

Author Comment

by:gudii9
ID: 39816144
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 .
0
 
LVL 7

Author Comment

by:gudii9
ID: 39816231
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
0
 
LVL 35

Expert Comment

by:girionis
ID: 39817849
The -d means "destination", it is the destination of the compiled classes.

For your second question, read an extensive answer at javaworld and stackoverflow.
0
 
LVL 7

Author Comment

by:gudii9
ID: 39819090

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

0
 
LVL 7

Author Comment

by:gudii9
ID: 39824483
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
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question