Categories
Entradas Java

Convert your JAVA programs into Windows EXE executables

Any JAVA programmer you have ever needed port your programs to native windows executables (especially those based on SWING, the JAVA GUI creation library) has run into the same problem.

By default, the execution of JAR files with a double mouse click requires that the user have the option of opening this type of program with the correct version of JAVA on their system (by default, some systems open it with winrar when it is installed with the basic options).

Many times the average user will not have knowledge of this or how to modify it, so the program can lose this type of user although its functionality is tremendously useful.

To avoid this contingency, Regex Laboratory has created a utility that seems essential: Jar2Exe

In RedesZone we are going to comment a little on this little tool, which is not free, but its cost is quite accessible: 11’13 euros for the standard version, with which we have plenty if we dedicate ourselves to free software and we are not interested in encrypting our code .

This program allows, starting from a .jar file, to create a Windows executable with multiple options that we will discuss in the article.

The first thing is to download the program from its official website:

http://www.regexlab.com/download/jar2exe/j2e_free.zip

We are going to download the free version, but we insist that the standard version, 11 euros, is more than enough for professional use.

We install and run it and the following screen appears:

This screen appears because our version is the free version. We simply click Next, the evaluation period is 30 days and it is more than enough for our article.

When you press next, this screen appears:

On this screen we choose our JAR file and the version minimal JAVA that our application needs.

We choose our test file and select JAVA version 1.6 as the minimum version:

We press next and we find this screen, in which we choose what type of application we are going to need. In our case it will be an application with a graphical interface, so we choose the second option:

And we click next. The program redirects us to this screen, in which we choose our Main class (the one that starts our JAVA program) and an image that will be used as Splash. In our case, our program already has a splash window, so we leave it blank. In most cases, the Main class will detect itself, if there is only one main in the application.

We choose and click next, navigating to this screen, in which we can configure different options: that the application is placed as an icon on the taskbar, that it supports the Windows log system and encrypt our JAVA file and its classes, to avoid where possible the hacking of our application. These are our options:

We press next and we see this screen, which only serves to add another .jar file and repeat the previous steps. In our case, it is not necessary.

We press next and on this screen we choose our icon for the program and its name when we create it. In our case, it will be Programa.exe and our icon will be a Windows icon, looking like this:

We click next and the .exe file is generated, next to our .jar file: it is ready to distribute and be used by our Windows users:

Categories
Entradas Java

Java course. Volume XVIII: Polymorphism

We return another Monday with another installment of the Java course.

In the previous installment we talked about the call to superclass methods, the redefinition of methods and how the call should be made superclass constructor from the “daughter” class.

In this installment we will talk about method polymorphism, or what is the same, methods that have the same name but are different internally, either by the number of parameters, or by the programming they have.

Without delay, let’s go with today’s volume.

We anticipate that delivery XX of our Java course will be an exercise that deals with the whole issue of inheritance and polymorphism and we will begin to apply access modes to the methods and attributes of the classes. But we will see the latter in volume XIX.

Polymorphism

The word polymorphism comes in “multiple forms.”

Polymorphic operations are those that perform similar functions with different objects.

Example: assume that class Figure and its subclasses exist

All of them with the operations:

We wish we could do the polymorphic operation move figure that works correctly with any kind of figure:

move figure

erase
draw in the new position

This polymorphic operation should:

  • call the operation erase of the Circle when the figure is a circle
  • call the operation erase of the Square when the figure is a square

Polymorphism in Java consists of two properties:

  • A reference to a superclass can point to an object of any of its subclasses.

  • The operation is selected based on the class of the object, not the class of the reference.

Thanks to these two properties, the method move figure would:

And it could be invoked as follows:

  • Thanks to the first property, the parameter f can refer to any subclass of Figure.
  • Thanks to the second property in move figure operations are called erase and draw appropriate.

The language allows a reference to a superclass to point to an object of any of its subclasses but not vice versa

Justification:

Any operation of the Vehicle class exists (overwritten or not) in the Car class.

  • A vehicle is not a car

It would be a mistake to try to invoke the operation:

For that reason the language prohibits it.

So far today’s volume, we only need one volume to finish everything related to inheritance.

In the next volume, as we indicated previously, we will deal with the access modifiers in Java and the conversion of references and we will give you a brief summary with the most important aspects of polymorphism and inheritance. It could be said that it is the basis for programming using these techniques.

