#What's the name of the structure like its: "foo.bar.class"

1 messages ยท Page 1 of 1 (latest)

swift meteor
#

tiny question

upper acornBOT
#

<@&987246964494204979> please have a look, thanks.

upper acornBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

#

Here is an AI assisted attempt to answer your question ๐Ÿค–. Maybe it helps! In any case, a human is on the way ๐Ÿ‘. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

The structure you are referring to is called a package structure in Java.

torn dagger
#

fully qualified name class type

crisp ingot
#

it kinda depends on the context

#

java.util.Scanner here u have a package and then the name of the class

#

but nothing holds u back from naming ur classes with lower case

#

and then it could also be inner classes

#

such as in java.util.ArrayList.Iterator

#

Iterator being an inner class of ArrayList

#

and java.util being the package its in

#

but yeah, in the end its called the "fully qualified name" of a class

#

like its "full address"

swift meteor
#

wait, is the "java.util.Scanner" just a representation of the the equivlent file directory .\java\util\Scanner?

crisp ingot
#

yes

#

packages are supposed to be represented in file hierachy

#

(theres a flag to tell javac to ignore that, but still)

swift meteor
#

so if i have my class like this .\build\MainClass it would be like build.MainClass

crisp ingot
#

no

#

packages are first and foremost a concept in ur java code

#

when u create a class, the first line denotes the package its in

#
package foo.bar;

public class Test {
  ...
}
#

the Test class is in the package foo.bar

#

its full name is foo.bar.Test

#

and javac wants u to represent this package hierarchy also in folder structure

#

so ur supposed to put it in a foo/bar/Test.java

swift meteor
#

so it's exclusively used for packages or is this thing use for other things?

crisp ingot
#

but that doesnt mean that all folders are automatically packages

#

the part that makes a package is this first line in the class

swift meteor
#

hm

crisp ingot
#

packages are part of accessibility control

swift meteor
#

could i ask you a question about manifests?

crisp ingot
#

u know, theres public, protected, private and if u dont write anything, u get "package-visible"

#

so packages are for package-visibility

#

and ultimately are used to organize ur code in a meaningful way

#

similar to folders

#

hence why ur also supposed to represent them with folders

crisp ingot
swift meteor
#

ay

#

right now i've had troble getting my .jar file to world, as every time i run it using java -jar helloWorld.jar it responds with "could not find main class"

What i use to compile from .class \Test build> jar cfm build-1.jar .\build\Manifest.txt .\build\helloWorld.class

#

i think it's a issue about the manifest pointing the wrong way, as rn i have it as main-class: helloWorld

crisp ingot
#

dont write the manifest urself

#

let ur IDE do it

#

can u share ur current manifest?

swift meteor
#

ay

crisp ingot
#

can u share the full helloworld file

#

the java, not class

swift meteor
upper acornBOT
#

Here is an example of a Java JAR manifest file with a main class entry:

Manifest-Version: 1.0
Main-Class: com.example.MainClass

In this example, the main class entry is specified as com.example.MainClass. Replace com.example.MainClass with the fully qualified name of your main class.

crisp ingot
#

ur class needs to be public

#

and perhaps u also need to put it in a package

#

im not sure if jars work with the "default package"

#

btw import java.lang.Math; is obsolete. anything from the java.lang package is auto-imported implicitly

#

and this myObj.close(); is technically a bug

#

only if they are tied to files or similar

swift meteor
#

god i know so little about java

crisp ingot
#

dont worry

swift meteor
crisp ingot
swift meteor
#

it giving the error: say the public type needs to be it's own file

crisp ingot
#

then u did a mistake

#

gonna share the code

#

or ur misinterpreting the error

#

would be good if u share the actual error message

crisp ingot
#

i suppose its not helloWorld.java?

swift meteor
#

same as class...

crisp ingot
#

i doubt

#

look at the case as well

#

u likely called it HelloWorld.java or helloworld.java or sth

#

but not helloWorld.java

swift meteor
#

so helloWorld.class

#

exact same

crisp ingot
#

can u please just share a full screenshot of ur IDE window

#

with the class name, the code and the error message in it

#

full screenshot

swift meteor
crisp ingot
#

of ur entire IDE window

#

but i can already see that u called it 0.java

#

instead of helloWorld.java

swift meteor
crisp ingot
#

a general note: visual studio code is a really bad IDE for writing java code. every second user asking here for help with some IDE related problem is using VSC

crisp ingot
#

see, ur file is called 0.java

#

it must be called helloWorld.java

swift meteor
#

dose the name effect the compiling to a class file?

#

ah

tight wagon
#

id also recommend yout to follow standard java naming conventions

#

so the class should be called HelloWorld