Class to java conversion

Overview of Converting and Exporting Java Class Files

The Converter preprocesses all of the Java class files that make up a package, and converts the package to a CAP file. The Converter also produces an export file.

Checks on the input classes include:

  • Must be legal according to the Java Card Virtual Machine specification
  • Must be Java SE 7 or earlier.
  • All input class files are compatible with each other.
  • Export files of imported packages are consistent with class files that were used for compiling the converting package.

The Converter generates the following output files:

  • A CAP file, which is a JAR-format file which contains the executable binary representation of the classes in a Java package.
  • Java Card Assembly file.
  • Export file.

If the package to be converted contains remote classes or interfaces or if the -debug option is specified, the Converter generates a CAP file suitable for version 2.2 or greater of the Java Card platform. Otherwise, the Converter generates files that can also be used by version 2.1 of the Java Card platform. To create a CAP file compatible with version 2.1 of the Java Card platform, you must also use export files for Java Card API packages from the Java Card 2.1. x development kit.

The Converter tool can only convert one package at a time. If you are converting more than one package with interdependencies, convert the packages in two passes. First, generate only the export files, then, after that, convert the required CAP or Java Card Assembly files.

Читайте также:  Алгоритм евклида вычитанием питон

If you have a source release, you may choose to convert packages that import other packages. If you are creating Java Card Assembly files to generate a mask, then the major and minor version number of the imported packages must agree with the version number of the package that imports them. See Version Numbers for Processed Packages for more information.

If you have a source release, you can localize locale-specific data associated with the Converter. Before you use the Converter tool, be sure to compile your Java code properly as described in Setting Java Compiler Options. For more information, see Localizing With The Development Kit.

For more information on the CAP file and its format, see the Virtual Machine Specification, Java Card Platform, Version 3.0.5, Classic Edition . The CAP file also contains a manifest file that provides human-readable information regarding the package that the CAP file represents. For more information on the manifest file and its contents, see Working With CAP Files.

For more information on the Java Card Assembly file, see Java Card Assembly Syntax Example and Producing a Mask File from Java Card Assembly Files. For more information on export files, see Using Export Files.

Источник

How to convert .class to .java?

questionsProfile questionsAnswers by AmitPai questionsQuestions by AmitPai

madhukar2sri

profileProfile answersAnswers by madhukar2sri

look for Decompiler like DJ Java Decompiler

and it is not 100% done it does not show the imports.

nareshv1

profileProfile answersAnswers by nareshv1

Using jadclipse pluging installed in ur IDE,u can view the class files like java files, but u will not be able to edit.

To make a class file into java file in editable format, get the jad.exe file
in crompt prompt, goto the file location, keep the jad.exe where the class file is present and run the command

jad .class
The output will be filaname.jad, u can rename them as java file and use it again

The jad doesnt bring the comments and import statements which were there in the class file

Источник

Transform object into another type with Java 8

Quite often when calling to get external data you need to convert an object returned into a internal class. Learn how to transform an object into another type by using java 8 function and stream’s map.

Detailed Video Notes

Applications may need to translate an object from one system domain to another. For instance, you may make a rest web service request, cross business unit native call or vendor request that returns a Location object which you need to map to the internal MyLocation class. In episode 2 we walked through transforming from one object to another with guava, in this episode we will examine how to transform an object into another type with java 8.

Getting started

Before we get started, there is two concepts to cover. First is a java.util.function.Function which accepts one argument and produces a result. The second is stream intermediate operation map which converts each element in a stream into another object via the supplied function. The method construct below where T is the type of input to the function and R is the result of the function. So T is what goes in and R is what comes out.

FunctionT, R> myFunction = new FunctionT, R>()  public R apply(T t)  return null; > >;

Throughout this tutorial we will reference two locations objects, GoogleGeoLocation which represents an external data object and MyLocation which is the class for our internal system.

GoogleGeoLocation

public class GoogleGeoLocation  private Integer homeMobileCountryCode; private Integer homeMobileNetworkCode; private String radioType; private String carrier; /. > 

MyLocation

public class MyLocation  private Double countryCode; private Double networkCode; private String myRadioType; private String myCarrier; //. >

Converting a single object