Categories
Entradas Java

Java course. Volume XI. All about TCP and UDP Sockets in Java

Because we are on a networking page, and you already have our particular Networking CourseWe are not going to tell you the characteristics of TCP and UDP as transport protocols, nor of the IP protocol, we will directly explain the architecture that we must have in Java to achieve this.

Java provides the InetAddress class to manage IP addresses and domains, some methods we can find are the following:

  • byte[] getAddress (); returns the IP address of an InetAddress object.
  • InetAddress getByName (String host); returns an InetAddress object.
  • static InetAddressgetByAddress (byte[] direction) ; We enter an IP address and it returns an object with that address.
  • static InetAddressgetByAddress (String host, byte[] addr); same as above but also save host.
  • InetAdress getLocalHost (); returns an object with the local IP address of the computer

Here is an example of all these methods:

[java]package InetAddress;

import java.net.InetAddress;
import java.net.UnknownHostException;
public class IP addresses {
public static void main (String[] args) {
byte[] localAddress = {127, 0, 0, 1}; // Localhost IP address
InetAddress team;
try {
// InetAddress static methods to get the computer object
computer = InetAddress.getLocalHost (); // We create the team object of the InetAddress class
System.out.println (“My computer is:” + computer);
System.out.println (“Your IP address is:” + computer.getHostAddress ());
System.out.println (“Your name is:” + computer.getHostName ());
System.out.println (“And your canonical name:” + team.getCanonicalHostName ());
System.out.println ();

// We get the team from the name
computer = InetAddress.getByName (“www.google.com”);
System.out.println (“the www.google.com team is:” + team);
System.out.println (“Your IP address is:” + computer.getHostAddress ());
System.out.println (“Your name is:” + computer.getHostName ());
System.out.println (“And your canonical name:” + team.getCanonicalHostName ());
System.out.println ();

// We obtain the device from its IP address
computer = InetAddress.getByAddress (local address);
System.out.println (“My computer is:” + computer);
System.out.println (“Your IP address is:” + computer.getHostAddress ());
System.out.println ();

// We obtain all the IP addresses of a computer
InetAddress[] identities;
computer = InetAddress.getLocalHost ();
identities = InetAddress.getAllByName (computer.getHostName ());
for (int i = 0; i System.out.println ();

} catch (UnknownHostException e) {
System.out.println (“Connection failed”);
System.out.println (e.toString ());
}
}
} [/java]

The output of the above program would be this:

My team is: – / 10.10.2.11
Your IP address is: 10.10.2.11
His name is: –
And its canonical name: –

the www.google.com team is: www.google.com/173.194.34.240
Your IP address is: 173.194.34.240
His name is: www.google.com
And its canonical name: mad01s09-in-f16.1e100.net

My computer is: /127.0.0.1
Your IP address is: 127.0.0.1

Id0: – / 10.10.2.11
Id1: – / 192.168.213.1
Id2: – / 192.168.182.1
Id3: – / **% 10
Id4: – / **% 17
Id5: – / **% 18

Now we are going to make a TCP client-server for the exchange of messages. We will do a very simple exchange of messages, the explanations are in the code itself but it does not have any difficulty.

TCP server

[java]

package Sockets;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {

public static void main (String args[]) {
ServerSocket server;
Socket connection;
DataOutputStream output;
DataInputStream input;
int num = 0;
try {
server = new ServerSocket (5000); // We create a ServerSocket on the specified port
System.out.println (“Server Started Successfully”);
while (true) {
connection = server.accept (); // We wait for a connection
num ++;
System.out.println (“Connection number” + num + “from:” + connection.getInetAddress (). GetHostName ());
input = new DataInputStream (connection.getInputStream ()); // We open the input and output channels
output = new DataOutputStream (connection.getOutputStream ());
String message = input.readUTF (); // We read the client’s message
System.out.println (“Connection n.” + Num + “message:” + message);
exit.writeUTF (“You are the best” + message); // We reply
connection.close (); // And we close the connection
}
} catch (IOException e) {
}
}
}

[/java]

TCP client

[java]

package Sockets;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;

public class Customer {

public static void main (String args[]) {
Client socket;
DataInputStream input;
DataOutputStream output;
String message, reply;
try {
client = new Socket (InetAddress.getLocalHost (), 5000); // We create the socket to connect to port 5000 of the server
input = new DataInputStream (client.getInputStream ()); // We create the input / output channels
output = new DataOutputStream (client.getOutputStream ());
message = “RedesZone”;
output.writeUTF (message); // We send a message to the server
answer = input.readUTF (); // We read the response
System.out.println (“My message:” + message);
System.out.println (“Server Response:” + response);
client.close (); // We close the connection
} catch (IOException e) {
System.out.println (“Error:” + e.getMessage ());
}
}
}

[/java]

Now we are going to see how to make a client-server program with UDP. This program is somewhat more complex than the previous one, but in essence it is very easy, only that we are “playing” with strings that we pass from the client to the server so you already know.

The client program generates a random number every 100ms and converts it to a given string and sends it through the UDP socket to print the string it has sent (not the send number) and we will check if it has been received in order.

UDP server:

[java]

package FullJavaProgram;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ServerUDP {
public static void main (String[] args) throws SocketException {
DatagramSocket socket = new DatagramSocket (5001); // We create the UDP socket
System.out.println (“Server started successfully”);
int i = 0;
while (true) {
try {
byte[] buf = new byte[128];
DatagramPacket packet = new DatagramPacket (buf, buf.length); // We form the datagram to start receiving data
socket.receive (package); // Order to receive packages
String string = new String (package.getData ());
i ++;
System.out.println (“Received from client:” + string);
String chunk [] = string.split (“:”);
String chunk Good [] = piece[0].split (“<");
int check = Integer.parseInt (chunkGood[1]);
if (i == check) {
System.out.println (“Success”);
} else {
System.out.println (“There was an error”);
}
} catch (IOException ex) {
Logger.getLogger (CustomerUDP.class.getName ()). Log (Level.SEVERE, null, ex);
}
}
}
}

[/java]

UDP client:

[java]

package FullJavaProgram;

import java.io.IOException;
import java.net. *;

public class CustomerUDP {

public static void main (String[] args) throws SocketException, UnknownHostException, IOException, InterruptedException {
DatagramSocket socket = new DatagramSocket (); // We create the UDP socket.
int i = 0;
while (true) {
i ++;
Thread.sleep (100);
if (i <10) {
random int = (int) (Math.random () * 1000);
String string = “<00" + i + ":" + random + ">“;
DatagramPacket packet = new DatagramPacket (string.getBytes (), string.length (), InetAddress.getLocalHost (), 5001); // We create the datagram and send it with the indicated data (arguments)
socket.send (package);
} else if (i> = 10 && i <100) {
random int = (int) (Math.random () * 1000);
String string = “<0" + i + ":" + random + ">“;
DatagramPacket packet = new DatagramPacket (string.getBytes (), string.length (), InetAddress.getLocalHost (), 5001);
socket.send (package);
} else if (i> = 100) {
random int = (int) (Math.random () * 1000);
String string = “<" + i + ":" + random + ">“;
DatagramPacket packet = new DatagramPacket (string.getBytes (), string.length (), InetAddress.getLocalHost (), 5001);
socket.send (package);
}
}
}
}

[/java]

After these examples, you already know how to use TCP and UDP sockets for the exchange of messages, we hope you liked it and it will help you learn to program sockets in Java.

Categories
Entradas Java

Access modifiers and reference conversion

Today we will finish everything related to inheritance. We will cover the topics of access modifiers for both attributes and classes or methods, we will explain what it is used for and what the reference conversion is.

Together with the topic of inheritance and polymorphism, we will complete a block that will be very useful if we are going to continue programming in Java. Many of the programming concepts and ideas that we have seen so far, we will use very often from now on.

Let’s start with the agenda for this volume.

Access modifiers

Access modifiers for class members:

  • – accessible from package
  • public: accessible from the entire program
  • private: accessible only from that class
  • protected: accessible from the package and from its subclasses in any package

Notice: Define protected attributes NO it is good programming practice.

  • That field would be accessible from any subclass.

There can be many and that would greatly complicate the maintenance task.

  • Furthermore, the field is accessible from all classes in the package.

Recommended use of protected access modifier

  • General rule: all fields in a class are private.
  • Public methods are provided to read and / or change the fields (but only when necessary).
  • In the case that it is desired that a field can only be read and / or changed by the subclasses, methods are used protected

Package (subclasses or not).


Therefore and regarding the access modifiers applied to methods and attributes of the classes:

  • EVERYONE the attributes of the classes that we program will be private.
  • If we want to modify an attribute from another class, we will make a method to be able to modify it, without directly using the attribute (now we will not be able to because they are private).
  • The methods will remain public.
  • We will only put a private method when this method is only used from methods of the class itself.
  • Conversion of references (casting)

It is possible to convert references.

The casting changes the “point of view” with which we see the object

  • Through v we see it as a Vehicle (and therefore we can only invoke methods of that class).
  • Through c we see it as a Car (and we can invoke any of the methods of that class).

Doing an incorrect type conversion throws a ClassCastException exception at run time.

Java provides the instanceof operator that lets you know the class of an object.

  • v instanceof Car”Returns true if v points to an object of the class Car or any of its (possible) subclasses

With this we have reached the end of this installment.

In the next installment, as we have already mentioned, an exercise will be proposed, not very complex at the moment, which will basically consist of getting in touch with Java inheritance. When this is already established, we will propose a more complex one in which you have to use more knowledge. For now to close this chapter, I leave you a summary with the most important of inheritance and polymorphism.

Heritage

Classes can be extended.

  • The subclass inherits the attributes and methods of the superclass.

By extending a class you can redefine its operations.

  • If desired, it can be invoked from the new operation to that of the superclass: incremental programming.

New operations and attributes can be added to the subclass.

Polymorphism

Polymorphism allows us to abstract operations.

  • We can invoke them without worrying about the differences for different objects.
  • The system chooses the appropriate operation for the object.

Polymorphism is associated with class hierarchies:

  • A superclass and all subclasses derived from it directly or indirectly.

Polymorphism in Java consists of two properties:

  • A reference to a superclass can point to an object of any of its subclasses.
  • The operation is selected based on the class of the object, not the class of the reference.

We wait for you in the next volume !! Very soon we will start with graphics !!

Categories
Entradas Java

Java course. Volume VIII: Deadlocks in Concurrent Programming

In previous volumes we have seen how the monitors work, traffic lights and locks in Java, which is closely related to concurrent programming in Java.

However, we have not discussed a very common problem that usually occurs in concurrent systems: The famous and feared deadlock.

A deadlock, or also known as deadlock, prevents the concurrent program from continuing its execution since it is completely blocked and cannot advance.

What conditions must be met for a deadlock to occur?

  • Mutual exclusion to be able to reuse shared resources.
  • Partial allocation of resources, in such a way that the process only blocks what it needs at that moment and not all (to increase the performance of the program).
  • Once the resource has been acquired, we do not release it until we have taken the other one and finish our action.
  • Circular waiting: release of serial processes, that is, when one process waits for another, and in turn that other is waiting for the next.

We must design our program to avoid deadlocks. At first, the created program may not interlock, but it is possible that after several minutes it will interlock, so we must be careful when programming. If we are not very experienced, we can always do trial / error to check the result of our program.

The deadlock is also often called deadlock. In Wikipedia we can find more information about deadlock.

We can also see the following YouTube video showing DeadLock:

A classic DeadLock problem is the philosophers dinner that you can also find on Wikipedia.

Therefore, we must program in such a way to avoid this serious problem that we can leave our program totally unusable and all that it entails.

Categories
Entradas Java

Java Course: Binary Data Trees

A binary tree is an ordered and oriented tree, in which each node can have a left child and a right child.

Binary tree operations

The operations of the ADT tree are

  • parameterless constructor: Create an empty binary tree
  • constructor with one parameter: Creates a binary tree with a single element, which will be its root
  • constructor with three parameters: Creates a binary tree whose root is a node containing the indicated element, and making its left child be left branch, and its right child be right branch. Branches can be empty, and in that case no left or right child is added, respectively.

Operations of the iterators of binary trees (modification)

The iterator of binary trees is conceptually identical to that of trees, but its operations are different.

  • builder: Creates the tree iterator, with the current node equal to the root, or invalid if the tree is empty
  • InsertSonLeft: Add a left child to the current node, with the indicated value. Throw YaExists if a left child already existed
  • insert child right: Add a right child to the current node, with the indicated value. Throw YaExiste if a right child already existed
  • delete sheet: If the current node is a leaf, it removes it from the tree and makes the current node its parent. If it’s not a leaf, throw NoIsLeaf.
  • modifies element: Modifies the content of the current node by replacing it with the New element. Returns the old content of the current node
  • replacesBranchLeft: replaces the branch of the tree whose root is the left child of the current node, replacing it with new Branch (if it is empty it leaves the current node without a left child). Returns the branch that has been replaced as an independent tree (can be empty).
  • replacesBranchRight: replaces the branch of the tree whose root is the right child of the current node, replacing it with new Branch (if it is empty it leaves the current node without a right child). Returns the branch that has been replaced as an independent tree (can be empty).

Operations of the iterators of binary trees (traversal and query)

  • content: returns the element contained in the current node
  • iraARaiz: makes the current node the root of the tree; will be invalid if the tree is empty
  • go to son left: makes the current node the left child of the current one; will be invalid if the current node has no left child
  • go to son right: makes the current node the right child of the current one; will be invalid if the current node has no right child
  • go father: makes the current node the parent of the current one; will be invalid if the current node was the root
  • is sheet: returns a boolean that indicates if the current node is a leaf or not (that is, if it has no children)
  • esRaiz: returns a boolean that indicates if the current node is the root of the tree
  • has son left: returns a boolean that indicates whether the current node has a left child or not
  • has child right: returns a boolean that indicates whether the current node has a right child or not
  • it is valid: returns a boolean that indicates if the current node is valid, or not
  • clone: returns a tree iterator that is a copy of the current one

Binary trees interface

[java]

package adts;

public interface BinaryTree

{

IterBinTree iterator ();

void doNull ();

boolean isEmpty ();

}

[/java]

Interface for iterators of binary trees

[java]

package adts;

public interface IterBinArbol {

// modification operations

void insertsLeftChild (E element)

throws Already Exists, Not Valid;

void insertsChildRight (E element)

throws Already Exists, Not Valid;

E removesLeaf () throws NoIsLeaf, NoValid;

E modifiesElement (E elementNew)

throws Not Valid;

BinaryTree replaceLeftBranch

(BinaryTree newBranch) throws NotValid;

BinaryTree replacesRightBranch

(BinaryTree newBranch) throws NotValid;

// query operations

E content () throws NotValid;

boolean isSheet () throws NotValid;

boolean isRoot () throws NotValid;

boolean hasLeftChild () throws NotValid;

boolean hasRightChild () throws NotValid;

boolean isValid ();

// walk operations

void irARaiz ();

void goLeftChild () throws NotValid;

void goToRightChild () throws NotValid;

void goFather () throws NotValid;

// duplicate an iterator

IterBinTree clone ();

BinaryTree cloneTree ();

}

[/java]

Search in binary trees

Binary trees are very well suited for finding items efficiently. To do this, all the elements are stored in the ordered tree:

  • All the left descendants of a knot are smaller than it.
  • All the right descendants of a knot are greater than it.

[java]

public > IterBinTree searchesOrdered (E elem, IterBinTree iter)

{

if (! iter.esValido ()) {

// not found

return null;

}

try {

int comparison =

elem.compareTo (iter.content ());

if (comparison == 0) {

// node found

return iter.clone ();

} else if (comparison <0) {

// we look to the left

iter.irLeftChild ();

return searchOrdered (elem, iter);

} else {

// we look to the right

iter.irRightChild ();

return searchOrdered (elem, iter);

}

} catch (NotValid e) {

System.out.println (“Unexpected error:” + e);

return null;

}

}

[/java]

Inserting elements into the tree

[java]

public static > void insertsOrdered (E elem, IterBinTree iter)

{

try {

int comparison =

elem.compareTo (iter.content ());

if (comparison <0) {

// we go left

if (iter.hasLeftChild ()) {

iter.irLeftChild ();

insertsOrdered (elem, iter);

} else {

iter.insertaLeftChild (elem);

}

} else if (comparison> 0) {

// we go to the right

if (iter.hasRightChild ()) {

iter.irRightChild ();

insertOrdered (elem, iter);

} else {

iter.insertaChildRight (elem);

}

}

} catch (Already exists e) {

System.out.println (“Unexpected error:” + e);

} catch (NotValid e) {

System.out.println (“Unexpected error:” + e);

}

}

[/java]

With this we conclude today’s delivery of the Java course for the moment. The next time we come back it will be with concurrent and distributed programming in Java. If you have any questions, do not hesitate to tell us.

Categories
Entradas Java

Class, object and structure of a program

Exercise 1:

[java]

System.out.println (“Line number 1 n”);
System.out.println (“Line number 2”);

[/java]

Exercise 2:

[java]

System.out.println (“Line number 1” + “nhola”);

[/java]

We could also have done without the need to concatenate the strings (the + symbol is used to concatenate strings with variables or other strings).

The backslash and the n (n) is a reserved character and is used to make a new line (you will see that there are several more).

Once the previous challenge has been solved and discussed, it is time to get to this article, if you do not understand something, look for information to expand or contrast, and if you still do not understand it well, put a comment.

Class and Object Concept

Java programs are made up of classes. A class in java is a definition of a module of a program. Objects can be created from a class. Each of these objects is said to be an instance of the class.

Difference between class and object


An object is a program element characterized by:

– Attributes: are data contained in the object, and that determine its state.
– Operations or methods: these are actions with which we can request information about the object, or modify it.
– They are composed of sequences of instructions that operate with attributes.

Structure of a program

A java program is a set of classes, where one of them is special in two respects:

– Contains an operation called main.
– Usually objects of this class are not created.
– The operating system invokes the main method when executing the program.

Structure of an operation

The simplest case is that of a program with only one class, which has this structure:

[java]import imported_classes;
public class Name {
attributes
operations
}[/java]

Imported classes are those belonging to external packages.
– A package is a collection of classes.
– In a main class, one of the operations is called main.

Structure of a method or operation

Operations or methods (like main) have the following structure:

descriptors returned_value name (arguments)
{
statements;
instructions;
}

The declarations indicate and refer to data, classes, and objects to be used in the statements.

The instructions represent calculations that are made with that data.

Program example (The same as the first article):

[java]public class Hello
{
/ ** this is the main method * /
public static void main (String[] args)
{
// No declarations
System.out.println (“Hello, how are you?”);
}
}[/java]

  • public: the method can be used from outside.
  • static: the method belongs to the class (not the class objects).
  • void: nothing returns.
  • String[] args: is the argument, data that is passed to the operation.
  • System: is a predefined class that represents the computer.
  • out: it is an object of class System, predefined: it represents the screen.
  • println: method to put a text on the screen.
  • Comments: From documentation (/ ** * /), normal, with beginning and end (/ * * /), normal, until end of line (//).
  • Use of “;” to finalize statements and instructions.
  • Use of {} to define the contents of classes and methods.

In the next installment we will continue with data types and simple expressions

Categories
Entradas Java

Final Release of Java 8 Announced

Java is one of the most widely used programming languages ​​on a multitude of platforms. Both Windows and other systems such as Linux, Mac and even mobile platforms such as Android are compatible with this language, which allows programmers to launch cross-platform applications easily for all operating systems. Java works within a kind of “virtual machine”, which is what allows it to work on all operating systems without having to completely change all the source code.

Java JDK 7 was first released 2 years, 7 months and 18 days ago. During all this time it has been growing, improving and correcting bugs and vulnerabilities to encourage programmers to use this programming environment and to continue growing, especially on mobile platforms such as Android.

Just a few hours ago, the developers just published an entry announcing the final release of Java 8 for all users, the new version of this complete and multiplatform programming language.

The main novelties that will reach all programmers with the new Java 8 and that will open many doors to applications developed under this language are:

  • New lambdas that will allow the use of functional instances with concise syntax.
  • Possibility of working with default methods in the interfaces.
  • A new API for dates that simplifies working with days and times.
  • java.util.stream to perform operations on stock streams.
  • Lets you annotate an object multiple times with the same annotation.
  • Delete the PermGen space.
  • Developed a new method to order arrays in parallel.
  • Nashorn, the new JavaScript engine.

Oracle has announced a conference to announce the launch and talk about the main features of this new version of the programming language on April 25, 2014, a conference that can be followed live from the following Oracle web page.

The news of the new Java 8 is very interesting for programmers. We will have to wait to see what use these make of the new functions that Oracle has introduced to its multiplatform programming language.

Are you a programmer? What do you think of the new Java 8?

Source: mreinhold

Categories
Entradas Java

Our program to find cheap flights on Ryanair

We present you a program developed in the JAVA language, this developed entirely by us and we hope you like it.

Before starting, inform you that this program can be run on any operating system as long as it has the Java virtual machine installed.

BuscaVuelos RZ, Today it is in Beta phase, so it will have small errors, new ideas to improve the program will also be welcomed.

This program examines all flights on the website of Ryanair, the main difference with the website itself is that you can look at the flights for months and years in a table.

It also allows you to send a e-mail to our email inbox with the information we see on the screen, but including only the cheapest flights. Currently they are sent in plain text but later versions of the program will send a PDF with the results formatted conveniently.

Searches can be performed by month, year, origin, destination and with a maximum price filter.

It seems that the Java course it is paying off and we have done this little project so you can see what this programming language is capable of. Very soon we will also publish another program related to Pepephone.

Here are some screenshots.

Main menu:

Searching for flights:

Search result:

At the moment this is all, if we see that the program is interesting, it could be expanded to search for flights in other companies and above all, we would improve the graphical interface.

You can download the program from here:

Download BuscaVuelos RZ .JAR (All operating systems)

Download BuscaVuelos RZ .EXE (Windows Only)

Configuration of the mail properties (only using .JAR in the BETA version):

– Open the .JAR with the Winrar program or equivalent.
– Navigate to the files directory
– Extract the files configuracionCorreo.properties and emails.properties. Of these two files, the first is to configure the sender and the second the destination addresses
– Edit them conveniently according to the examples that come in them.
– Re-insert them into the .jar without any additional compression.

All kinds of comments, new ideas etc are allowed, even a better name for the program.

Categories
Entradas Java

Inheritance and polymorphism exercise

Another Monday, we are here with another installment of the RedesZone Java course.

We have already finished the topic of inheritance and everything related to it. We have talked about polymorphism, how the super class constructor should be called, and how objects should be created.

We have also talked about variable access modifiers, classes and methods. We saw where some methods that we have used and will continue to use come from, such as equals or toString. It is also worth mentioning that we have talked about the reference conversion of objects. You have all the articles available in the Java course index.

As we anticipated in the previous volume, in this installment we are going to propose a problem related to inheritance, not very complicated, but where you can practice everything related to it.

So let’s go with the statement.

ADSLZone needs to manage the entire web database in a different way from the one it now uses. Taking into account that they want to manage all the users of the web (both zoneros, as members of the staff), the Gurus of the page met to decide how this management should be done and all reached the following consensus:

  • All members are users
  • Users will have the following attributes private
  1. An integer that indicates how many messages it carries.
  2. A string containing the email.
  3. A string containing the name (nick) in the forum.
  • Users have the following methods:
  • Increase the number of messages by 1.
  • Decrease the number of messages by 1.
  • Modify the email.

The Gurus of AdslZone, who are very demanding, want there to be two classes within the users: moderators, administrators.

The moderators have the following attributes private

  1. An integer that indicates how many messages it carries.
  2. A string containing the email.
  3. A string containing the name (nick) in the forum.
  4. An integer that indicates the post number that they have sent to the papalera.
  • The moderators have the following methods:
  1. Increase the number of messages by 1
  2. Decrease the number of messages by 1
  3. Modify the email
  4. Increase by 1 the number of messages sent to the trash for breaking the rules

The administrators have the following attributes private:

  1. An integer that indicates how many messages it carries.
  2. A string containing the email.
  3. A string containing the name (nick) in the forum.
  4. An integer that indicates the post number that they have sent to the papalera.
  5. an integer indicating the number of bans you have made.

And they have the following methods.

  • Increase the number of messages by 1.
  • Decrease the number of messages by 1.
  • Modify the email.
  • Change your own username.
  • Increase the number of messages sent to the trash by 1 for breaking the rules.
  • Increase by 1 the number of user bans for being spammers.

From this we deduce that we have a clear superclass, the users, and then two subclasses, the moderators and the administrators.

The following scheme clarifies how the implementation of the three classes is required:

We are asked to implement the three classes with their respective methods. Realize that there are repeating attributes and methods in subclasses. This when implementing it is not necessary because you already know that we have extends.

You already know that if you have any questions, you can consult both Sergio and me.

In the next installment we will put the solution with detailed explanations so that the concepts are clearer.