engage 2014 - JavaBlast

74
JavaBlast engage 2014 René Winkelmeyer midpoints GmbH

Transcript of engage 2014 - JavaBlast

Page 1: engage 2014 - JavaBlast

JavaBlast

engage 2014

René Winkelmeyer midpoints GmbH

Page 2: engage 2014 - JavaBlast

René Winkelmeyer Senior Consultant

midpoints GmbH http://www.midpoints.de IBM Advanced Business Partner IBM Design Partner Services

•  Notes / Domino Consulting •  E-Mail Management •  Mobile

Products •  IBM Notes Traveler planning & deployment •  mobile app development •  Domino based iOS Device Management •  Domino based “Dropbox” for Notes and iOS

About me

Page 3: engage 2014 - JavaBlast

René Winkelmeyer Senior Consultant

•  Skype

muenzpraeger •  Twitter

muenzpraeger •  LinkedIn

muenzpraeger •  Slideshare

muenzpraeger

•  Web http://blog.winkelmeyer.com http://www.midpoints.de

•  Mail [email protected] [email protected]

OpenNTF •  File Navigator •  Generic NSF View Widget for IBM Connections

About me

Page 4: engage 2014 - JavaBlast

4

What’s this session about?

§  This session is about Java and Eclipse.

§  The goal is to make your life as an developer easier.

§  Most of the content can be applied to Java in Domino and to Domino Designer.

§  The views are my own – yours may be different. ;-)

Page 5: engage 2014 - JavaBlast

Tip #1: Don’t return NULL values

§  Returning NULL from your own methods is a bad behavior.

§  Forces people to doublecheck for NULL and values.

§  Instead return something „empty“ or your own „NULL“.

Page 6: engage 2014 - JavaBlast

Tip #1: Don’t return NULL values

Page 7: engage 2014 - JavaBlast

7

Tip #2: Use the Eclipse Marketplace for IDE enhancements

§  Thousands of helpful (and sometimes not helpful) addons are available for Eclipse

§  Just go to the Eclipse Marketplace and search for your favorite term

Page 8: engage 2014 - JavaBlast

8

Tip #3: Style your Editor like you want

§  People have different opinions on which kind of text display is better (for their eyes)

§  Black text on white background

§  White text on black background

§  Colored text on white background

§  Colored text on black background

§  xxx text on xxx background

Page 9: engage 2014 - JavaBlast

9

Tip #3: Style your Editor like you want

§  The „Eclipse Color Theme“ plug-in comes to your rescue.

§  Different color codings (background, text etc.) for different editors within Eclipse

Page 10: engage 2014 - JavaBlast

10

Tip #3: Style your Editor like you want

§  Header

§  Content

Page 11: engage 2014 - JavaBlast

11

Tip #3: Style your Editor like you want

Page 12: engage 2014 - JavaBlast

12

Tip #4: Easy access to the files of your projects

§  „StartExplorer“ give you the capability to access the physical files of your Java project directly from within the IDE.

Page 13: engage 2014 - JavaBlast

13

Tip #4: Easy access to the files of your projects

§  Open shell at the file/folder location

§  Open Explorer/Finder/Nautilus etc at the file/folder location

§  Execute custom commands against the file/folder

Page 14: engage 2014 - JavaBlast

14

Tip #4: Easy access to the files of your projects

Page 15: engage 2014 - JavaBlast

15

Tip #5: Intelligent Code recommendation

§  Replace the built-in content assist with „Code Recommenders“ – and learn how others use and built code.

Page 16: engage 2014 - JavaBlast

16

Tip #5: Intelligent Code recommendation

§  „Favorites“ at the top of the new content assist show you what others have mostly used.

Page 17: engage 2014 - JavaBlast

17

Tip #5: Intelligent Code recommendation

Page 18: engage 2014 - JavaBlast

18

Tip #5: Intelligent Code recommendation

Page 19: engage 2014 - JavaBlast

19

Tip #6: Use meaningful names in your code

§  Use meaningful names – ‘nuff said.

Page 20: engage 2014 - JavaBlast

20

Tip #7: Ease code comment generation

