SlideShare una empresa de Scribd logo
1 de 24
Beginning Java for .NET
developers
Why learn Java?
• Complement your developer skills
• Be able to develop Android apps
• Target Linux OS
Where do I get Java?
• Oracle (official vendor, acquirer of Sun)
• IBM (no Windows support – at least in
Nov.2013)
• OpenJDK (Ubuntu)
• many others
IDEs
•
•
•
•

Eclipse
Netbeans (Oracle)
IntelliJ IDEA (JetBrains, makers of ReSharper)
many others
Common features
•
•
•
•
•
•
•
•

Object-oriented
Compiled, not interpreted
Statically typed
Type safe
Runtime (JVM) – based (available on many platforms)
Garbage collected
Allows native interoperability
Runs on mobile devices (smartphones, tablets, even
feature-phones)
• JLS / CLS – multiple languages on the same platform
Similar projects and technologies
•
•
•
•
•
•
•

Hibernate – NHibernate
log4j – log4net
Play – ASP.NET MVC
JUnit – NUnit
JavaFX – WPF
Swing/AWT – Winforms
JSP/JSF – ASP.NET (Webforms)
Subtle and not-so-subtle differences
• Language differences
(calls, conventions, execution, syntactic
sugar, code organization, syntax)
• Platform differences (architecture, classsystem, execution, operations, data types and
others)
Language - Calling methods
•
•
•
•

No out or ref parameter modifiers
No optional parameters
No named parameters
params written as “…”
public void doSomething(Object… args) { … }

• No extension methods
Language - Coding conventions
• Methods are camelCased and not PascalCased
• The opening brace is to be put on the same line :
public void doSomething() {
}

• Interfaces are not prefixed with a capital I :
Throwable, Runnable etc.

• Enum values are all-uppercase
• Abbreviation words in compound names can be
all-caps : URLParser (as opposed to .NET’s
UrlParser)
Language - Code execution
• Switch allows fall-through by design
• Convenient multicatch statement :
try { … } catch(IOException | NetworkException e) { … }

• Override return in finally
• No #Ifdef
• Try-with-resources as using equivalent :
try(IOStream s = new IOStream()) { … }
Language – Convenience features
• No as feature. Test with instanceOf and then
cast
• No lambdas yet. Promised in Java 8. Use
anonymous inner classes
• Static method import. Like extensions
methods but the other way around.
import static com.something.Otherclass.someMethod;
…
someMethod(..);

• No explicit interface implementation
Language – Organization
• No nested packages in a single file.
namespace Outer
{
namespace Inner
{
…
}
}

• Only one public class in a .java file
• The public class name must match case-wise the
filename
• No partial classes
• No partial methods
Language – Syntax
• protected means ‘protected internal’

• implements or extends instead of colon (‘:’)
• No var facility
•

foreach syntax

: for(Type

variable : collection){…}

• instanceOf instead of is
• SomeClass.class instead of typeof(SomeClass)

• Annotations are prefixed with @ and not ‘[‘, ‘]’
• .. can also be applied to assignment statements
Language – Syntax (cont’d)
• No indexers

public int this[int index] { get { … } }

• No #regions
• Binary numeric literals :

int n217 = 0b11011001;

• Underscore allowed (and ignored) in numeric literals :
int cardNo = 1234_5678_9012_3456;

• The base class is called superclass, the derived class is
called subclass
• Calling the superclass constructor is done within the
constructor not outside, it is optional, but if done, must
be the first statement of the constructor
Language – data types
• Default access modifier (i.e. not specifying one)
means package (kind of internal), for methods
or fields.
• String must be written with capital S. Seems
irrelevant but it will be the most common typo.
• Interfaces can have static final fields (“constants”)
– before enums this was a way to simulate
enums.
• No operator overloading
• No implicit or explicit conversions can be defined
on types
Language – Enums
•
•
•
•
•
•
•

•
•
•

Reference type – like classes
Enums can have fields and constructor (though it must be private)
You can override methods. Typically toString()
Lazily created. Each enum value is instantiated at its first use.
Abstract methods, overridable in specific values
Allows inheritance. Although it has the semantic value of a
superset, not subset.
valueOf(String name) instead of Enum.Parse
values() for enumerating all values
name() – gets the enum value name; typically toString() does the
same but the latter can get overriden
ordinal() – gets the order index of the value
Platform – Architecture
• @Override annotation is optional. Overload instead

•
•
•

•

