Java Tuple

Java Tuple

Tuples are a collection of objects of different types. The different types bit is what makes them different from arrays and lists. This would mean that you could have one object(with that tuple being that one object) contain all of someones identifying information, like age(int), gender(string), name(string), etc.

Ex:

Triplet<String, String, Integer> = new Triplet<String, String,Integer>(“Julia”, “female”, 20) ;

or in generalized form:

SpecificTupleType<ObjectType1,ObjectType2,etc> = new SpecificTupleType<ObjectType1,ObjectType2,etc>(Object1,Object2,etc);

That’s how you make a tuple by the way. So there are actually ten kinds of tuples, that vary bu how many objects you can have in a tuple, so for one object it would be a unit, two pair, three triplet, four quartet, etc. So the max number of objects you can have in a Tuple is 10. Also Java doesn’t have the JavaTuple data structure by default so you will need to download the JavaTuple library onto whatever platform you are using to make the program(EX.: Eclipse).

Some advantages to tuples are that they are immutable(which means you can’t change them after you have created them), they are type safe, they are serializable(which means that they can be put in the file system and can therefore be put into other applications) they can be used in iterations and they have things like toString() and equals() built into them.

Usefull Methods(will be updated with the rest of the information soon)

It’s possible I will also do one on the LabelValue and KeyValue classes.(There like another version of the pair tuple from my understanding).

Some sites to go to for more information are the tuple library which is already linked, geekforGeeks, tutorialspoints, and howtodoinjava.

C# arrays – basic information

C# arrays – basic information

An array is a place you store multiple variables of the same datatype. There are three types of arrays single-dimensional, multi-dimensional and jagged.

The single and multi arrays are what they sound like with the single dimensional array acting like a row, while the multi is like a grid, or a cube. So the single array is made like so:

type[ ] arrayName = new type[numberOfValuesBeingPutInArray];

or

type[] arrayName = {value1, Value2, Value3,etc};

You can also make a array by by doing:

type[] arrayName = newType[] {{value1, Value2, Value3,etc};

The multi-dimensional array is very similiar as it essentially just changes the [] to [ , ] or however many commas like so:

type[ , ] arrayName = new type[ numberOfRows, numberOfColumns ];

type[ , , ] arrayName = new type[ numberDimension1, numberDimension2, numberDimension3 ];

type[ , ] arrayName = {{V1,V2,etc}, {V1,V2, etc} , etc};

type[ , ] arrayName = {{{V1,V2,etc}, {V1,V2, etc} , etc}}, {{V1,V2,etc}, {V1,V2, etc} , etc} , etc} ;

