frc java5-8andeclipse

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

Upload: jeanne-boyarsky

Post on 02-Aug-2015

104 views

Category:

Technology


1 download

TRANSCRIPT

Intro to Java 5-8 and Eclipse

11/16/14Jeanne Boyarsky

Programming Mentor FRC Team 694

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

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

Pause for CommercialMy first book:

Installing Eclipse Eclipse Luna 4.4

+ plugins

https://www.eclipse.org/downloads/

Eclipse is used more “in the real world”

than NetBeans

FIRST recommends C/C++ edition. (I used the Java edition and things seem fine)

Eclipse Version Q&A Can I use an older version of Eclipse?

It will not support Java 8 syntax additions or the FRC plugins..

When is Eclipse released?

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)

Eclipse - Perspectives Eclipse has different “perspectives” (sets of views)

Java and Resource Git/Svn and Team Synchronization

Eclipse - Views Views are screen elements

Package explorer Problems Tasks – used for code with //TODO Console - output

To add:

Window > Show view > Console

Tip: Configure contents

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

Tip: Show hidden files

Filter

Uncheck

Ex: .classpath

Tip: Variables Built in: Use classpath variables for the FRC libraries so

no changes to project on different computers

Eclipse – Autocomplete Control + space

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

Creating a new project Just like NetBeans, create a new project

More Eclipse Create a class

Force a rebuild

Update the classpath

Look at errors

Sync package explorer with code

Compact list

Outline view

Running the Ant script Right click build.xml - Run As

Or run link up top

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

How to migrate NetBeans project? There isn't a generic way I recommend:

– Create a new Eclipse project

– Copy the source code from the NetBeans source directory

– Commit to version control

Installing Java Java Platform (JDK) 8

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

(Or)

Not the micro edition anymore!

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.

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)

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)

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

Java 5 – Enhanced for loop Which is easier to read/write?

Can use for array, ArrayList and more

Java 5 – Static imports Don't have to write Ports.X over and over and ...

Java 7 – Diamond Operator Less typing:

Java 7 - Underscores Make long numbers easier to read during the rush to

change code between matches:

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);

Java 7 – try with resources Which is easier to read/write?

Java 8 Lambdas and functional programming (way too much to

cover in one slide)

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())

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!

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

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/