of override can occur.
Cloning is awkard, non-intuitive. Cloneable marker
interface and protected clone().
No static classes. Make it final, create a private
constructor and throw an exception inside the
constructor
Return type covariance : Override a method and return
a subclass of the original method’s return type class.
Typical use : overriding clone().
You can alter a collection while iterating it without
getting an exception, but only if done through the
current iterator.
Platform – Classes
• A method is virtual by default – not like in .NET where
it’s sealed (final) by default. This is how Hibernate
strived and NHibernate struggles.
• Generics are implemented using type erasure. No
List<primitive> and no arrays of generic types.
• No (known) way to create a generic type, by
reflection, at runtime.
• Inner classes have outer class reference by default.
Except static inner classes.
• No method generators. i.e. yield
• Type inference by ‘diamond’ style constructors.
List<Integer> = new ArrayList<>();
Platform – Execution
• Checked exceptions. Each method must
declare what exceptions it can throw or catch
them.
• RuntimeExceptions are exempt
• Errors are not catchable
Platform – Convenience features
• No properties
• No events
• Three ways to simulate events :
– Nested anonymous classes
– Implementing interfaces and passing this
– Lambdas (promised in Java 8)
Platform – Operations
• Primitives have reference-types peers (wrappers)
• Do not confuse them to their primitive
counterparts. == operator will compare instances
instead of values
• Strings also should not be compared with ==
operator. Although there is string interning this
will usually fail you
• No checked mode. Numeric wrap-around always.
Platform – Data types
•
•
•
•

No unsigned numeric data types
No multi-dimensional arrays
No structs or other user-defined value-types
No dynamic infrastructure. Only in non-Java
languages compiled to bytecode.
• The primitives are not part of the type
hierarchy. Only their wrappers are.
Platform – others
• Upon deployment desktop apps don’t have an
EXE or other prepared entry point, executable
file
• The Garbage Collector does not have a
(separate) Large Object Heap, nor its
associated issues (fragmentation)
Further reading
• Enums : http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html
• JLS : http://docs.oracle.com/javase/specs/
• Java 8 Release date : http://openjdk.java.net/projects/jdk8/

Más contenido relacionado

La actualidad más candente

2CPP04 - Objects and Classes
2CPP04 - Objects and Classes2CPP04 - Objects and Classes
2CPP04 - Objects and ClassesMichael Heron
 
Introduction to Kotlin for Android developers
Introduction to Kotlin for Android developersIntroduction to Kotlin for Android developers
Introduction to Kotlin for Android developersMohamed Wael
 
10 Things I Hate About Scala
10 Things I Hate About Scala10 Things I Hate About Scala
10 Things I Hate About ScalaMeir Maor
 
Scala - the good, the bad and the very ugly
Scala - the good, the bad and the very uglyScala - the good, the bad and the very ugly
Scala - the good, the bad and the very uglyBozhidar Bozhanov
 
Comparing Golang and understanding Java Value Types
Comparing Golang and understanding Java Value TypesComparing Golang and understanding Java Value Types
Comparing Golang and understanding Java Value TypesPéter Verhás
 
Lock-free algorithms for Kotlin Coroutines
Lock-free algorithms for Kotlin CoroutinesLock-free algorithms for Kotlin Coroutines
Lock-free algorithms for Kotlin CoroutinesRoman Elizarov
 
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!scalaconfjp
 
Code reviews
Code reviewsCode reviews
Code reviewsRoger Xia
 
“Insulin” for Scala’s Syntactic Diabetes
“Insulin” for Scala’s Syntactic Diabetes“Insulin” for Scala’s Syntactic Diabetes
“Insulin” for Scala’s Syntactic DiabetesTzach Zohar
 
Python introduction
Python introductionPython introduction
Python introductionRoger Xia
 
Why Scala for Web 2.0?
Why Scala for Web 2.0?Why Scala for Web 2.0?
Why Scala for Web 2.0?Alex Payne
 
Reviewing CPAN modules
Reviewing CPAN modulesReviewing CPAN modules
Reviewing CPAN modulesneilbowers
 
Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersMiles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersSkills Matter
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8LivePerson
 
C# 6.0 - DotNetNotts
C# 6.0 - DotNetNottsC# 6.0 - DotNetNotts
C# 6.0 - DotNetNottscitizenmatt
 
A Static Type Analyzer of Untyped Ruby Code for Ruby 3
A Static Type Analyzer of Untyped Ruby Code for Ruby 3A Static Type Analyzer of Untyped Ruby Code for Ruby 3
A Static Type Analyzer of Untyped Ruby Code for Ruby 3mametter
 

La actualidad más candente (20)

Scala’s implicits
Scala’s implicitsScala’s implicits
Scala’s implicits
 