The first step in converting an object to another is defining a function. Mentioned earlier, a function will accept a type of GoogleLocation and will return an instance of MyLocation . Inside this method we will create a new object of MyLocation and set the values passed from GoogleGeoLocation . Our mapping between objects is pretty straight forward but you could apply various mapping or business rules. Calling function.apply will apply the function to the given argument.

FunctionGoogleGeoLocation, MyLocation> externalToMyLocation = new FunctionGoogleGeoLocation, MyLocation>()  public MyLocation apply(GoogleGeoLocation t)  MyLocation myLocation = new MyLocation(); myLocation.setCountryCode(Double.valueOf(t .getHomeMobileCountryCode())); myLocation.setMyCarrier(t.getCarrier()); myLocation.setMyRadioType(t.getRadioType()); myLocation.setNetworkCode(Double.valueOf(t .getHomeMobileNetworkCode())); return myLocation; > >; @Test public void convertSingleObject()  GoogleGeoLocation googleLocation = new GoogleGeoLocation(310, 410, "gsm", "Vodafone"); MyLocation myLocation = externalToMyLocation.apply(googleLocation); assertEquals(myLocation.getMyRadioType(), googleLocation.getRadioType()); >
MyLocation [countryCode=310.0, networkCode=410.0, myRadioType=gsm, myCarrier=Vodafone]

Create a list of objects from another

Next you might be dealing with a collection of objects to convert. Let’s seed our data with random google locations and call java.util.stream.Stream() on the list. A java 8 stream represents a sequence of elements in which one or more operations can be performed such as reduction and aggregate operations. As we pointed out above we will call the map and pass in the function to transform the list. Finally calling collect we will instruct the stream to return a List of myLocations.

@Test public void convertCollection()  GoogleGeoLocation googleLocation1 = new GoogleGeoLocation(310, 410, "gsm", "Vodafone"); GoogleGeoLocation googleLocation2 = new GoogleGeoLocation(222, 777, "gprs", "Verizon"); GoogleGeoLocation googleLocation3 = new GoogleGeoLocation(111, 234, "gsm", "Sprint"); GoogleGeoLocation googleLocation4 = new GoogleGeoLocation(345, 567, "gprs", "Us Cell"); ListGoogleGeoLocation> gLocations = new ArrayListGoogleGeoLocation>(); gLocations.add(googleLocation1); gLocations.add(googleLocation2); gLocations.add(googleLocation3); gLocations.add(googleLocation4); ListMyLocation> myLocations = gLocations.stream() .map(externalToMyLocation) .collect(Collectors.MyLocation> toList()); System.out.println(myLocations); >
[MyLocation [countryCode=310.0, networkCode=410.0, myRadioType=gsm, myCarrier=Vodafone], MyLocation [countryCode=222.0, networkCode=777.0, myRadioType=gprs, myCarrier=Verizon], MyLocation [countryCode=111.0, networkCode=234.0, myRadioType=gsm, myCarrier=Sprint], MyLocation [countryCode=345.0, networkCode=567.0, myRadioType=gprs, myCarrier=Us Cell]]

Using a familiar way

You might be asking, why not use the standard foreach construct. Using a function promotes cleaner concise code, reusable method, promotes thinking in a functional manner and much easier to unit test. Just think, if we didn’t use a function we would have copied the same logic to convert a single object and the ArrayList. To show the contrast we wrote out a familiar way of pilling all the logic in a single for loop.

ListMyLocation> myLocations = new ArrayListMyLocation>(); for (GoogleGeoLocation externalLocation: gLocations)  MyLocation myLocation = new MyLocation(); myLocation.setCountryCode(Double.valueOf(externalLocation .getHomeMobileCountryCode())); myLocation.setMyCarrier(externalLocation.getCarrier()); myLocation.setMyRadioType(externalLocation.getRadioType()); myLocation.setNetworkCode(Double.valueOf(externalLocation .getHomeMobileNetworkCode())); myLocations.add(myLocation); > System.out.println(myLocations);

Hope you enjoyed today’s level up, have a great day!

Transform object into another type with Java 8 posted by Justin Musgrove on 24 November 2014

Tagged: java, java-tutorial, and java8

All the code on this page is available on github: View the source

Источник

Оцените статью