You can essentially have as many dimensions as you want so long as you have the memory space for it and your compiler can handle it. If you declare an array without initializing it(assigning it values either with new or the {}, you would need to use the new operator to assign the values similar to what’s shown in the third example for single arrays.

You cannot change the length or number of dimensions after the instance of the array is made. If you don’t declare what the values in the array are they are the default for the type( 0 or null). The elements can be of any type so long as they are within the type of the array. This means that if you make the type Object (as in the object class that all types should be a part of) you can put whatever value want in it, but if you make an int array you can only put ints not anything else. When calling from an array the first value is at zero and the last value is at the number of values-1. So, arrayName[0,0] would call the value in the first column and the first row.

For example:

int array[] = {1,2,3,4,5};

System.Console.WriteLine(array[0]);

// the console will print out 1

System.Console.WriteLine(array[4]);

// the console will output 5

You can use a foreach loop to go through an array, which will be discussed in a different post. Along with some common and useful methods used with arrays.

A jagged array is an array of arrays , and this is the link to the more detailed post on them.

The Microsoft tutorial for this is here.

C# constructors

C# constructors

A constructor is what creates the instance of a class(also known as a object). They essentially define the default values for a object, even if you don’t specifically make a constructor you will still have the parameter-less constructor, which is essentially the default that every class will automatically have. It will set all global variables that aren’t defined to the default definition of their type.

A constructor is made by doing:

accessmodifier variabletype variableName;

accessmodifier variabletype2 variableName2;

public ClassName(parametertype1 parameterName, parametertype2 ParameterName2)

{

variableName = parameterName;

variableName2 = parameterName2;

}

It’s easiest to think of a constructor as a kind of method where it is used to define a object( aka giving values to global variables for that instance of the class), and it being the same name as the name of its type( with it’s type being the class you are making a instance of).

There are also static constructors which basically defines the static global variables.

So something like:

accessmodifier static variabletype variableName;

static ClassName()

{

variableName = value;

}

Notice that the static constructor is parameter-less since, the static variables shouldn’t be changing in the code based on which instance is being used.

You call a constructor by creating a object of that type with the correct arameters, in other words like this:

ClassName objectName = new ClassName( valueForParameter, valueForParameter2);

The valueForParameter can of course be a variableName or a value(as in say the parameter type was int you could but 12 or 15 or you could put the int variable myInt that you have already assigned a value).

There is more information on the Microsoft docs guide.

C# interfaces

C# interfaces

Note: I have only ever actually used interfaces in java, mostly because I don’t see a need for interfaces when making programs to be used in Unity.

A interface is essentially a completely abstract class. This means all the methods should be abstract. So its a group of related code that a non-abstract class or a struct need to implement. They are used because a class can only inherit one class but it can inherit multiple interfaces, and struct can’t inherit.

You declare a interface by:

interface IInterfaceName<T>

{

returnType MethodName( parameterType1 parameter1);

}

So you use interface instead of class and the name of the Interface should have a Uppercase I at the very beginning. Between the brackets is a abstract method.

You have a class inherit a interface by:

public class ClassName : IInterfaceName<ClassName>

{

}

The class that is implementing the interface must be public, non-static and have the same name as the interface member(the thing between the <>). It must also define all the abstract methods that don’t have a default. It has a default if you define the method in the interface(I believe you need to be working with c# 8.0 and above to do this though), but if you define the method in the class that default will be overridden. If the class that is implementing the interface is abstract it must still define the methods, but you can define them as abstract you just need to essentially tell the compiler that the method is abstract in the class. If a class were to inherit ClassName it would also inherit the interface, although you can still re-implement it. Classes can also define extra indexers and properties(so like get and set methods) for a property or index that is defined in a interface.

Click for info on this from Microsoft.

C# methods

C# methods

Methods are basically the places you put code so the program executes it. They are generally within a class and the main method of a class is where the program starts executing statements when running that code(unless another class is calling a method from that class). Generally the main method will call a constructor(link to a different post eventually) to make a object of that class, and/or call a different method to perform some sort of action.

The format for making a method is

accessmodifier optionalmodifier returntype MethodName( parametertype1 parameterName1, parametertype2, parameterName2)

{

//statements

}

The default access modifier is private, and putting it there is optional, so long as you want the access level to be private, if you want it to be public you have to put public. The optional modifiers i am talking about are things like abstract, sealed, static, ect which modify how you can use the the method. The return type is the datatype, or reference type you want your method to return to the place it was called from. If there isn’t a return type the keyword void should be in its place. The parameters are variables you are giving the method when you call it, if the method isn’t suppose to take any variables, leave the parenthesis empty.

When calling a method you have to pay attention to the return type if its a void method you need to call it something like:

object.MethodName( parameterName1 , parameterName2);

if it has a returntype it will need to be something like:

returntype variuableName = obj.MethodName(parameterName1, parameterName2);

The difference between the two is essentially that void is just performing a operation and shouldn’t be expected by the code to return something, while with a returntype the method does need somewhere to put the value it is returning.

The main method should be formatted along the lines of:

accessmodifier static void Main()

{

//statements

}

That is all the information I consider to be basic information there is of course more information at the Microsoft doc for c# methods.

C# variables

C# variables

In C# a variable is a name given to a space in the computers memory that the program manipulates. The various types of variables decides the size,layout and the range of values for that space, as well as the operators that can be applied to it.

These types are separated into value types and reference types.(built in means that the types should be available in any class )

  • Value types:
    • Simple types :
      • Signed integral(sbyte,short, int, long);
      • Unsigned integral(byte, ushort, uint, ulong);
      • Unicode characters (char);
      • IEEE binary floating-point( float, double);
      • High-precision decimal floating-point (decimal);
      • Boolean( bool) -true or false ;
    • User defined types :Enum types (enum E { . . . });Struct types (Struct S { . . .})
    • Nullable value types:Extensions of all other value types with a null value
  • Reference types
    • Class types
      • Ultimate base class of all other types: object
      • Unicode strings: string
      • User-defined types of the form class C { . . .}
    • Interface types
      • User-defined types interface I {. . . }
    • Array types
      • Single- and multi-dimensional
    • Delegate types
      • User-defined types of the form delegate int D( . . . )

The variables I tend to use are string, int, double, float, char bool and the reference types. You can also use the key word var to make a variable, it has to be within a method though.

You declare variables by doing:

variableType variableName = variable;

so when declaring an int it would be something like:

int myNum =5:

You don’t have to declare a variable and assign it a value at the same time so long as you assign the value before you use it.

In which case you do:

variableType variableName;

If you don’t want anyone to be able to change the variable after its declaration(and you do need to declare the variable for it to work). You put const in front of the variableType so it would be:

const myNum=5;

which would cause an error if someone tried to overwrite the variable assignment later in the code. If you are just changing the assigned value just do:

variableName = Variable;

You can declare multiple variables of the same type at the same time by doing:

variableType varN1=v1, varN2=v2, varN3 = v3;

Note you can’t use key words as names for variables, and you want the name to be somewhat descriptive so you know what it is when you use it. The names are also case sensitive and should start with a lowercase letter (although I don’t think the lowercase part is required by the system), they can’t contain whitespace and I believe they can only use letters,numbers and the underscore character( _ ).

C # classes

C # classes

Classes are a reference type. So they essentially tell the program that this set of constructors, methods, etc is associated with this object. So a class is really the blueprint for a object you are making, whether that object is in another class or is embedded in the class.

In C# there are namespaces which are essentially groups of classes. Most of these namespaces are for classes that the language gives such as System, which has the Console class in it. You can of course make one yourself. If you are using methods from a different class make sure to import it or have your class inherit it. I will talk more about this in a different post which I will link, If I remember.

So you use classes by creating a object that has that class as its type. For example:

Meclass whatever = new Meclass();

So it’s: NameOfClass NameOfObject = CallConstructore();

With the constructor call being new NameOfClass(VariableThatMatchesAConstructor)

You create a class by doing:

public class ClassName

{

//methods,constructors global variables, etc

}

So ‘public’ would be the access-modifier (will hopefully make a post on this too but for now you can look at Microsoft docs aka where I get most of my information on C#), the rest is fairy self explanatory.

objects vs classes

objects vs classes

The biggest thing to remember about objects and classes is that a object is a instance of a class. People commonly say that a class is a blueprint, and a object is a specific iteam made off of that blueprint. Another anology is that a class is a page in a coloring book, and a object is that coloring page fully colored, with the variables defined in the constructor being the colors.

An example of this is making a string:

string example = “object”:

So String is a class, and “example” is a object.

Some things to keep in mind is that their are static methods and variables and those belong to the class so if one object of that class changes a static variable, then that variable is changed for all the objects of the class during that runtime.

For example(in Java):

https://codehs.com/share/CountingObjects_sAXefQ

public class MyProgram
{
public static int numObj=0;
public int var=0;
public static int counto()
{
numObj++;
return numObj;
}
public int count()
{
var++;
return var;
}
public static void main(String[] args)
{
//static methods don’t have the object name in the call to the method because the object doesn’t //matter
MyProgram one = new MyProgram();
System.out.println(“these are the result of static variables”+ “\n”+counto());
// so numObj is 0 then 0+1=1
MyProgram two = new MyProgram();
System.out.println(counto());
//so numObj is 1 then 1+1=2

// non-static have the object name or this because it does matter
System.out.println(“These are the result of non-static” +”\n” +two.count()+ ” “+two.count() );
// so var =0 currently for object two ,so 0+1=1 then var now = 1 so 1+1=2
System.out.println(one.count()+ ” “+one.count() );
// so var =0 currently for object one so 0+1+=1, ten var now =1 so 1+1=2

}

}

. Net General

. Net General

Microsoft has it all explained here and the information below is just really basic summary of it https://dotnet.microsoft.com/learn/dotnet/what-is-dotnet

.Net is a free opensource cross development platform, which is used to make a variety of applications(so things for the web,mobile,desktop,gaming,and IoT(which stands for Internet of things)). It allows you to use multiple languages, editors and libraries to build said applications. The actual languages that these applications can be written in is C#, F#, and visual basic. The application will work on any compatible OS, but it depends on what .net implementation you are using.

The .net framework is for the stuff on windows.

Xamarin/Mono is for the major mobile operating systems.

THe .Net core is for implementation for windows,Linux, and MacOS.

.Net standard is the common API’s for all .net implementations, with the specific ones often having additional API’s like the framework has additionall API’s for accessing the windows registry.

NuGet is the package manager for .net.

.net is opensource under the .Net Foundation, which is a seperate independent organization.

A lot of people use .net because it is open source, it has a managed run time which improves security, it’s fast, it’s cross-platform, and it has shown to be the most productive platform for developers.

C# masterlist

C# masterlist

C# uses the .NET framework like C does. It is also a language that is object oriented. The language is used to make various kinds of applications such as mobile applications, windows applications and web applications, and games. Like Java c# has things like loops, arrays, data types, strings, single inheritance, etc.

Object oriented programming

  • .NET Framework :

References :

System namespace- (has a list of all the classes, so use search to find the class you want ) https://docs.microsoft.com/en-us/dotnet/api/system?view=netframework-4.8

Formatting, conversion,parsing etc – https://docs.microsoft.com/en-us/dotnet/standard/base-types/