2CPP04 - Objects and Classes
2CPP04 - Objects and Classes2CPP04 - Objects and Classes
2CPP04 - Objects and Classes
 
Introduction to Kotlin for Android developers
Introduction to Kotlin for Android developersIntroduction to Kotlin for Android developers
Introduction to Kotlin for Android developers
 
java introduction
java introductionjava introduction
java introduction
 
10 Things I Hate About Scala
10 Things I Hate About Scala10 Things I Hate About Scala
10 Things I Hate About Scala
 
Scala - the good, the bad and the very ugly
Scala - the good, the bad and the very uglyScala - the good, the bad and the very ugly
Scala - the good, the bad and the very ugly
 
Comparing Golang and understanding Java Value Types
Comparing Golang and understanding Java Value TypesComparing Golang and understanding Java Value Types
Comparing Golang and understanding Java Value Types
 
C Sharp Course 101.5
C Sharp Course 101.5C Sharp Course 101.5
C Sharp Course 101.5
 
Lock-free algorithms for Kotlin Coroutines
Lock-free algorithms for Kotlin CoroutinesLock-free algorithms for Kotlin Coroutines
Lock-free algorithms for Kotlin Coroutines
 
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
 
Code reviews
Code reviewsCode reviews
Code reviews
 
“Insulin” for Scala’s Syntactic Diabetes
“Insulin” for Scala’s Syntactic Diabetes“Insulin” for Scala’s Syntactic Diabetes
“Insulin” for Scala’s Syntactic Diabetes
 
Python introduction
Python introductionPython introduction
Python introduction
 
Why Scala for Web 2.0?
Why Scala for Web 2.0?Why Scala for Web 2.0?
Why Scala for Web 2.0?
 
Reviewing CPAN modules
Reviewing CPAN modulesReviewing CPAN modules
Reviewing CPAN modules
 
Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersMiles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java Developers
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
 
C# 6.0 - DotNetNotts
C# 6.0 - DotNetNottsC# 6.0 - DotNetNotts
C# 6.0 - DotNetNotts
 
A Static Type Analyzer of Untyped Ruby Code for Ruby 3
A Static Type Analyzer of Untyped Ruby Code for Ruby 3A Static Type Analyzer of Untyped Ruby Code for Ruby 3
A Static Type Analyzer of Untyped Ruby Code for Ruby 3
 
AngularConf2015
AngularConf2015AngularConf2015
AngularConf2015
 

Destacado (20)

Scala for C# Developers
Scala for C# DevelopersScala for C# Developers
Scala for C# Developers
 
Python basic
Python basicPython basic
Python basic
 
Dot net guide for beginner
Dot net guide for beginner Dot net guide for beginner
Dot net guide for beginner
 
C++ to java
C++ to javaC++ to java
C++ to java
 
3rd june
3rd june3rd june
3rd june
 
C sharp
C sharpC sharp
C sharp
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
A comparison between C# and Java
A comparison between C# and JavaA comparison between C# and Java
A comparison between C# and Java
 
Microsoft C# programming basics
Microsoft C# programming basics  Microsoft C# programming basics
Microsoft C# programming basics
 
java vs C#
java vs C#java vs C#
java vs C#
 
2.overview of c#
2.overview of c#2.overview of c#
2.overview of c#
 
Difference between C++ and Java
Difference between C++ and JavaDifference between C++ and Java
Difference between C++ and Java
 
C sharp
C sharpC sharp
C sharp
 
Basics of c# by sabir
Basics of c# by sabirBasics of c# by sabir
Basics of c# by sabir
 
C vs c++
C vs c++C vs c++
C vs c++
 
ASP.NET Session 1
ASP.NET Session 1ASP.NET Session 1
ASP.NET Session 1
 
Java v/s .NET - Which is Better?
Java v/s .NET - Which is Better?Java v/s .NET - Which is Better?
Java v/s .NET - Which is Better?
 
Java script basic
Java script basicJava script basic
Java script basic
 
C# basics
C# basicsC# basics
C# basics
 
Python overview
Python   overviewPython   overview
Python overview
 

Similar a Beginning Java for .NET developers

Java Closures
Java ClosuresJava Closures
Java ClosuresBen Evans
 
Rust All Hands Winter 2011
Rust All Hands Winter 2011Rust All Hands Winter 2011
Rust All Hands Winter 2011Patrick Walton
 
Functional Programming In Jdk8
Functional Programming In Jdk8 Functional Programming In Jdk8
Functional Programming In Jdk8 Bansilal Haudakari
 