§  Option 1: Write /** at the top of a method and press ENTER.

Page 21: engage 2014 - JavaBlast

21

Tip #7: Ease code comment generation

§  Option 2: Auto-generate comments for selected elements

Page 22: engage 2014 - JavaBlast

22

Tip #8: Don’t document your code for documentation purposes

§  Good documentation describes why the code is doing what is does – not what it‘s doing.

Page 23: engage 2014 - JavaBlast

23

Tip #8: Don’t document your code for documentation purposes

§  Good documentation describes why the code is doing what is does – not what it‘s doing.

Page 24: engage 2014 - JavaBlast

24

Tip #9: Code styling – for projects and workspaces

§  Having a similar pattern for „how code looks like“ makes it easier to read, understand and maintain.

§  That‘s even more essential when working in a team.

Page 25: engage 2014 - JavaBlast

25

Tip #9: Code styling – for projects and workspaces

Page 26: engage 2014 - JavaBlast

26

Tip #9: Code styling – for projects and workspaces

Page 27: engage 2014 - JavaBlast

27

Tip #9: Code styling – for projects and workspaces

Page 28: engage 2014 - JavaBlast

28

Tip #10: Awesome “Reflection”s

§  Reflection is the ability to make modifications at runtime by making use of Type Introspections.

§  i. e. it allows you to add a JAR at runtime even if it‘s not in the classpath

§  „setAccessible“ is for men, not for boys!

Page 29: engage 2014 - JavaBlast

29

Tip #11: Type-safe Enumerations

§  Enumerations (or short: enums) are a rock-solid alternative to the commonly used static int or String constants.

Page 30: engage 2014 - JavaBlast

30

Tip #11: Type-safe Enumerations

Page 31: engage 2014 - JavaBlast

31

Tip #11: Type-safe Enumerations

Page 32: engage 2014 - JavaBlast

32

Tip #11: Type-safe Enumerations

Page 33: engage 2014 - JavaBlast

33

Tip #12: Use Buffered streams for I/O operations

§  Use Buffered streams for I/O operations whenever possible.

§  Unbuffered streams

§  Read and write is handled by the OS directly, which may lead to heavy disk usage

§  Buffered streams

§  Read and write is handled in-memory

Page 34: engage 2014 - JavaBlast

34

Tip #12: Use Buffered streams for I/O operations

Page 35: engage 2014 - JavaBlast

35

Tip #13: Singleton – instance

§  Singletons are bad. Some people say. Others really like them.

§  The main use case for a Singleton is to have data available across classes. Think „global“.

Page 36: engage 2014 - JavaBlast

36

Tip #13: Singleton – instance

§  Instantiated at the first call. Really handy if you run multi-threaded or concurrent access against the same data.

Page 37: engage 2014 - JavaBlast

37

Tip #13: Singleton – instance

Page 38: engage 2014 - JavaBlast

38

Tip #14: The Builder pattern

§  A Builder gives you the capability to wrap complex objects into a fluent interface.

Page 39: engage 2014 - JavaBlast

39

Tip #14: The Builder pattern

Page 40: engage 2014 - JavaBlast

40

Tip #15: Serialize and Deserialize

§  Serialization allows you to store (serizalizable) Objects in a JVM-independent way.

§  It‘s a byte representation of the objects type and the objects data.

§  The object needs to implement java.io.Serializable.

Page 41: engage 2014 - JavaBlast

41

Tip #15: Serialize and Deserialize

Page 42: engage 2014 - JavaBlast

42

Tip #15: Serialize and Deserialize

Page 43: engage 2014 - JavaBlast

43

Tip #16: Find Your Bugs

§  Employ good coding practises (and find bad ones) using „FindBugs“ from the Eclipse Marketplace.

Page 44: engage 2014 - JavaBlast

44

Tip #16: Find Your Bugs

Page 45: engage 2014 - JavaBlast

45

Tip #16: Find Your Bugs

§  You‘ll see the output right within your IDE.

Page 46: engage 2014 - JavaBlast

46

Tip #16: Find Your Bugs

§  You‘ll see the output right within your IDE.

Page 47: engage 2014 - JavaBlast

47

Tip #17: Transform to HTML-escaped characters

§  Had ever the need to convert (special) characters to HTML encoded strings?

§  Several 3rd party libraries (i. e. Apache) are available for that.

§  Leverage the built-in capabilities. A „char“ is represented as a number. So it‘s an easy one to encode that one.

Page 48: engage 2014 - JavaBlast

48

Tip #17: Transform to HTML-escaped characters

Page 49: engage 2014 - JavaBlast

49

Tip #18: Pass „unlimited“ objects as method arguments

§  Pass „unlimited“ objects as method values just by adding „...“ to the end of the class name.

Page 50: engage 2014 - JavaBlast

50

Tip #19: Accessing localized ressources

§  If you localize your applications make your that you can easily access it by placing it in your package.

Page 51: engage 2014 - JavaBlast

51

Tip #20: Edit your properties properly escaped

§  Working with localization could be very interesting. Different charsets in different languages.

§  Those localized files are normally placed in files like „messages_nl.properties“, „messages_de.properties“ and so on.

Page 52: engage 2014 - JavaBlast

52

Tip #20: Edit your properties properly escaped

§  For a proper display they need to be converted to ASCII.

§  One easy way is to convert them via the built-in tool „native2ascii“. The binary is located within the /bin folder of your Java distribution.

Page 53: engage 2014 - JavaBlast

53

Tip #20: Edit your properties properly escaped

§  An alternative approach is to use the „Properties Editor“ plugin.

§  It converts the text to ASCII when you save the file!

Page 54: engage 2014 - JavaBlast

54

Tip #21: Use “finally” for cleaning up

§  „finally“ you can clean up.

§  Think about closing I/O connections, recycle Domino objects etc.

Page 55: engage 2014 - JavaBlast

55

Tip #21: Use “finally” for cleaning up

Page 56: engage 2014 - JavaBlast

56

Tip #22: Debugging is simple – just do it

Page 57: engage 2014 - JavaBlast

57

Tip #23: Debug Detail formatters give you value insights

§  Inspecting current object and variable values while debugging code is one of the big benefits using Eclipse.

§  Change your variables and/or issue commands/methods against them.

§  It applies also to Domino Java objects!

Page 58: engage 2014 - JavaBlast

58

Tip #23: Debug Detail formatters give you value insights

Page 59: engage 2014 - JavaBlast

59

Tip #23: Debug Detail formatters give you value insights

Page 60: engage 2014 - JavaBlast

60

Tip #24: Recycle, recycle, recycle

§  Recycling is important in Domino!

§  Recycling is important in Domino!

§  Recycling is important in Domino!

§  Recycling is important in Domino!

§  Recycling is important in Domino!

§  Recycling is important in Domino!

§  Recycling is important in Domino!

Page 61: engage 2014 - JavaBlast

61

Tip #24: Recycle, recycle, recycle

§  Free‘ing the Cpp-Handle is critical, as ressources are limited on the server.

§  Free‘ing the parent normally frees the children.

§  Keep your house clean, i. e. always recycle EmbeddedObjects.

Page 62: engage 2014 - JavaBlast

62

Tip #24: Recycle, recycle, recycle

§  Running a NSD gives you insights of the currently used backend handles.

§  If you‘re still on 8.5.2 => Upgrade!

Page 63: engage 2014 - JavaBlast

63

Tip #25: Exceptions are not for control-flow

§  Use Exceptions for stuff you can recover and for unexpected conditions.

Page 64: engage 2014 - JavaBlast

64

Tip #25: Exceptions are not for control-flow

Page 65: engage 2014 - JavaBlast

65

Tip #25: Exceptions are not for control-flow

Page 66: engage 2014 - JavaBlast

66

Tip #26: Typed vs. Un-Typed Collections

§  Typed collections make your life much more easier.

§  You see in the code what type it is.

§  No need for casting

§  Easier for looping (instead of using an iterator)

Page 67: engage 2014 - JavaBlast

67

Tip #26: Typed vs. Un-Typed Collections

Page 68: engage 2014 - JavaBlast

68

Tip #26: Typed vs. Un-Typed Collections

Page 69: engage 2014 - JavaBlast

69

Tip #27: Don’t concatenate too much

§  Even if it‘s convenient – try to avoid „too much“ method concatenation.

§  Makes your life a lot easier, especially during development and debugging.

Page 70: engage 2014 - JavaBlast

70

Tip #27: Don’t concatenate too much

Page 71: engage 2014 - JavaBlast

71

Tip #28: Accessible fields

§  Fields should always be private except for constants

§  Accessible fields cause tight coupling

§  They are corruptible

§  If a field needs to be accessed => use „Getter“ and „Setter“

Page 72: engage 2014 - JavaBlast

72

Tip #28: Accessible fields

Page 73: engage 2014 - JavaBlast

73

Tip #29: Keep code clean

§  Delete not-needed / „out-commented“ code

§  Your SCM takes care of the history.

Page 74: engage 2014 - JavaBlast

74

Thank you very much!