Skip to content Skip to sidebar Skip to footer

Continueouse Update in Java Continuous Update in Java

Most of the software related majors in most universities in China have learned C and Java, but several languages ​​in .NET can be said to be choosch.

Since Visual Studio is relatively convenient on the Windows platform, some classmates will self-study .NET development technology before the Java class at the University.

This class of students require some code conversion skills to help learn Java.

Reprint, please indicate the author nukepayload2

Before this, I spitted Tinymce editor, it won't correctly dyed some keywords in VB.NET, such as Async, Nameof, Aggregate. Some keywords C # cannot be stained correctly, such as __ARGLIST.

Since I have begun to go to Java lessons, the misfortunes appearing in the code welcome everyone.

Enumeration type

VB

            Public            Enum                          Direction                        Right = 1                          DownRight     Down            DownLeft     Left     UpLeft              Up     UpRight                        End Enum          

C#

            public            enum                                          Direction                            {             Down = 1,             DownLeft,             Left,             UpLeft,             Up,             UpRight,             Right,             DownRight         }          

Convert to Java is like this. It feels almost the same as C ++ / CLI and C ++ / CX.

If the original enumeration is longer, it is best to write a small program to switch.

            public            enum                          Direction {             Down(1),             DownLeft(2),             Left(3),             UpLeft(4),             Up(5),             UpRight(6),             Right(7),             DownRight(8)                        private            int                          __value;                        private            Direction(int                          value) {                        this.__value =              value;     }      @Override                        public                          String toString() {                        return            String.valueOf(this            .nCode);     }  }          

That __value is my copy .Net reference source, if you see it, you can change your name.

2. Abnormal

Java's exception is not RuntimeException, you have to use the throws declaration, otherwise you can only process the unhandledException (ERRORLISTENER) like AccessviolaionException.

When converting the code, write a bunch of throws. Trouble, write a layer, I forgot what is abnormal.

This is better, as long as it is not a fatal exception, the custom exception is inherited to RuntimeException. Several several need to use the exception to ErrorListener with error.

            class            PointOutOfScreenException            extends                          RuntimeException{                        public                          PointOutOfScreenException(){                        super("Out of the screen ...");     } }          

have to be aware of is

<1> Java does not support an abnormal filter.

