Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Friday, 21 February 2020

CODING > Java 02 Password generator

Definition

As there is nothing more frustrating than create a new random password for everyone in a company, the automated process to do so could be required somewhere.

Summary

In the following script we create a java class "PassGen01" which has three main variables, containing two arrays of words and a random two digit number.

Later we have another two number generator (0 to 3 as the possible positions of the two arrays we have)

Finally, everything is concatenated into the variable "pass" and shown into console through a System.out

Code

public class PassGen01 {
public static void main(String[] args) {

String[] pass_list01 = {"Spring", "Summer", "Autumn", "Winter"};
String[] pass_list02 = {"Day", "Month", "Year", "Decade"};
int pass_num_random = ((int)(Math.random() * (99 - 10) + 10));

int pass_list_index_random01 = ((int)(Math.random() * (3 - 0)));
int pass_list_index_random02 = ((int)(Math.random() * (3 - 0)));

String pass = (pass_list01[pass_list_index_random01])
+ (pass_list02[pass_list_index_random02]) 
+ (pass_num_random) 
+ "!";
System.out.println(pass);
}

}

Results

AutumnMonth25!
SummerMonth95!
AutumnDay77!
AutumnYear65!
SpringYear94!

Tuesday, 18 February 2020

CODING > Java 01 Start


Starting on Java

Java is a general-purpose programming language that is class-based, object-oriented, and designed to have as few implementation dependencies as possible.
Java is for many, the starting point on coding as it represents the easy and flexible start as it is used as the base of so many server and desktop based applications

Downloading Java

There are many versions of different code languages and environments, depending if you are gonna use a interpreter for some application already written for any specific language or developing those apps themselves, you would need one or the other.
  • JRE: If you want to run Java programs, but not develop them, download the Java Runtime Environment
  • JDK: To start coding and executing java we would need  the Java Development Kit.
    Link here
At this point there should be some advice:

The Oracle JDK License has changed for releases starting April 16, 2019.

The new Oracle Technology Network License Agreement for Oracle Java SE is substantially different from prior Oracle JDK licenses. The new license permits certain uses, such as personal use and development use, at no cost -- but other uses authorized under prior Oracle JDK licenses may no longer be available

Apart from the Development kit, you would need as well some environment to start typing your code and run it, test it or break it. For that you need an IDE or Integrated Development Environment, we picked Eclipse

Start coding

After following the main tutorial, we arrive to our first java class / app which returns a classic "Hello World!"
public class HelloWorld {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello world!");
}
}

Links