Basic info on java intro
Basic info on java introBasic info on java intro
Basic info on java introkabirmahlotra
 
Basic info on java intro
Basic info on java introBasic info on java intro
Basic info on java introkabirmahlotra
 
Java SpringMVC SpringBOOT (Divergent).ppt
Java SpringMVC SpringBOOT (Divergent).pptJava SpringMVC SpringBOOT (Divergent).ppt
Java SpringMVC SpringBOOT (Divergent).pptAayush Chimaniya
 
Lambda Expressions Java 8 Features usage
Lambda Expressions  Java 8 Features usageLambda Expressions  Java 8 Features usage
Lambda Expressions Java 8 Features usageAsmaShaikh478737
 
Unit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rdUnit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rdprat0ham
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryPray Desai
 
Playing with Java Classes and Bytecode
Playing with Java Classes and BytecodePlaying with Java Classes and Bytecode
Playing with Java Classes and BytecodeYoav Avrahami
 
Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)Ryan Cuprak
 

Similar a Beginning Java for .NET developers (20)

Java and the JVM
Java and the JVMJava and the JVM
Java and the JVM
 
Java Closures
Java ClosuresJava Closures
Java Closures
 
Rust All Hands Winter 2011
Rust All Hands Winter 2011Rust All Hands Winter 2011
Rust All Hands Winter 2011
 
Functional Programming In Jdk8
Functional Programming In Jdk8 Functional Programming In Jdk8
Functional Programming In Jdk8
 
Basic info on java intro
Basic info on java introBasic info on java intro
Basic info on java intro
 
Basic info on java intro
Basic info on java introBasic info on java intro
Basic info on java intro
 
Java SpringMVC SpringBOOT (Divergent).ppt
Java SpringMVC SpringBOOT (Divergent).pptJava SpringMVC SpringBOOT (Divergent).ppt
Java SpringMVC SpringBOOT (Divergent).ppt
 
Lambda Expressions Java 8 Features usage
Lambda Expressions  Java 8 Features usageLambda Expressions  Java 8 Features usage
Lambda Expressions Java 8 Features usage
 
Unit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rdUnit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rd
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 
Ruby basics
Ruby basicsRuby basics
Ruby basics
 
Java
JavaJava
Java
 
oop unit1.pptx
oop unit1.pptxoop unit1.pptx
oop unit1.pptx
 
CS8392 OOP
CS8392 OOPCS8392 OOP
CS8392 OOP
 
Should i Go there
Should i Go thereShould i Go there
Should i Go there
 
Module 1.pptx
Module 1.pptxModule 1.pptx
Module 1.pptx
 
Playing with Java Classes and Bytecode
Playing with Java Classes and BytecodePlaying with Java Classes and Bytecode
Playing with Java Classes and Bytecode
 
Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)
 
java slides
java slidesjava slides
java slides
 
Cse java
Cse javaCse java
Cse java
 

Último

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 

