How do I compile a .java file into class version 8?

I downloaded JDK 8 and when I use the Javac (class file) it compiles the .java into an incompatible .class version. How would I compile a .java file into a specific .class version?

πŸ‘︎ 4
πŸ’¬︎
πŸ“…︎ Dec 30 2021
🚨︎ report
HELP, NDS HOMEBREW, PSTRO NDS JAVA: so I wanted to use the Pstro NDS Java homebrew software to launch a .jar game, it didn't work so I used JADmaker to make the file into both a .jad and .class but still doesn't work, any suggestions? reddit.com/gallery/r4qq56
πŸ‘︎ 11
πŸ’¬︎
πŸ‘€︎ u/Gelborb_357
πŸ“…︎ Nov 29 2021
🚨︎ report
Updating Minecraft Server to 1.18 Issue Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 60.0

Hi friends,

I am trying to update my Minecraft server, and I am getting the below issue. I have tried redownloading the file from Minecraft and updating java, and i am still stumped. Has anyone else experienced this? Can anyone please help?

Error: LinkageError occurred while loading main class net.minecraft.bundler.Main

java.lang.UnsupportedClassVersionError: net/minecraft/bundler/Main has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 60.0

πŸ‘︎ 4
πŸ’¬︎
πŸ‘€︎ u/Truthlessheros
πŸ“…︎ Nov 30 2021
🚨︎ report
How to i pull info from another Java class(in another file)

So Java isn’t mu main language, so I don’t know along of the in depth stuff. I recently met with another FTC programmer who had a class in a other code file, and was able to pull it to which ever file he wanted it to. The file just had some functions so he didn’t have to re write them, Andy advice on how to do this, also we use onbot Java.

πŸ‘︎ 5
πŸ’¬︎
πŸ‘€︎ u/Busy_Command
πŸ“…︎ Nov 12 2021
🚨︎ report
Trying to Make Equivalent .class files (with Java and Clojure)

I followed the guide here and am able to produce a .class file whose method ("exec") I can invoke while running a SPARQL query. No problem with Java.

Then I tried to replicate that .class file using Clojure. I am getting a java.lang.AbstractMethodError when I try to invoke the "exec" method in this .class file.

Here is the Java source that works.

Here is the Clojure that I tried to make equivalent to that Java source.

Here is the javap output for the .class file from the Java source.

Here is the javap output for the .class file from the Clojure source.

Here is the error.

Versions are here.

For the Clojure source: I built /app/datething.jar with lein uberjar.

For the Java source: I built /app/myapp.jar with mvn clean compile assembly:single.

I invoke Apache Fuseki like this:

java  -cp /app/myapp.jar:/app/datething.jar:/app:/app/sparql-anything-fuseki/target/sparql-anything-server-0.4.0-SNAPSHOT.jar com.github.sparqlanything.fuseki.Endpoint

Can anyone spot what I am doing wrong?

πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/justin2004
πŸ“…︎ Oct 24 2021
🚨︎ report
Is there any way to statically detect broken references in a set of Java class files?

