SlideShare a Scribd company logo
1 of 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/

More Related Content

What's hot

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
 

What's hot (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
 

Viewers also liked (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 to 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 to 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
 

Recently uploaded

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 

Recently uploaded (20)

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 

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/