Último (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

Beginning Java for .NET developers

  • 1. Beginning Java for .NET developers
  • 2. Why learn Java? • Complement your developer skills • Be able to develop Android apps • Target Linux OS
  • 3. Where do I get Java? • Oracle (official vendor, acquirer of Sun) • IBM (no Windows support – at least in Nov.2013) • OpenJDK (Ubuntu) • many others
  • 4. IDEs • • • • Eclipse Netbeans (Oracle) IntelliJ IDEA (JetBrains, makers of ReSharper) many others
  • 5. Common features • • • • • • • • Object-oriented Compiled, not interpreted Statically typed Type safe Runtime (JVM) – based (available on many platforms) Garbage collected Allows native interoperability Runs on mobile devices (smartphones, tablets, even feature-phones) • JLS / CLS – multiple languages on the same platform
  • 6. Similar projects and technologies • • • • • • • Hibernate – NHibernate log4j – log4net Play – ASP.NET MVC JUnit – NUnit JavaFX – WPF Swing/AWT – Winforms JSP/JSF – ASP.NET (Webforms)
  • 7. Subtle and not-so-subtle differences • Language differences (calls, conventions, execution, syntactic sugar, code organization, syntax) • Platform differences (architecture, classsystem, execution, operations, data types and others)
  • 8. Language - Calling methods • • • • No out or ref parameter modifiers No optional parameters No named parameters params written as “…” public void doSomething(Object… args) { … } • No extension methods
  • 9. Language - Coding conventions • Methods are camelCased and not PascalCased • The opening brace is to be put on the same line : public void doSomething() { } • Interfaces are not prefixed with a capital I : Throwable, Runnable etc. • Enum values are all-uppercase • Abbreviation words in compound names can be all-caps : URLParser (as opposed to .NET’s UrlParser)
  • 10. Language - Code execution • Switch allows fall-through by design • Convenient multicatch statement : try { … } catch(IOException | NetworkException e) { … } • Override return in finally • No #Ifdef • Try-with-resources as using equivalent : try(IOStream s = new IOStream()) { … }
  • 11. Language – Convenience features • No as feature. Test with instanceOf and then cast • No lambdas yet. Promised in Java 8. Use anonymous inner classes • Static method import. Like extensions methods but the other way around. import static com.something.Otherclass.someMethod; … someMethod(..); • No explicit interface implementation
  • 12. Language – Organization • No nested packages in a single file. namespace Outer { namespace Inner { … } } • Only one public class in a .java file • The public class name must match case-wise the filename • No partial classes • No partial methods
  • 13. Language – Syntax • protected means ‘protected internal’ • implements or extends instead of colon (‘:’) • No var facility • foreach syntax : for(Type variable : collection){…} • instanceOf instead of is • SomeClass.class instead of typeof(SomeClass) • Annotations are prefixed with @ and not ‘[‘, ‘]’ • .. can also be applied to assignment statements
  • 14. Language – Syntax (cont’d) • No indexers public int this[int index] { get { … } } • No #regions • Binary numeric literals : int n217 = 0b11011001; • Underscore allowed (and ignored) in numeric literals : int cardNo = 1234_5678_9012_3456; • The base class is called superclass, the derived class is called subclass • Calling the superclass constructor is done within the constructor not outside, it is optional, but if done, must be the first statement of the constructor
  • 15. Language – data types • Default access modifier (i.e. not specifying one) means package (kind of internal), for methods or fields. • String must be written with capital S. Seems irrelevant but it will be the most common typo. • Interfaces can have static final fields (“constants”) – before enums this was a way to simulate enums. • No operator overloading • No implicit or explicit conversions can be defined on types
  • 16. Language – Enums • • • • • • • • • • Reference type – like classes Enums can have fields and constructor (though it must be private) You can override methods. Typically toString() Lazily created. Each enum value is instantiated at its first use. Abstract methods, overridable in specific values Allows inheritance. Although it has the semantic value of a superset, not subset. valueOf(String name) instead of Enum.Parse values() for enumerating all values name() – gets the enum value name; typically toString() does the same but the latter can get overriden ordinal() – gets the order index of the value
  • 17. Platform – Architecture • @Override annotation is optional. Overload instead • • • • of override can occur. Cloning is awkard, non-intuitive. Cloneable marker interface and protected clone(). No static classes. Make it final, create a private constructor and throw an exception inside the constructor Return type covariance : Override a method and return a subclass of the original method’s return type class. Typical use : overriding clone(). You can alter a collection while iterating it without getting an exception, but only if done through the current iterator.
  • 18. Platform – Classes • A method is virtual by default – not like in .NET where it’s sealed (final) by default. This is how Hibernate strived and NHibernate struggles. • Generics are implemented using type erasure. No List<primitive> and no arrays of generic types. • No (known) way to create a generic type, by reflection, at runtime. • Inner classes have outer class reference by default. Except static inner classes. • No method generators. i.e. yield • Type inference by ‘diamond’ style constructors. List<Integer> = new ArrayList<>();
  • 19. Platform – Execution • Checked exceptions. Each method must declare what exceptions it can throw or catch them. • RuntimeExceptions are exempt • Errors are not catchable
  • 20. Platform – Convenience features • No properties • No events • Three ways to simulate events : – Nested anonymous classes – Implementing interfaces and passing this – Lambdas (promised in Java 8)
  • 21. Platform – Operations • Primitives have reference-types peers (wrappers) • Do not confuse them to their primitive counterparts. == operator will compare instances instead of values • Strings also should not be compared with == operator. Although there is string interning this will usually fail you • No checked mode. Numeric wrap-around always.
  • 22. Platform – Data types • • • • No unsigned numeric data types No multi-dimensional arrays No structs or other user-defined value-types No dynamic infrastructure. Only in non-Java languages compiled to bytecode. • The primitives are not part of the type hierarchy. Only their wrappers are.
  • 23. Platform – others • Upon deployment desktop apps don’t have an EXE or other prepared entry point, executable file • The Garbage Collector does not have a (separate) Large Object Heap, nor its associated issues (fragmentation)
  • 24. Further reading • Enums : http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html • JLS : http://docs.oracle.com/javase/specs/ • Java 8 Release date : http://openjdk.java.net/projects/jdk8/