The document compares and contrasts the programming languages Java and C#. It outlines similarities and differences in their program structure, data types, operators, loops, arrays, strings, exception handling, namespaces/classes, constructors/destructors, objects, properties, structs, console I/O, and file I/O. Key differences include C# using namespaces instead of packages and optional destructors instead of finalize methods. Both support similar basic programming concepts but with some syntactic variations.
Slides from my PyCon 2011 talk, "Exhibition of Atrocity," a confessional of my sins against the Python programming language.
Abstract: http://us.pycon.org/2011/schedule/presentations/138/
Video: http://www.pycon.tv/#/video/49
Python's "batteries included" philosophy means that it comes with an astonishing amount of great stuff. On top of that, there's a vibrant world of third-party libraries that help make Python even more wonderful. We'll go on a breezy, example-filled tour through some of my favorites, from treasures in the standard library to great third-party packages that I don't think I could live without, and we'll touch on some of the fuzzier aspects of the Python culture that make it such a joy to be part of.
Slides from my PyCon 2011 talk, "Exhibition of Atrocity," a confessional of my sins against the Python programming language.
Abstract: http://us.pycon.org/2011/schedule/presentations/138/
Video: http://www.pycon.tv/#/video/49
Python's "batteries included" philosophy means that it comes with an astonishing amount of great stuff. On top of that, there's a vibrant world of third-party libraries that help make Python even more wonderful. We'll go on a breezy, example-filled tour through some of my favorites, from treasures in the standard library to great third-party packages that I don't think I could live without, and we'll touch on some of the fuzzier aspects of the Python culture that make it such a joy to be part of.
Python is an interpreted high-level general-purpose programming language. Its design philosophy emphasizes code readability with its use of significant indentation. Its language constructs as well as its object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects
Everybody is talking about ES6, but is anyone out there using it in production? Mango recently started adopting ES6 features that make our front-end code easier to write and maintain.
In this talk, I will explain why we decided to use ES6, how we started to use it in production (using npm, browserify and babel) and I'll explain what problems we found along the way and how we solved them.
Links:
https://getmango.com
https://getmango.com/blog/writing-es6-modules-with-6to5/
http://kangax.github.io/compat-table/
https://github.com/zloirock/core-js
https://github.com/mango/emitter
http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts
http://benmccormick.org/2015/04/07/es6-classes-and-backbone-js/
How to avoid Go gotchas - Ivan Daniluk - Codemotion Milan 2016Codemotion
One of the primary strengths of Go programming language is a built-in first-class support for concurrency. We're going to learn about it in a completely new way, using interactive 3D visualizations, which help us understand the complex but astonishing world of modern concurrent software. We'll see what’s happening inside the real code—from a simple “Hello, World” to real production-level high-loaded servers, and learn different approaches and concurrency patterns that are used for building concurrent pipelines and algorithms. And we'll do it all in 3D!
Big Data Day LA 2015 - Mongoose v/s Waterline: Battle of the ORM by Tim Fulme...Data Con LA
Mongo is swiftly becoming the default, general purpose database du jour. In green field Node.JS systems, Mongo is almost the default persistence mechanism. At the same time, going completely schema-less raises it's own issues.
Enter the NoSQL ORM solution. By encoding schema information in easily changeable JavaScript definitions, Node.JS systems can get the benefits of both worlds. High velocity change throughput, with just enough guardrails to keep things on the tracks.
Mongoose has traditionally been the go-to ORM package, providing lightweight schema definitions on top of Mongo. Waterline has recently come out of the Sails.JS project with some interesting innovations. In this presentation we compare and contrast the two packages through a few typical ORM use cases.
Swift is a new programming language introduced by Apple for iOS and Mac app development. It has the best of both C and Objective-C with speed, interactivity and modern conventions.
A short talk on what makes Functional Programming - and especially Haskell - different.
We'll take a quick overview of Haskell's features and coding style, and then work through a short but complete example of using it for a Real World problem.
http://lanyrd.com/2011/geekup-liverpool-may/sdykh/
My JSConf.eu talk about next-gen JavaScript metaprogramming features, starting with ES5's new Object APIs and then focusing on the forthcoming Proxy object, approved for the next ECMA-262 Edition. This is beautiful work from Tom Van Cutsem and Mark Miller, with Andreas Gal helping on the implementation front -- proxies are already shipping in Firefox 4 betas.
Apple's Swift has achieved the top place in Stack Overflow's "Most Loved" list of programming languages in its 2015 Developer Survey. Based on information gleaned from GitHub and Stack Overflow, analyst firm RedMonk has seen Swift's popularity ranking soar from 68 to 22 in an unprecedented 6 months.
The "Extreme Swift" event does not require advanced, or even any, knowledge of Swift. Learn about some of the more outrageous features of the language which help explain what the fuss is all about!
Never look at programming the same way again — even if you never end up writing a single line of Swift code in your life.
In this talk we contrast and compare the interface of the Java Bindings
with the development and design of the Scala bindings and interfaces, with
particular reference to the introduction of Scala language specific features
such as the use of Options and the Scala Actors model.
Python is an interpreted high-level general-purpose programming language. Its design philosophy emphasizes code readability with its use of significant indentation. Its language constructs as well as its object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects
Everybody is talking about ES6, but is anyone out there using it in production? Mango recently started adopting ES6 features that make our front-end code easier to write and maintain.
In this talk, I will explain why we decided to use ES6, how we started to use it in production (using npm, browserify and babel) and I'll explain what problems we found along the way and how we solved them.
Links:
https://getmango.com
https://getmango.com/blog/writing-es6-modules-with-6to5/
http://kangax.github.io/compat-table/
https://github.com/zloirock/core-js
https://github.com/mango/emitter
http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts
http://benmccormick.org/2015/04/07/es6-classes-and-backbone-js/
How to avoid Go gotchas - Ivan Daniluk - Codemotion Milan 2016Codemotion
One of the primary strengths of Go programming language is a built-in first-class support for concurrency. We're going to learn about it in a completely new way, using interactive 3D visualizations, which help us understand the complex but astonishing world of modern concurrent software. We'll see what’s happening inside the real code—from a simple “Hello, World” to real production-level high-loaded servers, and learn different approaches and concurrency patterns that are used for building concurrent pipelines and algorithms. And we'll do it all in 3D!
Big Data Day LA 2015 - Mongoose v/s Waterline: Battle of the ORM by Tim Fulme...Data Con LA
Mongo is swiftly becoming the default, general purpose database du jour. In green field Node.JS systems, Mongo is almost the default persistence mechanism. At the same time, going completely schema-less raises it's own issues.
Enter the NoSQL ORM solution. By encoding schema information in easily changeable JavaScript definitions, Node.JS systems can get the benefits of both worlds. High velocity change throughput, with just enough guardrails to keep things on the tracks.
Mongoose has traditionally been the go-to ORM package, providing lightweight schema definitions on top of Mongo. Waterline has recently come out of the Sails.JS project with some interesting innovations. In this presentation we compare and contrast the two packages through a few typical ORM use cases.
Swift is a new programming language introduced by Apple for iOS and Mac app development. It has the best of both C and Objective-C with speed, interactivity and modern conventions.
A short talk on what makes Functional Programming - and especially Haskell - different.
We'll take a quick overview of Haskell's features and coding style, and then work through a short but complete example of using it for a Real World problem.
http://lanyrd.com/2011/geekup-liverpool-may/sdykh/
My JSConf.eu talk about next-gen JavaScript metaprogramming features, starting with ES5's new Object APIs and then focusing on the forthcoming Proxy object, approved for the next ECMA-262 Edition. This is beautiful work from Tom Van Cutsem and Mark Miller, with Andreas Gal helping on the implementation front -- proxies are already shipping in Firefox 4 betas.
Apple's Swift has achieved the top place in Stack Overflow's "Most Loved" list of programming languages in its 2015 Developer Survey. Based on information gleaned from GitHub and Stack Overflow, analyst firm RedMonk has seen Swift's popularity ranking soar from 68 to 22 in an unprecedented 6 months.
The "Extreme Swift" event does not require advanced, or even any, knowledge of Swift. Learn about some of the more outrageous features of the language which help explain what the fuss is all about!
Never look at programming the same way again — even if you never end up writing a single line of Swift code in your life.
In this talk we contrast and compare the interface of the Java Bindings
with the development and design of the Scala bindings and interfaces, with
particular reference to the introduction of Scala language specific features
such as the use of Options and the Scala Actors model.
We are an IT Company that's develop website,software,android,iPhone application as well as provide professional training in different course like php training, android training, iPhone training, .net training in Gandhinagar.
C# is a object oriented programming language as well as modern programming Language. It is nothing but extension of C++. Its a simple and general purpose programming language for application development.
Java v/s .NET is an age old debate! We have compared both Java and .NET on parameters like technical performance and future scope. NIIT provides certification courses for both Java and .NET. View our presentation and choose which course to enrol for at NIIT!
Explaining ES6: JavaScript History and What is to ComeCory Forsyth
An overview of some of the history of JavaScript, how it became ECMAScript (and what Ecma is), as well as highlights of the new features and syntax in ES6 aka ES2015.
Originally presented to the New York Public Library on June 4 2015.
Ceylon is a new programming language for the JVM which was recently released on http://ceylon-lang.org with Eclipse based tooling available from day one.
This talk will introduce you to the goals and some of the features of the language while showing the features of the Eclipse based IDE.
Ceylon is a programming language for writing large programs in a team environment. The language is elegant, highly readable, extremely typesafe, and makes it easy to get things done. And it's easy to learn for programmers who are familiar with mainstream languages used in business computing. Ceylon has a full-featured Eclipse-based development environment, allowing developers to take best advantage of the powerful static type system. Programs written in Ceylon execute on the JVM.
Slides as they were used at EclipseCon 2012
Lors de cette présentation, nous apprendrons à créer des applications Web plus rapidement et avec moins d'erreurs en utilisant un langage de programmation puissant et amusant.
Agenda
- Installer TypeScript et configurer un nouveau projet.
- Tirer avantage des types de données.
- Développer en Objets avec TypeScript
- Ecrire de meilleures fonctions
- Retrouver vos données avec LINQ
- Programmer de manière asynchrone
- Bonnes pratiques
- Avantages et inconvénients des projets TypeScript
- Conclusion et Discussion
Are you stuck in the Java world? I’ll share my story about convincing my team and the client of the benefits of Kotlin. Furthermore I’ll delve into how we migrated an existing Java Android app, with 300k active users, to Kotlin. Even if you have never seen Kotlin before, come and see how you will create better apps with this modern and elegant language. At the end of this talk you’ll be able to convince your team / client why it’s a great to use Kotlin. The power of Kotlin can be leveraged everywhere you use Java, since it compiles to JVM bytecode. So even if you’re not an Android developer, check out this session to get acquainted with Kotlin! No excuses: switch to Kotlin :)
A talk about how Javascript developers can make better and less error prone code by adopting two practices: using type-checkers to validate types during the development process, using Flowtype as an example; and by applying some common clean code practices to make their code more readable.
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
Keynote at DIGIT West Expo, Glasgow on 29 May 2024.
Cheryl Hung, ochery.com
Sr Director, Infrastructure Ecosystem, Arm.
The key trends across hardware, cloud and open-source; exploring how these areas are likely to mature and develop over the short and long-term, and then considering how organisations can position themselves to adapt and thrive.
Welocme to ViralQR, your best QR code generator.ViralQR
Welcome to ViralQR, your best QR code generator available on the market!
At ViralQR, we design static and dynamic QR codes. Our mission is to make business operations easier and customer engagement more powerful through the use of QR technology. Be it a small-scale business or a huge enterprise, our easy-to-use platform provides multiple choices that can be tailored according to your company's branding and marketing strategies.
Our Vision
We are here to make the process of creating QR codes easy and smooth, thus enhancing customer interaction and making business more fluid. We very strongly believe in the ability of QR codes to change the world for businesses in their interaction with customers and are set on making that technology accessible and usable far and wide.
Our Achievements
Ever since its inception, we have successfully served many clients by offering QR codes in their marketing, service delivery, and collection of feedback across various industries. Our platform has been recognized for its ease of use and amazing features, which helped a business to make QR codes.
Our Services
At ViralQR, here is a comprehensive suite of services that caters to your very needs:
Static QR Codes: Create free static QR codes. These QR codes are able to store significant information such as URLs, vCards, plain text, emails and SMS, Wi-Fi credentials, and Bitcoin addresses.
Dynamic QR codes: These also have all the advanced features but are subscription-based. They can directly link to PDF files, images, micro-landing pages, social accounts, review forms, business pages, and applications. In addition, they can be branded with CTAs, frames, patterns, colors, and logos to enhance your branding.
Pricing and Packages
Additionally, there is a 14-day free offer to ViralQR, which is an exceptional opportunity for new users to take a feel of this platform. One can easily subscribe from there and experience the full dynamic of using QR codes. The subscription plans are not only meant for business; they are priced very flexibly so that literally every business could afford to benefit from our service.
Why choose us?
ViralQR will provide services for marketing, advertising, catering, retail, and the like. The QR codes can be posted on fliers, packaging, merchandise, and banners, as well as to substitute for cash and cards in a restaurant or coffee shop. With QR codes integrated into your business, improve customer engagement and streamline operations.
Comprehensive Analytics
Subscribers of ViralQR receive detailed analytics and tracking tools in light of having a view of the core values of QR code performance. Our analytics dashboard shows aggregate views and unique views, as well as detailed information about each impression, including time, device, browser, and estimated location by city and country.
So, thank you for choosing ViralQR; we have an offer of nothing but the best in terms of QR code services to meet business diversity!
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
91mobiles recently conducted a Smart TV Buyer Insights Survey in which we asked over 3,000 respondents about the TV they own, aspects they look at on a new TV, and their TV buying preferences.
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfPaige Cruz
Monitoring and observability aren’t traditionally found in software curriculums and many of us cobble this knowledge together from whatever vendor or ecosystem we were first introduced to and whatever is a part of your current company’s observability stack.
While the dev and ops silo continues to crumble….many organizations still relegate monitoring & observability as the purview of ops, infra and SRE teams. This is a mistake - achieving a highly observable system requires collaboration up and down the stack.
I, a former op, would like to extend an invitation to all application developers to join the observability party will share these foundational concepts to build on:
UiPath Test Automation using UiPath Test Suite series, part 4DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 4. In this session, we will cover Test Manager overview along with SAP heatmap.
The UiPath Test Manager overview with SAP heatmap webinar offers a concise yet comprehensive exploration of the role of a Test Manager within SAP environments, coupled with the utilization of heatmaps for effective testing strategies.
Participants will gain insights into the responsibilities, challenges, and best practices associated with test management in SAP projects. Additionally, the webinar delves into the significance of heatmaps as a visual aid for identifying testing priorities, areas of risk, and resource allocation within SAP landscapes. Through this session, attendees can expect to enhance their understanding of test management principles while learning practical approaches to optimize testing processes in SAP environments using heatmap visualization techniques
What will you get from this session?
1. Insights into SAP testing best practices
2. Heatmap utilization for testing
3. Optimization of testing processes
4. Demo
Topics covered:
Execution from the test manager
Orchestrator execution result
Defect reporting
SAP heatmap example with demo
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Albert Hoitingh
In this session I delve into the encryption technology used in Microsoft 365 and Microsoft Purview. Including the concepts of Customer Key and Double Key Encryption.
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
A presentation about the usage and availability of Varnish on Kubernetes. This talk explores the capabilities of Varnish caching and shows how to use the Varnish Helm chart to deploy it to Kubernetes.
This presentation was delivered at K8SUG Singapore. See https://feryn.eu/presentations/accelerate-your-kubernetes-clusters-with-varnish-caching-k8sug-singapore-28-2024 for more details.
3. Program Structure
• package hello;
• public class HelloWorld {
• public static void main(String[] args) {
• String name = "Java";
• // See if an argument was passed from the command
line
• if (args.length == 1)
• name = args[0];
• System.out.println("Hello, " + name + "!");
• }
• }
using System;
namespace Hello {
public class HelloWorld {
public static void Main(string[] args) {
string name = "C#";
// See if an argument was passed from the command line
if (args.Length == 1)
name = args[0];
Console.WriteLine("Hello, " + name + "!");
}
}
}
4. Comments
• // Single line
• /* Multiple
• line */
• /** Javadoc documentation
comments */
// Single line
/* Multiple
line */
/// XML comments on a single line
/** XML comments on multiple lines */
5. Data Types
•Value Types
• bool
• byte, sbyte
• char
• short, ushort, int, uint, long, ulong
• float, double, decimal
•structures, enumerations
•Reference Types
• object (superclass of all other classes)
• string
•arrays, classes, interfaces, delegates
•Convertions
•// int to string
• int x = 123;
• String y = x.ToString(); // y is "123"
•// string to int
• y = "456";
• x = int.Parse(y); // or x = Convert.ToInt32(y);
•// double to int
• double z = 3.5;
• x = (int) z; // x is 3 (truncates decimal)
Value Types
bool
byte, sbyte
char
short, ushort, int, uint, long, ulong
float, double, decimal
structures, enumerations
Reference Types
object (superclass of all other classes)
string
arrays, classes, interfaces, delegates
Convertions
// int to string
int x = 123;
String y = x.ToString(); // y is "123"
// string to int
y = "456";
x = int.Parse(y); // or x = Convert.ToInt32(y);
// double to int
double z = 3.5;
x = (int) z; // x is 3 (truncates decimal)
6. Constants
• // May be initialized in a
constructor
• final double PI = 3.14;
const double PI = 3.14;
// Can be set to a const or a variable. May be
initialized in a constructor.
readonly int MAX_HEIGHT = 9;
7. Enumerations
• enum Action {Start, Stop, Rewind, Forward};
• // Special type of class
• enum Status {
• Flunk(50), Pass(70), Excel(90);
• private final int value;
• Status(int value) { this.value = value; }
• public int value() { return value; }
• };
• Action a = Action.Stop;
• if (a != Action.Start)
• System.out.println(a); // Prints "Stop"
• Status s = Status.Pass;
• System.out.println(s.value()); // Prints "70"
enum Action {Start, Stop, Rewind, Forward};
enum Status {Flunk = 50, Pass = 70, Excel = 90};
No equivalent.
Action a = Action.Stop;
if (a != Action.Start)
Console.WriteLine(a); // Prints "Stop"
Status s = Status.Pass;
Console.WriteLine((int) s); // Prints "70"
9. Choices
•greeting = age < 20 ? "What's up?" : "Hello";
•if (x < y)
• System.out.println("greater");
•if (x != 100) {
• x *= 5;
• y *= 2;
• }
•else
• z *= 6;
•int selection = 2;
•switch (selection) { // Must be byte, short, int, char, or
enum
• case 1: x++; // Falls through to next case if no break
• case 2: y++; break;
• case 3: z++; break;
• default: other++;
• }
greeting = age < 20 ? "What's up?" : "Hello";
if (x < y)
Console.WriteLine("greater");
if (x != 100) {
x *= 5;
y *= 2;
}
else
z *= 6;
string color = "red";
switch (color) { // Can be any predefined type
case "red": r++; break; // break is mandatory; no fall-
through
case "blue": b++; break;
case "green": g++; break;
default: other++; break; // break necessary on default
}
10. Loops
•while (i < 10)
• i++;
•for (i = 2; i <= 10; i += 2)
• System.out.println(i);
•do
• i++;
•while (i < 10);
•for (int i : numArray) // foreach construct
• sum += i;
•// for loop can be used to iterate through any Collection
• import java.util.ArrayList;
• ArrayList<Object> list = new ArrayList<Object>();
• list.add(10); // boxing converts to instance of Integer
• list.add("Bisons");
• list.add(2.3); // boxing converts to instance of Double
•for (Object o : list)
• System.out.println(o);
while (i < 10)
i++;
for (i = 2; i <= 10; i += 2)
Console.WriteLine(i);
do
i++;
while (i < 10);
foreach (int i in numArray)
sum += i;
// foreach can be used to iterate through any collection
using System.Collections;
ArrayList list = new ArrayList();
list.Add(10);
list.Add("Bisons");
list.Add(2.3);
foreach (Object o in list)
Console.WriteLine(o);
11. Arrays
• int nums[] = {1, 2, 3}; or int[] nums = {1, 2, 3};
• for (int i = 0; i < nums.length; i++)
• System.out.println(nums[i]);
• String names[] = new String[5];
• names[0] = "David";
• float twoD[][] = new float[rows][cols];
• twoD[2][0] = 4.5;
• int[][] jagged = new int[5][];
• jagged[0] = new int[5];
• jagged[1] = new int[2];
• jagged[2] = new int[3];
• jagged[0][4] = 5;
int[] nums = {1, 2, 3};
for (int i = 0; i < nums.Length; i++)
Console.WriteLine(nums[i]);
string[] names = new string[5];
names[0] = "David";
float[,] twoD = new float[rows, cols];
twoD[2,0] = 4.5f;
int[][] jagged = new int[3][] {
new int[5], new int[2], new int[3] };
jagged[0][4] = 5;
12. Strings
•// String concatenation
•String school = "Harding ";
• school = school + "University"; // school is "Harding University"
•// String comparison
• String mascot = "Bisons";
• if (mascot == "Bisons") // Not the correct way to do string comparisons
• if (mascot.equals("Bisons")) // true
• if (mascot.equalsIgnoreCase("BISONS")) // true
• if (mascot.compareTo("Bisons") == 0) // true
•System.out.println(mascot.substring(2, 5)); // Prints "son"
•// My birthday: Oct 12, 1973
• java.util.Calendar c = new java.util.GregorianCalendar(1973, 10, 12);
• String s = String.format("My birthday: %1$tb %1$te, %1$tY", c);
•// Mutable string
•StringBuffer buffer = new StringBuffer("two ");
• buffer.append("three ");
• buffer.insert(0, "one ");
• buffer.replace(4, 7, "TWO");
• System.out.println(buffer); // Prints "one TWO three"
// String concatenation
string school = "Harding ";
school = school + "University"; // school is "Harding University"
// String comparison
string mascot = "Bisons";
if (mascot == "Bisons") // true
if (mascot.Equals("Bisons")) // true
if (mascot.ToUpper().Equals("BISONS")) // true
if (mascot.CompareTo("Bisons") == 0) // true
Console.WriteLine(mascot.Substring(2, 3)); // Prints "son"
// My birthday: Oct 12, 1973
DateTime dt = new DateTime(1973, 10, 12);
string s = "My birthday: " + dt.ToString("MMM dd, yyyy");
// Mutable string
System.Text.StringBuilder buffer = new System.Text.StringBuilder("two ");
buffer.Append("three ");
buffer.Insert(0, "one ");
buffer.Replace("two", "TWO");
Console.WriteLine(buffer); // Prints "one TWO three"
13. Exception Handling
• // Must be in a method that is declared to throw this
exception
• Exception ex = new Exception("Something is really
wrong.");
• throw ex;
• try {
• y = 0;
• x = 10 / y;
• } catch (Exception ex) {
• System.out.println(ex.getMessage());
• } finally {
• // Code that always gets executed
• }
Exception up = new Exception("Something is really wrong.");
throw up; // ha ha
try {
y = 0;
x = 10 / y;
} catch (Exception ex) { // Variable "ex" is optional
Console.WriteLine(ex.Message);
} finally {
// Code that always gets executed
}
14. Namespaces
• package harding.compsci.graphics;
• // Import single class
• import
harding.compsci.graphics.Rectangle
;
• // Import all classes
• import harding.compsci.graphics.*;
namespace Harding.Compsci.Graphics {
...
}
or
namespace Harding {
namespace Compsci {
namespace Graphics {
...
}
}
}
// Import single class
using Rectangle = Harding.CompSci.Graphics.Rectangle;
// Import all class
using Harding.Compsci.Graphics;
16. Constructors / Destructors
• class SuperHero {
• private int mPowerLevel;
• public SuperHero() {
• mPowerLevel = 0;
• }
• public SuperHero(int powerLevel) {
• this.mPowerLevel= powerLevel;
• }
• // No destructors, just override the finalize method
• protected void finalize() throws Throwable {
• super.finalize(); // Always call parent's finalizer
• }
• }
class SuperHero {
private int mPowerLevel;
public SuperHero() {
mPowerLevel = 0;
}
public SuperHero(int powerLevel) {
this.mPowerLevel= powerLevel;
}
~SuperHero() {
// Destructor code to free unmanaged resources.
// Implicitly creates a Finalize method.
}
}
17. Objects
• SuperHero hero = new SuperHero();
• hero.setName("SpamMan");
• hero.setPowerLevel(3);
• hero.Defend("Laura Jones");
• SuperHero.Rest(); // Calling static method
• SuperHero hero2 = hero; // Both refer to same object
• hero2.setName("WormWoman");
• System.out.println(hero.getName()); // Prints WormWoman
• hero = null; // Free the object
• if (hero == null)
• hero = new SuperHero();
• Object obj = new SuperHero();
• System.out.println("object's type: " + obj.getClass().toString());
• if (obj instanceof SuperHero)
• System.out.println("Is a SuperHero object.");
SuperHero hero = new SuperHero();
hero.Name = "SpamMan";
hero.PowerLevel = 3;
hero.Defend("Laura Jones");
SuperHero.Rest(); // Calling static method
SuperHero hero2 = hero; // Both refer to same object
hero2.Name = "WormWoman";
Console.WriteLine(hero.Name); // Prints WormWoman
hero = null ; // Free the object
if (hero == null)
hero = new SuperHero();
Object obj = new SuperHero();
Console.WriteLine("object's type: " + obj.GetType().ToString());
if (obj is SuperHero)
Console.WriteLine("Is a SuperHero object.");
18. Properties
• private int mSize;
• public int getSize() { return mSize; }
• public void setSize(int value) {
• if (value < 0)
• mSize = 0;
• else
• mSize = value;
• }
• int s = shoe.getSize();
• shoe.setSize(s+1);
private int mSize;
public int Size {
get { return mSize; }
set {
if (value < 0)
mSize = 0;
else
mSize = value;
}
}
shoe.Size++;
19. Structs
• No structs in Java. struct StudentRecord {
public string name;
public float gpa;
public StudentRecord(string name, float gpa) {
this.name = name;
this.gpa = gpa;
}
}
StudentRecord stu = new StudentRecord("Bob", 3.5f);
StudentRecord stu2 = stu;
stu2.name = "Sue";
Console.WriteLine(stu.name); // Prints "Bob"
Console.WriteLine(stu2.name); // Prints "Sue"
20. Console I/O
• java.io.DataInput in = new
java.io.DataInputStream(System.in);
• System.out.print("What is your name? ");
• String name = in.readLine();
• System.out.print("How old are you? ");
• int age = Integer.parseInt(in.readLine());
• System.out.println(name + " is " + age + "
years old.");
• int c = System.in.read(); // Read single
char
• System.out.println(c); // Prints 65 if
user enters "A"
• // The studio costs $499.00 for 3 months.
• System.out.printf("The %s costs $%.2f for
%d months.%n", "studio", 499.0, 3);
• // Today is 06/25/04
Console.Write("What's your name? ");
string name = Console.ReadLine();
Console.Write("How old are you? ");
int age = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("{0} is {1} years old.", name, age);
// or
Console.WriteLine(name + " is " + age + " years old.");
int c = Console.Read(); // Read single char
Console.WriteLine(c); // Prints 65 if user enters "A"
// The studio costs $499.00 for 3 months.
Console.WriteLine("The {0} costs {1:C} for {2} months.n", "studio", 499.0, 3);
// Today is 06/25/2004
Console.WriteLine("Today is " + DateTime.Now.ToShortDateString());
21. File I/O
•import java.io.*;
•// Character stream writing
•FileWriter writer = new FileWriter("c:myfile.txt");
• writer.write("Out to file.n");
• writer.close();
•// Character stream reading
•FileReader reader = new FileReader("c:myfile.txt");
•BufferedReader br = new BufferedReader(reader);
• String line = br.readLine();
• while (line != null) {
• System.out.println(line);
• line = br.readLine();
• }
• reader.close();
•// Binary stream writing
•FileOutputStream out = new FileOutputStream("c:myfile.dat");
• out.write("Text data".getBytes());
• out.write(123);
• out.close();
•// Binary stream reading
•FileInputStream in = new FileInputStream("c:myfile.dat");
• byte buff[] = new byte[9];
• in.read(buff, 0, 9); // Read first 9 bytes into buff
• String s = new String(buff);
• int num = in.read(); // Next is 123
• in.close();
using System.IO;
// Character stream writing
StreamWriter writer = File.CreateText("c:myfile.txt");
writer.WriteLine("Out to file.");
writer.Close();
// Character stream reading
StreamReader reader = File.OpenText("c:myfile.txt");
string line = reader.ReadLine();
while (line != null) {
Console.WriteLine(line);
line = reader.ReadLine();
}
reader.Close();
// Binary stream writing
BinaryWriter out = new BinaryWriter(File.OpenWrite("c:myfile.dat"));
out.Write("Text data");
out.Write(123);
out.Close();
// Binary stream reading
BinaryReader in = new BinaryReader(File.OpenRead("c:myfile.dat"));
string s = in.ReadString();
int num = in.ReadInt32();
in.Close();