A few weeks ago we ran into a problem where we'd upgraded some dependencies in a project to newer versions, and things seemed to be fine, but it turned out that one code path that wasn't exercised in our unit tests would sometimes throw a NoSuchMethodError. This was because one library that our code depends on (let's call it libraryB) was sometimes calling a method in another library that our code also directly depends on (libraryA), and the newer version of libraryA had removed that method. Nothing was caught during the build, because none of our code directly referenced the removed method.

Today we ran into this problem again with a different set of libraries. This time our tests found the problem ("libraryB" in this case was our test framework), but it took a while to debug.

I'm wondering if there are any tools that could help detect this situation at build time by performing static analysis of the classes in the runtime class path.

I know this won't be perfect in cases where reflection or classloading outside of the predefined classpath are being used but aside from that I believe it's at least theoretically possible: starting at a set one or more entry points, crawl the references to other methods, classes, and fields, and report any reachable references that have no match in the classpath.

Are there any existing tools that can do this?

πŸ‘︎ 33
πŸ’¬︎
πŸ‘€︎ u/xenomachina
πŸ“…︎ Mar 05 2021
🚨︎ report
Problems running 1.17.0 java server (Main has been compiled by a more recent version of the Java Runtime (class file version 60.0))

So I have fully updated java to the latest release and I have verified my machine will run the server of 1.16.5. However, when I use the 1.17.0 server jar file, I get this..

G:\Minecraft\server>java -Xmx1024M -Xms1024M -jar servernew.jar Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.UnsupportedClassVersionError: net/minecraft/server/Main has been compiled by a more recent version of the Java Runtime (class file version 60.0), this version of the Java Runtime only recognizes class file versions up to 52.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$100(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

Nothing I do seems to fix this. Any suggestions?

EDIT: Fixed! I had 8 still installed WITH 16.. Once I deleted 8, it worked.

πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/Lance_lake
πŸ“…︎ Jun 09 2021
🚨︎ report
Getting a String from java class to javascript file

Hey Guys!

I am currently sitting on a university project using Java Spring. It is going to be some kind of employee management system, where I need a piece of google maps with pins on cities where employees are active in the terminal.

However, when I use the Google Maps API with javascript it is reeeeeally simple to create a pin in a specific location, but the terminal is (and has to be) coded in Java.

That s why I am looking for a way to get a String from the Terminal class (the name of the city) into my javascript file, so I can work with it there.

I can t hardcode it because the functionality to add new terminals is required.

Any help is much appreciated, since I am fairly good in Java but completely new to JavaScript.

πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/frevelmann
πŸ“…︎ Jun 14 2021
🚨︎ report
Accessing methods in a controller class in a JAVA file.

I am new to FXML and am having a bit of a trouble. I have my FXML file created, as well as my controller class and some methods in some JAVA classes. Is there a way to access Methods and Objects that are inside my Controller class, in my JAVA classes? I have tried making them static, but then the controller doesn't recognize them. Is there a solution, or should all my methods be made in another class?

πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/CampNaughtyBadFun
πŸ“…︎ Apr 01 2021
🚨︎ report
Can I Save Just A Class File? (JAVA)

I have a two-part project where in the first part I write a CLASS from a textbook problem and a UML diagram of it(Below is the direction):

  • Create the UML diagram as instructed in Algorithm Workbench #1a, page 392.
  • Write the Java class as instructed in Algorithm Workbench #1b, page 392
  • Be sure to write only the class and not a program.

And the second part I write a PROGRAM from the UML diagram of the first class(from the first part). The PROGRAM also includes creating objects and running inputs through the program. (Below is the direction):

  • Write the Java program for the UML class diagram.
  • Be sure to write only the program. Do not include the class in the program file or a zero is earned for this entire assignment.

Is anyone able to explain what this means or can describe what is different between submitting just the class vs. the program? Am I even to submit a file that is a class(xxx.class)?

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/jcksnsmyth
πŸ“…︎ Apr 17 2021
🚨︎ report
Separating .class files from .java files

I'm not super sure that this is the correct place for this but it definitely has to do with programing.

I'm trying to make my files look a bit cleaner by making a directory for all my .class files for my java projects in sublime text 3. I assumed I could just make a separate directory like I see IDEs like Eclipse use but when I move the .class files and attempt to run the code it says it cannot find/load the main class.

Do I need to manipulate some sort of path in my system environment? If I do, do I need to do that for every bin directory that I have for other file paths? If so, how?

If this isn't the correct place for this please point me in the right direction.

πŸ‘︎ 4
πŸ’¬︎
πŸ‘€︎ u/alem_147
πŸ“…︎ Jan 20 2021
🚨︎ report
How to a refresh the whole Java file on a Mac, for context I am working on locked test for homework, after unlocking the test I’m supposed to refresh so a new class pops up from GitHub to confirm I’ve unlocked the test. Thanks!
πŸ‘︎ 14
πŸ’¬︎
πŸ‘€︎ u/dee_gamer
πŸ“…︎ Feb 04 2021
🚨︎ report
is it possible to use minecraft's sources (java/class files) in a plugin?

im fairly new to making mc plugins btw so i dont know a lot of the stuff. i know that if you're making a plugin, you just simply 'include' the bukkit/craftbukkit jar file and that lets you use extend from JavaPlugin. and you can also use the entities that come with bukkit, which are in org.bukkit.entity.Entity, etc.

what im wondering is, is it possible to 'include' the minecraft source files? e.g. using net.minecraft.entity.Entity, or net.minecraft.tileentity.TileEntity (instead of bukkit's solution like BlockState). i've tried in the past but it always says that the sources dont exists (when importing both the java files and class/compiled sources).

i did find that using CraftBukkit for example (im using a very old version of minecraft, 1.6.4), i can use net.minecraft.server.v1_6_R3.Entity, which does work. and then i could make my own functions for converting bukkit objects to CraftBukkit objects (i think they're sometimes called 'notch objects' too), like getting the CraftBukkit's WorldServer from Bukkit's CraftWorld handle, then converting a BlockState to TileEntity using the block positions. however i still want to try and use minecraft's original sources.

is it possible?

(btw im doing this because im trying to fix some bugs/crashes in mods, and i cant fully 'interface' with those mods due to the missing references from minecraft's sources, because the mods are looking for net.minecraft.tileentity.TileEntity whereas i can only get net.minecraft.server.v1_6_R3.TileEntity. i can interface with mods in places where minecraft's source objects aren't needed, but once they're required in functions for example... cant use)

edit: not sure if this is actually how MC does it, but i think on the server side the server remaps all of the mod's imports to the server side ones, e.g. net.minecraft.entity.Entity to net.minecraft.server.v1_6_R3.Entity for example. so i guess what i'd need to do is remap the mods myself and include them as dependencies to my plugin project (instead of the original mod). idk how to do that though :(

apparently it doesn't do that but i found a way to import the Minecraft sources allowing me to recompile mod files so that's pretty nifty

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/tea-vs-coffee
πŸ“…︎ Dec 28 2020
🚨︎ report
My jar file cannot make use of its libraries and gives Exception java.lang.NoClassDefFoundError: org/json/JSONObject. Tho this JSONObject is being accessed and i don't get any exception when i run my Main class.

Solved, thanks to this post

I have created a Java project with an artifact JAR. This project uses JSONObject class from its jar file. Which i am able to access and use in my project and i don't get any exception but when running the jar file created i get the exception java.lang.NoClassDefFoundError: org/json/JSONObject.

Is it due to JSONObject jar file not being bundelled with my project JAR artifact?

This is my artifact settings page and Here you can see i have added jsonObject Jar file as library

Here i have added JSONObject as dependency

πŸ‘︎ 12
πŸ’¬︎
πŸ‘€︎ u/like_my_likes
πŸ“…︎ Sep 06 2020
🚨︎ report
Running a .java file as opposed to .class?

I started learning Java pretty recently, and I've been running programs successfully for a while now. However, my cousin, who also just started learning Java ran into something kinda strange. I understand that the .java file has to first be compiled to create the .class file, which contains the byte code for the JVM. At least this is my understanding. My cousin, though, found that after compiling, the only way for him to run the program was to say:

java program.java

Whats more, after deleting the .class file completely, the program still runs with the above command in the cmd. Notably, I'm on Windows while he's on Mac, but this seems like such a drastic departure from what I know about how Java works that I don't really have a clue why this is happening. Does anyone have experience with this particular issue? Would greatly appreciate an answer.

πŸ‘︎ 9
πŸ’¬︎
πŸ“…︎ Aug 15 2020
🚨︎ report
TIL Java .class file header contains magic number 0xCAFEBABE
πŸ‘︎ 9
πŸ’¬︎
πŸ‘€︎ u/danielsoft1
πŸ“…︎ Oct 29 2020
🚨︎ report
Help please, I’ve saved the file name as Level1.java, should i save the other public classes and save them all in a folder? Im confused. Thanks.

Its saying β€œclass Level2 is public, should be declared in a file named Level2.java” β€œclass NoOverrideFinal is public should be declared in a file named NoOverrideFinal.java”

πŸ‘︎ 7
πŸ’¬︎
πŸ‘€︎ u/poctis
πŸ“…︎ Jul 30 2021
🚨︎ report
What are .class files used for post java 11?

So I wanna start of by saying that i'm sort of new to java and still have no idea what i'm doing, anyway, recently I decided to play around the command line and try to compile and run a few of my school homework (as opposed to doing so with an IDE).

Obviously, I started with "javac -classpath "someLibrary"ex10.java" which gave me a .class file but when i went to run that .class file with "java -classpath "someLibrary" ex10.class" it gave me the following error:

Could not find or load main class ex10.class

Caused by: java.lang.ClassNotFoundException: ex10.class

Running java -classpath "unit4.jar" ex10 gave me:

Error: Could not find or load main class ex10

Caused by: java.lang.NoClassDefFoundError: prjGrid/ex10 (wrong name: ex10)

But for some reason when i just ignored the .class file and ran java -classpath "unit4.jar" ex10.java everything ran perfectly. I read that java 11 introduced a way to run .java files without compiling separately, but then why do we need .class files and the "javac" command in the first place post java 11?

πŸ‘︎ 12
πŸ’¬︎
πŸ‘€︎ u/Ph4nT0mZ
πŸ“…︎ Aug 16 2020
🚨︎ report
Viewing Java Class Files in Emacs nullprogram.com/blog/2012…
πŸ‘︎ 5
πŸ’¬︎
πŸ‘€︎ u/negativeoilprice
πŸ“…︎ Dec 22 2020
🚨︎ report
[College - Java programming] not sure what I’m doing wrong here. I need to change the class name to awesome and file name to Awesome.java. But when I change Programming to awesome I get an error.
πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/Cosmicmermaidx3
πŸ“…︎ Sep 06 2020
🚨︎ report
What is the name of class file? (java)

Before I start, this is from a quiz I just gave. I got 9.5/10 and this frustrated me. The question is:

>What is the name of the class file you create following these instructions:
>
>Open Eclipse, create a new Project and a new Package named Week2Quiz.
>
>In the package, create a class named Test and put the following code into your class file:

/**
Β * This is a java class to test and review your knowledge in week 2
Β */
package week2Quiz;
import java.util.Scanner;
/**
Β * u/author Kkeogh
Β *
Β */
public class Test {
/**
Β * u/param args
Β */
public static void main(String[] args) {
int x, y;
float f;
Scanner scan;
scan = new Scanner(System.in);
System.out.print("Please enter a whole number : ");
x= scan.nextInt();
f = x;
System.out.println(x/2);
System.out.println(x%2);
System.out.println(f/2.0);
if (x%2 == 0)Β 
System.out.println("Red");
else
System.out.println("Green");
x=99;
System.out.println("The value of x is "+x);
x-=9;
System.out.println("The value of x is "+x);
y=x/10;
y++;
System.out.println("The value of y is "+y);
}
}

I wrote the answer "Test" and I got marked 0.5 out of 1. What should I have written? Test.class? I have another attempt left and I want to get 10/10 and I would appreciate if anyone would help me with this.

Thank you.

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/subaz08
πŸ“…︎ Aug 08 2020
🚨︎ report
How Do I print media like .mp4, .mp3, .mov, .jpeg, .png, .gif files in a Java Class?

So I started doing java in 9th grade this year and I wanted to know how to run these files. Im making a game and I wanna know how to run these files in a java class. I looked it on the internet and most of the programs were skeletal and I could not understand. Do I have to make a class and declare it as a package or what do I do? Im only a beginner and my knowledge ony extends till the imperative statements. Plz help.

πŸ‘︎ 5
πŸ’¬︎
πŸ‘€︎ u/Pradius_Pie1908
πŸ“…︎ Oct 03 2020
🚨︎ report
On the structure of Java files and classes

Hi everyone,

I had a question pop in my mind recently : how should Java classes be declared ? One per file or are several classes per file ok?

I ask this because in my Java course, we usually have one class/enum/interface per file and that's it. It's even implied by the IDE's as Intellij or Netbeans will ask you what your file will be (class/enum/interface,etc) when you create a new one.

In other languages such as Python though, it's often advised you put related classes together in the same file. But there's also no notion of package and scope as there's in Java.

So what's what?

Thanks

πŸ‘︎ 28
πŸ’¬︎
πŸ‘€︎ u/NoisyFrequency
πŸ“…︎ May 19 2021
🚨︎ report
what command line tool can disassemble java class file

Hi, what command line tool can disassemble java class file with source line information? javap seems can't
thanks
Peter

πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/quantrpeter
πŸ“…︎ Jun 02 2020
🚨︎ report
How to decompile .jar file or .class file? | Java Decompilers & eclipse ...
πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/javabeam12
πŸ“…︎ Sep 14 2020
🚨︎ report
A Chess game built in java that is displayed and played in the terminal. Used this as a way to teach myself the language. Feedback welcome for how to improve it. Forewarning: this file is thicc. Main class is around 700 lines of code. github.com/DankTrainTom/J…
πŸ‘︎ 10
πŸ’¬︎
πŸ‘€︎ u/DankTrainTom
πŸ“…︎ Apr 19 2020
🚨︎ report
Import Java Class in Other Java File

This may sound very dumb to those who are advanced but..

I am much better at python where I know what I want would look like

#Gets all the information from the Animal.py file

from Animal import Animal as Animal

If I wanted to import Animals.java with the Animals class into Zoo.java what is the java approach? Basically rebuilding an old project in new language but really stumped on this, even if it's trivial.

Thank you!

πŸ‘︎ 3
πŸ’¬︎
πŸ“…︎ Feb 05 2020
🚨︎ report
Minecraft says that main file was compiled using a newer version of java, and that it only recognizes class files till version 52.0

when I launch Minecraft 1.17 in vanilla, I am able to launch it normally, but when I use the new optifine1.17, Minecraft does not start up and I get this error on the developer console,

[09:52:58] [main/ERROR]: Unable to launch

java.lang.ClassNotFoundException: net.minecraft.client.main.Main

at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:186) ~[launchwrapper-of-2.2.jar:2.2]

at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:1.8.0_51]

at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.8.0_51]

at java.lang.Class.forName0(Native Method) ~[?:1.8.0_51]

at java.lang.Class.forName(Class.java:348) ~[?:1.8.0_51]

at net.minecraft.launchwrapper.Launch.launch(Launch.java:155) [launchwrapper-of-2.2.jar:2.2]

at net.minecraft.launchwrapper.Launch.main(Launch.java:30) [launchwrapper-of-2.2.jar:2.2]

Caused by: java.lang.UnsupportedClassVersionError: net/minecraft/client/main/Main has been compiled by a more recent version of the Java Runtime (class file version 60.0), this version of the Java Runtime only recognizes class file versions up to 52.0

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/aperiogon3141
πŸ“…︎ Jun 10 2021
🚨︎ report
New to Java, javac on class files

Pretty new to Java.

Say, you run javac first.java and it makes first.class. You can run this .class file with java first.

What if you run javac first.class, can you run what it makes / produces with the java command?

πŸ‘︎ 10
πŸ’¬︎
πŸ‘€︎ u/Dairy-Coq
πŸ“…︎ Aug 14 2019
🚨︎ report

Please note that this site uses cookies to personalise content and adverts, to provide social media features, and to analyse web traffic. Click here for more information.