32
Intro to Java 5-8 and Eclipse 6/8/14 Jeanne Boyarsky Programming Mentor FRC Team 694 Twitter @jeanneboyarsky Blog: http://www.selikoff.net Moderator on Java forums at: http://www.coderanch.com

Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Embed Size (px)

DESCRIPTION

FRC (FIRST Robotics Challenge) is switching from Java ME 1.4 to Java SE 8 along with switching from NetBeans to Eclipse for the 2014-2015 school year. I gave this presentation to representatives from teams 2601 (Townsend Harris) and 694 (Stuyvesant) today. Team 2601 recorded my presentation which is available on youtube (https://www.youtube.com/watch?v=AgreKkRjFgU&feature=youtu.be) and at the end of my presentation on slideshare.

Citation preview

Page 1: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Intro to Java 5-8 and Eclipse

6/8/14Jeanne Boyarsky

Programming Mentor FRC Team 694

Twitter @jeanneboyarskyBlog: http://www.selikoff.net

Moderator on Java forums at: http://www.coderanch.com

Page 2: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Java – “New” Features

This presentation is not a complete list.

Features most likely needed for FRC programming.

Includes:

– Non-micro APIs from Java 1.4 (and below)

– Java 5 new features

– Java 7 new features

– Java 8 new features

– (Java 6 didn't have much)

Page 3: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Java 1.4 non-Micro APIs

java.util.ArrayList – like an array, but grows dynamically (faster than a Vector)

java.lang.Math – more methods

java.util.Properties – read file in format key=value (example in Java 7 section)

Page 4: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Java 5 – Generics/Autoboxing

Generics – you specify the type of the ArrayList and the compiler tells you if you use it wrong

Autoboxing – Java converts primitives (int, double, etc) to Objects and back for you

Page 5: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Java 5 – Enhanced for loop

Which is easier to read/write?

Can use for array, ArrayList and more

Page 6: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Java 5 – Static imports

Don't have to write Ports.X over and over and ...

Page 7: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Java 7 – Diamond Operator

Less typing:

Page 8: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Java 7 - Underscores

Make long numbers easier to read during the rush to change code between matches:

Page 9: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Java 7 – Reading a file

NIO.2 makes reading a file (or network connection or the like) easier.

Also, now that we are on Java Standard Edition you can use open source APIs such ashttp://commons.apache.org/proper/commons-io/Which lets you code:String s = FileUtils.readFileToString(file);

Page 10: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Java 7 – try with resources

Which is easier to read/write?

Page 11: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Java 8

Lambdas and functional programming (way too much to cover in one slide)

Will likely not work with FRC APIs at least in 2015

Consider whether you want to use this style of programming when training your new team members.

Like Groovy – might be less clear at first.

Examples:

new Thread(() -> System.out.println(“foo”))

words.sort ((a,b) -> a.length() – b.length())

Page 12: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Multi-threading

Remember we have 2 CPUs now.

What can the second one do?

– Vision

– Logging

– Long running calculations

– Poll a sensor until some event happens

– Use your imagination!

Page 13: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Installing Java

Java Platform (JDK) 8

http://www.oracle.com/technetwork/java/javase/downloads/index.html

(Or)

Not the micro edition anymore!

Page 14: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Java Version Q&A

Why doesn't Java know how to count? The versions go 1.1, 1.2, 1.3, 1.4, 5, 6, 7, 8

Blame marketing!

What's the difference between Java Micro Edition (used by FRC until 2014) and the “small memory” version (used by FRC starting in 2015)?

Java Micro Edition didn't have a lot of the built in Java functions that you can now use.

Page 15: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Installing Eclipse

Eclipse Luna 4.4

https://www.eclipse.org/downloads/ (after 6/25/14)

https://www.eclipse.org/downloads/index-developer.php (release candidate if trying before 6/25/14)

Eclipse is used more“in the real world”

than NetBeans

Either the Eclipse Standard or Eclipse IDE for Java Developers is ok.Standard uses less memory and has everything we need for FIRST

Page 16: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Eclipse Version Q&A

Can I use an older version of Eclipse?

Yes, but it will not support Java 8 syntax additions.

What happens on 6/25/14?

Eclipse releases come out on the fourth Wednesday of June.

Release Name Version Java supported

June 2012 Juno 4.2 Java 6 (also known as 1.6)

June 2013 Kepler 4.3 Java 7 (also known as 1.7)

June 2014 Luna 4.4 Java 8 (also known as 1.8)

Page 17: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Eclipse - Perspectives

Eclipse has different “perspectives” (sets of views)

Java and Resource

Git/Svn and Team Synchronization

FRC? (don't know if will be in 2015 plugin)

Page 18: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Eclipse - Views

Views are screen elements

Package explorer

Problems

Tasks – used for code with //TODO

Console - output

To add:

Window > Show view > Console

Page 19: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Tip: Configure contents

Page 20: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Tip: Save launch configuration

Run as > ___ …. lets you enter options

On common tab can save those options

Can even put them in SVN/Git because just a file

Page 21: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Tip: Variables

Use a classpath variable for the FRC libraries so no changes to project on different computers

Page 22: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Eclipse – Autocomplete

Control + space

Page 23: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Warnings about FRC Eclipse plugin

This is NOT the official plugin we will use in the 2014-2015 season.

It is the experimental version from 2011.

I don't recommend installing it; this is just to get an idea of the process

Page 24: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Installing the FRC Eclipse Plugin

Help > Install New Software

Enter URL http://first.wpi.edu/FRC/java/eclipse/update/

Click add button

Give it a name. I used “FRC-old” so I remember to uninstall it before the season starts.

Check FRC box

Click next/accept license/next/finish. Restart Eclipse when finishes download (This step uses the internet to download the plugin)

Page 25: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse
Page 26: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Configuring FRC Eclipse Plugin

Enter your team number in Eclipse global preferences

Windows > Preferences on Windows/Linux

Eclipse > Preferences on Mac

Note difference between global and project preferences

Page 27: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Creating a new project

Just like NetBeans, create a new project

Page 28: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Creating a new component

Right click where you want to add something

Page 29: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Running the Ant script

Run As > FRC …

Note: Eclipse projects do not build using Ant automatically, they have a .classpath file for the classpath

Page 30: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

How to migrate NetBeans project?

There isn't a generic way

I recommend:

– Create a new Eclipse FRC project

– Copy the source code from the NetBeans source directory

Page 31: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

Questions

About Java or Eclipse:

– Friendly forums for those new (or not new) to Java

– http://www.coderanch.com

For FRC specific questions:

– After the 2014-2015 plugins launch

– http://www.chiefdelphi.com

Page 32: Get ready for FRC 2015: Intro to Java 5 through 8 updates and Eclipse

References

Blog posts from Championships:

http://www.selikoff.net/2014/04/25/first-wpilib-in-2015/

How to get around the problem launching Eclipse on a Mac:

http://www.selikoff.net/2013/06/29/eclipse-kepler-4-3-mac/

Old plugin docs:

https://subversion.assembla.com/svn/blue-cheese/branches/2012/docs/Tutorials/FRCEclipsePluginSetup.pdf