<2> Java does not support Try ... catch ... fault in MSIL (Using in VB, Using in C #)

3. Inference of the identifier type

VB

            Dim            a =                          New              StringBuilder                      

C#

            var            a =            new            StringBuilder();

Convert to Java and copy the Dafa with copy, copy the class name and paste it to the beginning.

StringBuilder a =            new            StringBuilder();

4. C # unsafe mode, VB and F # Various operators, dynamics, async, await, linq, no symbol type, event, delegate, custom value type, generic constraint

VB

                          Async            Function            LoadImages(device            As            CanvasDevice)            As                                          Task                            forestTiles            =            Await            SpriteSheet.LoadAsync(device,            $            "            SpriteSheets/ForestTiles{NameOf(ImageID)}.png            ",            New            Vector2(64,            64            ), Vector2.Zero)             wizardWalk            =            Await            SpriteSheet.LoadAsync(device,            "            SpriteSheets/WizardWalkRight.png            ",            New            Vector2(128,            192),            New            Vector2(64,            150            ))             wizardIdle            =            Await            SpriteSheet.LoadAsync(device,            "            SpriteSheets/WizardIdleRight.png            ",            New            Vector2(128,            192),            New            Vector2(64,            150            ))                        End Function          

C#

            async                                          Task              LoadImages(CanvasDevice              device)         {             forestTiles            =            await            SpriteSheet.LoadAsync(device,            $            "            SpriteSheets/ForestTiles{nameof(ImageID)}              .png            ",            new            Vector2(64,            64            ), Vector2.Zero);             wizardWalk            =            await            SpriteSheet.LoadAsync(device,            "            SpriteSheets/WizardWalkRight.png            ",            new            Vector2(128,            192),            new            Vector2(64,            150            ));             wizardIdle            =            await            SpriteSheet.LoadAsync(device,            "            SpriteSheets/WizardIdleRight.png            ",            new            Vector2(128,            192),            new            Vector2(64,            150            ));         }          

VB

            Public            Function            CalculateClipGeometry(resource            As            ICanvasResourceCreator, SourcePoint            As            Vector2, Geometies            As            CanvasGeometry(), ScreenSize            As            Size)            As                          CanvasGeometry                        Dim            geos =            Aggregate            geo            In                          Geometies              Let              Lines            =            Aggregate            tes            In                          geo.Tessellate              From              ln                        In            {New            LineSegment(tes.Vertex1, tes.Vertex2),            New            LineSegment(tes.Vertex1, tes.Vertex3),            New                                          LineSegment(tes.Vertex3, tes.Vertex2)}                        Select                          ln Distinct              Into              ToArray                        Select            Rays =            Aggregate            tes            In                          geo.Tessellate              From              light                        In            {New            LineSegment(SourcePoint, tes.Vertex1),            New            LineSegment(SourcePoint, tes.Vertex2),            New                                          LineSegment(SourcePoint, tes.Vertex3)}              Where                                      Not            (Aggregate            l            In                          Lines              Where              light.RayToBoundary(ScreenSize).HasIntersection(l)              Into              Any)                        Select                          light              Into              ToArray              Where              Rays.Length            >=            2            AndAlso            Rays(0).Name            Like            "            Ln*            "                                          Let              Fir            =              Rays.First                        Select            Arr =            Aggregate            ln            In                          Rays              Order By              ln.Angle(Fir)              Into              ToArray                        Select                                          CanvasGeometry.CreatePolygon(resource, {Arr.First.Point2, Arr.First.RayToBoundary(ScreenSize).Point2, Arr.Last.RayToBoundary(ScreenSize).Point2, Arr.Last.Point2})              Into              ToArray                        Return                          geos.Union                        End Function          

C#

            public            unsafe            void                          AddThree(__arglist)  {                        var            args =            new                                          ArgIterator(__arglist);                        var            a = (byte*)TypedReference.ToObject(args.GetNextArg());            *a+=3            ;  }          

Java

            //                          TODO: Write yourself. Directly convert this code but waste time!          

5. Event and commission

There is no article in this case, because Java has an anonymous class for the interface.

VB

            Event            Slide(sender            As            Object, e            As            SlideEventArgs)

C#

            delegate            void            SlideEventHandler(object                          sender,              SlideEventArgs              e);                        event            SlideEventHandler            Slide;

Java

            interface                          SlideEventHandler{                        void                          slide(Object sender, SlideEventArgs e); }          

VB processing event

            Sub            xx_Slide(sender            As            Object, e            As            SlideEventArgs)            Handles                          xx.Slide ...                        End Sub          

C # handling events

            Class name () {     xx.Slide            +=              xx_Slide; }                        void            xx_Slide(object                          sender,              SlideEventArgs              e) { ... }          

VB uses lambda expression handling events

            AddHandler            xx.Slide,            Sub(sender, e) ...

C # uses Lambda Expressions Processing Events

xx.Slide += (sender, e) =>  ...  ;

Java processing event

xx.setSlideListener(new                          SlideEventHandler(){                        void                          slide(Object sender, SlideEventArgs e){         ...     } });          

I haven't seen JDK 1.8 Lambda expressions can not be used to handle events and complete delegates, so they do not provide Java code in this area.

6. Important modifiers

Access level modifier

VB C# Java
Private private private
Protected protected not support
Protected Friend protected internal protected
Friend internal This is the default value
Public public public

Inheritance and polymorphic correlation modifiers

VB C# Java
MustInherit abstract abstract
MustOverride abstract abstract
Overridable virtual This is the default value
Overrides override @override
Overloads overload This is the default value
Shadows new not support
NotOverridable sealed final

Member class identifier

VB C# Java
Class class class
Module

[StandardModule()]

static sealed class

Final Class (inaccurate)
Event event not support
Custon Event event not support
Delegate delegate not support
Property Omitted not support
Dim Omitted Omitted
Interface interface interface
Function Omitted Omitted
Sub Omitted Omitted

7. Parameter passed

The following is a comparison of parameters.

VB C# Java
ByVal (This is the default value) This is the default value This is the default value
ByRef ref not support
ParamArray params ...
not support __arglist not support
not support * (Direct finger) not support
<In> in This is the default value
<Out> out not support

8. Attribute

Java does not support attributes, so you must write a method to encapsulate private fields :(

VB

            Public            Property            LastUpdateTimestamp            As            Date          

C#

            public            DateTime            LastUpdateTime {            get;            set;}

Java

            private                          DateTime lastUpdateTime;                        public                          DateTime getLastUpdateTime(){                        return                          lastUpdateTime; }                        public            void                          setLastUpdateTime(DateTime value){     lastUpdateTime            =              value; }          

Write here this time. Like Java, you can find an unreasonable place, but don't spray.

js practical code snippet (continuous update)

1. Get a number, the position number that should be in an ordered array: 2. Simple implementation of function debounce debounce: 3. Simple implementation of function throttling:  ...

Some tips for writing code (continuous update)

Initialize the double type array: Infinity 0x42; Infinity 0xc2. The read function of the template class: Prevent int explosion when reading longlong type numbers When reading int classint a=read<in...

Qt practical code snippet (continuous update)

Since the project needs to begin transformation learning C ++, GUI uses QT to develop, the development process has stepped on many pits, but it also accumulates some valuable experience, record it her...

8 basic sort algorithm code (continuous update)

I have recently seen two good blog posts, which introduces basic findings and sorting algorithms, they are constantly organizing, first put the code online, the reference materials are as follows: Vic...

smithockenshis.blogspot.com

Source: https://programmerall.com/article/51341360923/

Post a Comment for "Continueouse Update in Java Continuous Update in Java"