15 vs 30 day trial licenses for Jenkins Enterprise

On February 24th, I’m taking the beta for the Jenkins Certification. This beta is different than beta exams from Oracle. In particular, it is only being offered on one day. The only choices you have are:

  • whether you want the morning or afternoon offering. It’s also only being offered in 12 cities (8 in the US and 4 in Europe). I chose the afternoon because I’ll probably be up late the night before. (yeah, I know. not ideal for taking an exam)
  • whether you want the Open Source or Enterprise version of the exam. I chose Enterprise because we use it at work and I like some of the features like templates.

This isn’t a great time for me to study for or take an exam. The exam is being held, literally the day after the robot is due for robotics team on which I mentor the programmers. This means I have little spare time. Especially for the week before the exam.  It’s worth a shot though. I know a lot about Jenkins without studying. And studying for the exam has filled in a lot of what I don’t know nicely.

I started studying two weeks ago (when I registered.)  I wanted to use a trial license for the enterprise edition so I could play with those features at home. I checked the evaluation agreement and it said that trial licenses default to 30 days. I checked again today and it says 15 days so either they fixed it or I misread it. It’s possible they fixed it because I did inform them of the discrepancy.

I filled out the trial form which gave me a 15 day license. I used the contact us form on Cloudbees site to ask about the 15 vs 30 days. They don’t allow gmail as an email provider so I used my javaranch address. (I get that they only want to talk to companies but what if someone is running a business our of gmail?)

A two week trial is also a big annoying because you get the green bar that resists being hidden reminding you that license is about to expire. This left me with a problem because I wanted to review some features a few days before the exam. I’d have installed the enterprise trial license if I had know that it was only good for 15 days.

I checked the license again and it doesn’t say that you can’t use two trials back to back. That would solve my problem. You can’t get another trial for the same instance id. You can for the same email.

Note: Check the trial agreement before attempting this to make sure it isn’t banned in the future.

Approach 1 – Clean install

First, I renamed my working directory so Jenkins thinks it is clean install. I’m not attached to any of my configuration or jobs. So a clean install is fine. I did backup my old install in case I wanted to check on my settings:

mv $HOME/.jenkins $HOME/.jenkins-bkp

Then I started Jenkins:

java -jar jenkins.war

This gives a clean install with no plugins. I then followed the instructions to convert to Enterprise including getting a trial license successfully.

I did want the exact same plugins along with build tools, so rather than redoing that all manually, I ran:

cp -r $HOME/.jenkins-bkp/plugins/* $HOME/.jenkins/plugins
cp $HOME/.jenkins-bkp/config.xml $HOME/.jenkins/config.xml

I then hand edited the config.xml to set <useSecurity>false</useSecurity> instead of true.

Approach 2 – Delete the license files

The technique described here to delete a few files also might work.

 

 

 

 

comparing strings with compareTo

Thinking about using our OCA 8 book to study for the Java Foundations Junior Associate exam? It covers most of the topics. See what other topics you need to learn and where to read about that. One of those topics is comparing two Strings using compareTo(). Luckily there are only two things you need to know.

What does compareTo() return.

Scenario Result
The two Strings are equal 0
The first String sorts earlier alphabetically  a negative number
The first String sorts later alphabetically a positive number

Let’s look at some examples:

String first = "abc";
String second = "def";
System.out.println(first.equals(first));  // true
System.out.println(first.compareTo(first)); // 0

System.out.println(first.equals(second));  // false
System.out.println(first.compareTo(second)); // -3
System.out.println(second.compareTo(first)); // 3

Don’t worry. You don’t have to know the answer is -3. You just have to know that it is negative or positive or zero.

How is alphabetically defined?
For the exam, you need to know that numbers sort before letters and uppercase sorts before lowercase. What do you think the output of this code is?

public class PlayTest {

	public static void main(String[] args) {

		String nums = &quot;123&quot;;
		String uppercase = &quot;ABC&quot;;
		String lowercase = &quot;abc&quot;;
		printComparison(nums, nums);
		printComparison(nums, uppercase);
		printComparison(nums, lowercase);
		System.out.println();
		printComparison(uppercase, nums);
		printComparison(uppercase, uppercase);
		printComparison(uppercase, lowercase);
		System.out.println();
		printComparison(lowercase, nums);
		printComparison(lowercase, uppercase);
		printComparison(lowercase, lowercase);
	}

	private static void printComparison(String one, String two) {
		int result = one.compareTo(two);
		if (result == 0) {
			System.out.println(&quot;0&quot;);
		} else if (result &amp;amp;lt; 0) {
			System.out.println(&quot;negative&quot;);
		} else {
			System.out.println(&quot;positive&quot;);
		}
	}

The answer is:

0
negative
negative

positive
0
negative

positive
positive
0

Make sure you can fill this in by yourself. You should also know the space sorts before letters. For example, printComparison(“ABC”, “A C”); prints out a positive number.

Summary

There’s not much you have to memorize. The key facts are:

  • The method name is compareTo()
  • Numbers sort before capital letters which sort before lowercase letters
  • Spaces sort before letters

Practice Questions

Question 1

What does the following output? (Choose all that apply)

String first = &quot;MOO&quot;;
String second = &quot;moo&quot;;
System.out.println(first.compareTo(second));
System.out.println(first.equals(second));

A: A negative number

B: Zero

C: A positive number

D: true

E: false

F: none of the above

Question 2

What does the following output? (Choose all that apply)

String first = &quot;moo&quot;;
String second = &quot; moo&quot;;
System.out.println(first.compareTo(second));
System.out.println(first.equals(second));

A: A negative number

B: Zero

C: A positive number

D: true

E: false

F: none of the above

Question 3

What does the following output? (Choose all that apply)

String first = &quot;MOO&quot;;
String second = &quot;MOO&quot;;
System.out.println(first.compareTo(second));
System.out.println(first.equals(second));

A: A negative number

B: Zero

C: A positive number

D: true

E: false

F: none of the above

Question 4

What does the following output? (Choose all that apply)

String first = &quot;moo&quot;;
String second = &quot;MOO&quot;;
System.out.println(first.compare(second));
System.out.println(first.equals(second));

A: A negative number

B: Zero

C: A positive number

D: true

E: false

F: none of the above

Question 5

What does the following output? (Choose all that apply)

String first = &quot;MOO&quot;;
String second = &quot;1&quot;;
System.out.println(first.compareTo(second));
System.out.println(first.equals(second));

A: A negative number

B: Zero

C: A positive number

D: true

E: false

F: none of the above

The answers are posted here.

using iterators in java

Thinking about using our OCA 8 book to study for the Java Foundations Junior Associate exam? It covers most of the topics. See what other topics you need to learn and where to read about that. One of those topics is iterating through a list.

Since Java 5, the most common way to iterate though a list (if you don’t need the loop index) is:

List<String>  list = Arrays.asList("sheep", "deer", "rat");
for (String name : list) {
   System.out.println(name);
}

Before Java 5 came along, there was another way:

List list = Arrays.asList("sheep", "deer", "rat");
 Iterator it = list.iterator();
 while (it.hasNext()) {
   String name = (String) it.next();
   System.out.println(name);
 }

But we are told to use generics in new code which would give us:

List<String> list = Arrays.asList("sheep", "deer", "rat");
 Iterator<String> it = list.iterator();
 while (it.hasNext()) {
   String name = it.next();
   System.out.println(name);
 }

Why would you do this? Shrug. For reading old code I guess. But it is on the test so no time like the present to learn this idiom. See what is wrong here?

// DOES NOT COMPILE
 List<String> list = Arrays.asList("sheep", "deer", "rat");
 Iterator<String> it = list.iterator();
 while (it.next()) {
   String name = it.hasNext();
   System.out.println(name);
 }

This one reverses the order of hasNext/next. Remember that you have to check that the iterator has a next element before getting it. Now what do you think is the problem with this?

// BAD
 List<String> list = Arrays.asList("sheep", "deer", "rat");
 Iterator<String> it = list.iterator();
 System.out.println(it.next());

If the list is empty, this code throws an exception. Probably not what you had in mind. Instead, you should write:


 List<String> list = Arrays.asList("sheep", "deer", "rat");
 Iterator<String> it = list.iterator();
 if (it.hasNext()) System.out.println(it.next());

Summary

There’s not much you have to memorize. The key facts are:

  • Call hasNext() in an if statement or while loop
  • Call next() once you know there is a next element
  • If the Iterator doesn’t use generics, you must cast unless you want Object

Practice Questions

Question 1

Which correctly fill in the blanks?


 List<String> list = Arrays.asList("a", "b", "c");
 Iterator<String> it = list.iterator();
 while (it._____()) {
   String name = it.______();
   System.out.println(name);
 }

A: hasNext, next

B: next, hasNext

C: The code does not compile with either A or B

D: The code throws an exception after being completed with A or B

Question 2

Which correctly fill in the blanks?


 List<String> list = Arrays.asList("a", "b", "c");
 Iterator it = list.iterator();
 while (it._____()) {
   String name = it.______();
   System.out.println(name);
 }

A: hasNext, next

B: next, hasNext

C: The code does not compile with either A or B

D: The code throws an exception after being completed with A or B

Question 3

Which correctly fill in the blanks?


 List list = Arrays.asList("a", "b", "c");
 Iterator<String> it = list.iterator();
 while (it._____()) {
   String name = it.______();
   System.out.println(name);
 }

A: hasNext, next

B: next, hasNext

C: The code does not compile with either A or B

D: The code throws an exception after being completed with A or B

The answers are posted here.