Java Programming: Features, Runtime Environment and Projects Analysis
VerifiedAdded on 2020/01/28
|24
|6942
|313
Report
AI Summary
This report provides a detailed analysis of Java programming, beginning with an overview of its core features, including simplicity, security, portability, object-oriented capabilities, robustness, multithreading support, architecture-neutrality, interpretation, high performance, distribution, and dynamic behavior. The report then explores the Java Runtime Environment (JRE), its components, and its environmental flexibility, contrasting it with other programming environments. Several significant Java projects are examined, including JUnit, Eclipse, Spring, Solr, Hudson/Jenkins, Hadoop, and Android, highlighting their impact and contributions to the Java ecosystem. The report also presents a real-time problem and solution using Java, specifically a simplified Blackjack game, explaining the game's logic, rules, and implementation. This comprehensive overview aims to provide a thorough understanding of Java's capabilities and applications.

JAVA PROGRAMMING AND ITS BENEFITS
SECTION1
1.0 Features of Java Programming Language
A. Simple
• Java is Easy to compose and more coherent and eye getting.
• Java has a compact, strong arrangement of elements that makes it simple
to learn and utilize.
• Most of the ideas are drew from C++ in this manner making Java learning
less difficult Y. (Daniel Liang, 2012).
B. Secure
• Java program can't hurt other framework, in this way making it secure.
• Java gives a protected method for making Internet applications.
• Java gives secure approach to get to web applications
(http://www.c4learn.com/java/java-qualities highlights/, April 2016).
C. Portable
Java programs can execute in any environment for which there is a Java run-time
system-JVM (http://www.c4learn.com/java/java-characteristics-features/, April
2016).
Java programs can be run on any platform (Linux, Window, Mac)
Java programs can be transferred over World Wide Web (e.g applets)
D. Object-oriented
• Java writing computer programs is article arranged programming dialect.
• Like C++ java gives the vast majority of the item situated components (Daniel
Liang, 2012).
• Java is immaculate OOP. Dialect. (While C++ is semi object situated)
E. Robust
Java supports mistake free programming by being entirely written and
performing run-time checks.
F. Multithreaded
• Java gives incorporated backing to multithreaded programming (Daniel
Liang, 2012).
• Architecture-nonpartisan:
• Java is not attached to a particular machine or working framework design.
SECTION1
1.0 Features of Java Programming Language
A. Simple
• Java is Easy to compose and more coherent and eye getting.
• Java has a compact, strong arrangement of elements that makes it simple
to learn and utilize.
• Most of the ideas are drew from C++ in this manner making Java learning
less difficult Y. (Daniel Liang, 2012).
B. Secure
• Java program can't hurt other framework, in this way making it secure.
• Java gives a protected method for making Internet applications.
• Java gives secure approach to get to web applications
(http://www.c4learn.com/java/java-qualities highlights/, April 2016).
C. Portable
Java programs can execute in any environment for which there is a Java run-time
system-JVM (http://www.c4learn.com/java/java-characteristics-features/, April
2016).
Java programs can be run on any platform (Linux, Window, Mac)
Java programs can be transferred over World Wide Web (e.g applets)
D. Object-oriented
• Java writing computer programs is article arranged programming dialect.
• Like C++ java gives the vast majority of the item situated components (Daniel
Liang, 2012).
• Java is immaculate OOP. Dialect. (While C++ is semi object situated)
E. Robust
Java supports mistake free programming by being entirely written and
performing run-time checks.
F. Multithreaded
• Java gives incorporated backing to multithreaded programming (Daniel
Liang, 2012).
• Architecture-nonpartisan:
• Java is not attached to a particular machine or working framework design.
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

• Machine Independent i.e. Java is autonomous of equipment
(http://www.c 4learn.com/java/java-attributes highlights/, April 2016).
G. Interpreted
• Java bolsters cross-stage code using Java bytecode. Bytecode can be
deciphered on any stage by JVM.
H. High performance
• Byte-codes are exceedingly enhanced.
• JVM can executed them much quicker (Daniel Liang, 2012).
I. Distributed
• Java was planned with the conveyed environment.
• Java can be transmit, keep running over web.
J. Dynamic
Java programs convey with them significant measures of run-time sort data that is
utilized to confirm and resolve gets to objects at run time
(http://www.c4learn.com/java/java-attributes highlights/, April 2016).
1.1. JAVA Runtime Environment
Daniel Liang (2012), the Java Runtime Environment (JRE) is a set of software tools for
development of Java applications. It combines the Java Virtual Machine (JVM), platform
core classes and supporting libraries (https://www.techopedia.com/definition
/5442/java-runtime-environment-jre, April 2016).
From (https://www.techopedia.com/definition/5442/java-runtime-environment-jre,
April 2016), JRE consists of the following components:
i. Deployment technologies, including deployment, Java Web Start and Java Plug-in.
ii. User interface toolkits, including Abstract Window Toolkit (AWT), Swing, Java
2D, Accessibility, Image I/O, Print Service, Sound, drag and drop (DnD) and input
methods.
iii. Integration libraries, including Interface Definition Language (IDL), Java
Database Connectivity (JDBC), Java Naming and Directory Interface (JNDI),
Remote Method Invocation (RMI), Remote Method Invocation Over Internet
Inter-Orb Protocol (RMI-IIOP) and scripting (https://www.techopedia.com/definition
/5442/java-runtime-environment-jre, April 2016).
(http://www.c 4learn.com/java/java-attributes highlights/, April 2016).
G. Interpreted
• Java bolsters cross-stage code using Java bytecode. Bytecode can be
deciphered on any stage by JVM.
H. High performance
• Byte-codes are exceedingly enhanced.
• JVM can executed them much quicker (Daniel Liang, 2012).
I. Distributed
• Java was planned with the conveyed environment.
• Java can be transmit, keep running over web.
J. Dynamic
Java programs convey with them significant measures of run-time sort data that is
utilized to confirm and resolve gets to objects at run time
(http://www.c4learn.com/java/java-attributes highlights/, April 2016).
1.1. JAVA Runtime Environment
Daniel Liang (2012), the Java Runtime Environment (JRE) is a set of software tools for
development of Java applications. It combines the Java Virtual Machine (JVM), platform
core classes and supporting libraries (https://www.techopedia.com/definition
/5442/java-runtime-environment-jre, April 2016).
From (https://www.techopedia.com/definition/5442/java-runtime-environment-jre,
April 2016), JRE consists of the following components:
i. Deployment technologies, including deployment, Java Web Start and Java Plug-in.
ii. User interface toolkits, including Abstract Window Toolkit (AWT), Swing, Java
2D, Accessibility, Image I/O, Print Service, Sound, drag and drop (DnD) and input
methods.
iii. Integration libraries, including Interface Definition Language (IDL), Java
Database Connectivity (JDBC), Java Naming and Directory Interface (JNDI),
Remote Method Invocation (RMI), Remote Method Invocation Over Internet
Inter-Orb Protocol (RMI-IIOP) and scripting (https://www.techopedia.com/definition
/5442/java-runtime-environment-jre, April 2016).

iv. Other base libraries, including international support, input/output (I/O),
extension mechanism, Beans, Java Management Extensions (JMX), Java Native
Interface (JNI), Math, Networking, Override Mechanism, Security, Serialization
and Java for XML Processing (XML JAXP).
v. Lang and util base libraries, including lang and util, management, versioning, zip,
instrument, reflection, Collections, Concurrency Utilities, Java Archive (JAR),
Logging, Preferences API, Ref Objects and Regular Expressions (https://www.
techopedia.com/definition /5442/java-runtime-environment-jre, April 2016).
vi. Java Virtual Machine (JVM), including Java HotSpot Client and Server Virtual
Machines.
1.2. Environmental flexibility of Java Runtime
Existing programming situations are either helpful (Java), or they are adaptable (Jini,
Java RMI), or they are exceptionally beneficial (MPI). The greatest test is to give a
programming situation and a runtime framework that consolidate very compelling
execution and correspondence with the adaptability to continue running on effectively
changing arrangements of heterogeneous processors and frameworks.
Various scientists assume that Java will be a valuable innovation to diminish the many-
sided quality of matrix application programming (V. Getov, 2001). In perspective of an
all around characterized virtual machine and class libraries, Java is intrinsically more
versatile than dialects like C and Fortran, which are statically incorporated in a
conventional manner. Java grants undertakings to continue running on a heterogeneous
arrangement of assets with no prerequisite for recompilation or porting. Advanced In
the nick of time compilers (JITs, for example, the IBM JIT (A. D. Alexandrov et. at., 1997)
or Sun HotSpot2 get execution speed that is engaged to dialects like C or Fortran (J.M.
Bull, et. al., 2001). Other strong reasons for Java for matrix applications incorporate sort
security and coordinated backing for parallel and appropriated programming. Java gives
Remote Technique Invocation (RMI) for straightforward correspondence between Java
Virtual Machines (JVMs).
extension mechanism, Beans, Java Management Extensions (JMX), Java Native
Interface (JNI), Math, Networking, Override Mechanism, Security, Serialization
and Java for XML Processing (XML JAXP).
v. Lang and util base libraries, including lang and util, management, versioning, zip,
instrument, reflection, Collections, Concurrency Utilities, Java Archive (JAR),
Logging, Preferences API, Ref Objects and Regular Expressions (https://www.
techopedia.com/definition /5442/java-runtime-environment-jre, April 2016).
vi. Java Virtual Machine (JVM), including Java HotSpot Client and Server Virtual
Machines.
1.2. Environmental flexibility of Java Runtime
Existing programming situations are either helpful (Java), or they are adaptable (Jini,
Java RMI), or they are exceptionally beneficial (MPI). The greatest test is to give a
programming situation and a runtime framework that consolidate very compelling
execution and correspondence with the adaptability to continue running on effectively
changing arrangements of heterogeneous processors and frameworks.
Various scientists assume that Java will be a valuable innovation to diminish the many-
sided quality of matrix application programming (V. Getov, 2001). In perspective of an
all around characterized virtual machine and class libraries, Java is intrinsically more
versatile than dialects like C and Fortran, which are statically incorporated in a
conventional manner. Java grants undertakings to continue running on a heterogeneous
arrangement of assets with no prerequisite for recompilation or porting. Advanced In
the nick of time compilers (JITs, for example, the IBM JIT (A. D. Alexandrov et. at., 1997)
or Sun HotSpot2 get execution speed that is engaged to dialects like C or Fortran (J.M.
Bull, et. al., 2001). Other strong reasons for Java for matrix applications incorporate sort
security and coordinated backing for parallel and appropriated programming. Java gives
Remote Technique Invocation (RMI) for straightforward correspondence between Java
Virtual Machines (JVMs).
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

Tragically, a hard and energetic issue is Java's menial correspondence speed.
Specifically, Java's RMI execution is abundantly reprimanded (F. Breg, 2001). The
correspondence overhead can be maybe two or three solicitations of degree higher than
that of lower-level models like MPI or RPC (C. Thekkath et. al., 2009). In earlier
exploration on RMI (J. Maassen, 2001), we have tackled this execution issue by utilizing
a local compiler (Manta), supplanting the standard serialization tradition by an
exceptionally compelling, compiler-created zero-duplicate tradition written in C.
Shockingly, this strategy comes up short for matrix programming, as it requires a
custom Java runtime framework that can't be incorporated with standard JVMs. Along
these lines, an imperative exploration issue is the manner by which to get great
correspondence execution for Java without turning to techniques that surrender the
advantages of its virtual machine approach.
1.2.1 PROJECTS DONE WITH JAVA
Java’s open source ecosystem is strong and healthy, one of the primary reasons for our
creation of OSCON Java. Over the last decade, several projects have traveled beyond
mere adoption and had effects dominating the Java world, into software development in
general, and some even further into the daily lives of users (http://radar.
oreilly.com/2011/07/7-java-projects.html, April 2016).
1.2.1.1 JUnit
Ported to Java by Kent Beck and Erich Gamma from Beck’s work in unit testing in
Smalltalk, JUnit has been largely responsible for popularizing test-driven development
over the last decade. Many implementations have been created, in .NET, C, Python, Perl
and just about every language in popular use (http://radar.oreilly .com/2011/07/7-
java-projects.html, April 2016).
1.2.1.2 Eclipse
As Java and its APIs matured in the early 2000s, the Eclipse IDE provided a way for
programmers to be productive and negotiate the growing Java ecosystem. Eclipse was
also the first major project to use the SWT UI toolkit, providing important competition
to Sun’s Swing and showing that Java programs can provide a rich native interface.
Specifically, Java's RMI execution is abundantly reprimanded (F. Breg, 2001). The
correspondence overhead can be maybe two or three solicitations of degree higher than
that of lower-level models like MPI or RPC (C. Thekkath et. al., 2009). In earlier
exploration on RMI (J. Maassen, 2001), we have tackled this execution issue by utilizing
a local compiler (Manta), supplanting the standard serialization tradition by an
exceptionally compelling, compiler-created zero-duplicate tradition written in C.
Shockingly, this strategy comes up short for matrix programming, as it requires a
custom Java runtime framework that can't be incorporated with standard JVMs. Along
these lines, an imperative exploration issue is the manner by which to get great
correspondence execution for Java without turning to techniques that surrender the
advantages of its virtual machine approach.
1.2.1 PROJECTS DONE WITH JAVA
Java’s open source ecosystem is strong and healthy, one of the primary reasons for our
creation of OSCON Java. Over the last decade, several projects have traveled beyond
mere adoption and had effects dominating the Java world, into software development in
general, and some even further into the daily lives of users (http://radar.
oreilly.com/2011/07/7-java-projects.html, April 2016).
1.2.1.1 JUnit
Ported to Java by Kent Beck and Erich Gamma from Beck’s work in unit testing in
Smalltalk, JUnit has been largely responsible for popularizing test-driven development
over the last decade. Many implementations have been created, in .NET, C, Python, Perl
and just about every language in popular use (http://radar.oreilly .com/2011/07/7-
java-projects.html, April 2016).
1.2.1.2 Eclipse
As Java and its APIs matured in the early 2000s, the Eclipse IDE provided a way for
programmers to be productive and negotiate the growing Java ecosystem. Eclipse was
also the first major project to use the SWT UI toolkit, providing important competition
to Sun’s Swing and showing that Java programs can provide a rich native interface.
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

Eclipse has evolved toward a goal of being a universal IDE, and it now provides a rich
foundation for platform vendors to integrate with (http://radar.oreilly.com/2011/07/7
-java-projects.html, April 2016).
1.2.1.3 Spring
The Spring Framework has played an important role in enabling Java developers to be
productive, managing a balance between simplicity and features. Spring gives Java
developers a set of services providing commonly used application functionality such as
data access and transaction management. As a competitor to Sun’s Enterprise Java
Beans system, Spring enabled an alternative and simpler path for Java applications, as
well as ensuring a healthy competition of ideas in the way Java applications are
constructed (http://radar.oreilly.com/2011/07/7-java-projects.html, April 2016).
1.2.1.4 Solr
The Solr server, and the Lucene search engine it encapsulates, has been for many years
a simple and practical solution to providing search capabilities to web and enterprise
applications. Solr’s genius is in providing HTTP access to the powerful and fast Lucene
search library, enabling it to become a part of any system, regardless of whether it is
implemented in Java or not. More than any other project, Solr has ensured that good
search is a checkbox item for modern web applications (http://radar.
oreilly.com/2011/07/7-java-projects.html, April 2016).
1.2.1.5 Hudson and Jenkins
Originally developed as Hudson, and now also as Jenkins, this continuous integration
tool is a key part of a Java development setup. Jenkins provides automated build and
testing of a software project, continuing in the footsteps of JUnit in enabling agile
development on the Java platform. While both Hudson and Jenkins persist for now as
forks of each other, it doesn’t detract from the work of Kohsuke Kawaguchi in creating a
world-class continuous integration platform and so enhancing the quality of much Java
development. (http://radar.oreilly.com/2011/07/7-java-projects.html, April 2016)
1.2.1.6 Hadoop
foundation for platform vendors to integrate with (http://radar.oreilly.com/2011/07/7
-java-projects.html, April 2016).
1.2.1.3 Spring
The Spring Framework has played an important role in enabling Java developers to be
productive, managing a balance between simplicity and features. Spring gives Java
developers a set of services providing commonly used application functionality such as
data access and transaction management. As a competitor to Sun’s Enterprise Java
Beans system, Spring enabled an alternative and simpler path for Java applications, as
well as ensuring a healthy competition of ideas in the way Java applications are
constructed (http://radar.oreilly.com/2011/07/7-java-projects.html, April 2016).
1.2.1.4 Solr
The Solr server, and the Lucene search engine it encapsulates, has been for many years
a simple and practical solution to providing search capabilities to web and enterprise
applications. Solr’s genius is in providing HTTP access to the powerful and fast Lucene
search library, enabling it to become a part of any system, regardless of whether it is
implemented in Java or not. More than any other project, Solr has ensured that good
search is a checkbox item for modern web applications (http://radar.
oreilly.com/2011/07/7-java-projects.html, April 2016).
1.2.1.5 Hudson and Jenkins
Originally developed as Hudson, and now also as Jenkins, this continuous integration
tool is a key part of a Java development setup. Jenkins provides automated build and
testing of a software project, continuing in the footsteps of JUnit in enabling agile
development on the Java platform. While both Hudson and Jenkins persist for now as
forks of each other, it doesn’t detract from the work of Kohsuke Kawaguchi in creating a
world-class continuous integration platform and so enhancing the quality of much Java
development. (http://radar.oreilly.com/2011/07/7-java-projects.html, April 2016)
1.2.1.6 Hadoop

This Java implementation of the famous MapReduce model is the powerhouse that has
enabled most “big data” systems. By lowering the cost of extracting value from large
data sets, Hadoop has made practical the personalization and advertising businesses of
Facebook and Yahoo, and many other companies. In the same way that Linux enabled
large websites to be built on cheap hardware, Hadoop enables large-scale distributed
computing by handling failure at the software level. Both Hadoop and the above-
mentioned Lucene are the product of the work of Doug Cutting
(http://radar.oreilly.com /2011/07/7-java-projects.html, April 2016).
1.2.1.7 Android
Controversy is never that far from Java, whether the custodian be Sun or Oracle.
Google’s choice to use Java as the programming language for its massively
popular Android mobile operating system has led to a renewed interest in the language
from whole new communities of software developers. Android programs undergo a
further step to convert JVM bytecode to Dalvik bytecode — Dalvik being a virtual
machine optimized for mobile devices. Google has been able to leverage Eclipse to
provide software developers with a mature development environment for creating
Android applications (http://radar.oreilly.com/2011/07/7-java-projects.html, April
2016). Oracle and Google are currently engaged in a lawsuit over a claim that Android
infringes on multiple patents held by Oracle. The results of that suit notwithstanding,
Android has done much to recruit developers and perpetuate the use of Java in client-
side software development.
SECTION 2
enabled most “big data” systems. By lowering the cost of extracting value from large
data sets, Hadoop has made practical the personalization and advertising businesses of
Facebook and Yahoo, and many other companies. In the same way that Linux enabled
large websites to be built on cheap hardware, Hadoop enables large-scale distributed
computing by handling failure at the software level. Both Hadoop and the above-
mentioned Lucene are the product of the work of Doug Cutting
(http://radar.oreilly.com /2011/07/7-java-projects.html, April 2016).
1.2.1.7 Android
Controversy is never that far from Java, whether the custodian be Sun or Oracle.
Google’s choice to use Java as the programming language for its massively
popular Android mobile operating system has led to a renewed interest in the language
from whole new communities of software developers. Android programs undergo a
further step to convert JVM bytecode to Dalvik bytecode — Dalvik being a virtual
machine optimized for mobile devices. Google has been able to leverage Eclipse to
provide software developers with a mature development environment for creating
Android applications (http://radar.oreilly.com/2011/07/7-java-projects.html, April
2016). Oracle and Google are currently engaged in a lawsuit over a claim that Android
infringes on multiple patents held by Oracle. The results of that suit notwithstanding,
Android has done much to recruit developers and perpetuate the use of Java in client-
side software development.
SECTION 2
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

2.1 REAL TIME PROBLEM AND SOLUTION WITH JAVA
PROBLEM: A program that lets the user play Blackjack. The game will be a simplified
version of Blackjack as it is played in a casino. The computer will act as the dealer.
EXPLANATION: You should first compose a subroutine in which the customer plays one
redirection. The subroutine should give back a boolean quality to demonstrate whether
the customer wins or not. Return genuine if the customer wins, false if the merchant
wins. The framework needs an object of class Deck and two objects of sort Blackjack
Hand, one for the merchant and one for the customer. The general thing in Blackjack is
to get a hand of cards whose quality is as near 21 as could be normal considering the
present situation, without going over. The redirection goes like this:
Initial, two cards are managed into every player's hand. If the merchant's hand has an
estimation of 21 right now, then the merchant wins. Something else, if the customer has
21, then the customer wins. (This is known as a "Blackjack".) Note that the merchant
wins on a tie, so if both players have Blackjack, then the merchant wins.
Right away, if the amusement has not finished, the customer gets a chance to add a
couple cards to her hand. In this stage, the customer sees her own particular cards and
sees one of the merchant's two cards. (In a club, the merchant gives himself one card
face up and one card face down. All the customer's cards are managed face up.) The
customer settles on a decision whether to "Hit", which intends to add another card to
her hand, or to "Stand", which intends to stop taking cards
(http://math.hws.edu/eck/cs124/javanotes4/c5/ex-5-5-aaswer. html, April, 2016).
If the customer Hits, there is a plausibility that the customer will go more than 21. All
things considered, the preoccupation is over and the customer loses. If not, then the
method continues. The customer finds the opportunity to pick again whether to Hit or
Stand.
In case the customer Stands, the preoccupation will end, however first the merchant
gets a chance to draw cards. The merchant just takes after principles, with no decision.
The guideline is that the length of the estimation of the merchant's hand is not exactly
or equivalent to 16, the merchant Hits (that is, takes another card). The customer
PROBLEM: A program that lets the user play Blackjack. The game will be a simplified
version of Blackjack as it is played in a casino. The computer will act as the dealer.
EXPLANATION: You should first compose a subroutine in which the customer plays one
redirection. The subroutine should give back a boolean quality to demonstrate whether
the customer wins or not. Return genuine if the customer wins, false if the merchant
wins. The framework needs an object of class Deck and two objects of sort Blackjack
Hand, one for the merchant and one for the customer. The general thing in Blackjack is
to get a hand of cards whose quality is as near 21 as could be normal considering the
present situation, without going over. The redirection goes like this:
Initial, two cards are managed into every player's hand. If the merchant's hand has an
estimation of 21 right now, then the merchant wins. Something else, if the customer has
21, then the customer wins. (This is known as a "Blackjack".) Note that the merchant
wins on a tie, so if both players have Blackjack, then the merchant wins.
Right away, if the amusement has not finished, the customer gets a chance to add a
couple cards to her hand. In this stage, the customer sees her own particular cards and
sees one of the merchant's two cards. (In a club, the merchant gives himself one card
face up and one card face down. All the customer's cards are managed face up.) The
customer settles on a decision whether to "Hit", which intends to add another card to
her hand, or to "Stand", which intends to stop taking cards
(http://math.hws.edu/eck/cs124/javanotes4/c5/ex-5-5-aaswer. html, April, 2016).
If the customer Hits, there is a plausibility that the customer will go more than 21. All
things considered, the preoccupation is over and the customer loses. If not, then the
method continues. The customer finds the opportunity to pick again whether to Hit or
Stand.
In case the customer Stands, the preoccupation will end, however first the merchant
gets a chance to draw cards. The merchant just takes after principles, with no decision.
The guideline is that the length of the estimation of the merchant's hand is not exactly
or equivalent to 16, the merchant Hits (that is, takes another card). The customer
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

should see all the merchant's cards at this moment. In a matter of seconds, the champ
can be determined: If the merchant has gone more than 21, the customer wins.
Something else, if the merchant's aggregate is more vital than or equivalent to the
customer's aggregate, then the merchant wins. Something else, the customer wins
(http://math.hws.edu/eck/cs124/javanotes4/c5/ex-5-5-answer.html, April, 2016).
Two notes on programming: At any point in the subroutine, when you know who the
champ is, you can say "return genuine;" or "return false;" to end the subroutine and
come back to the primary framework. To abstain from having an abundance of variables
in your subroutine, remember that a capacity call, for example,
userHand.getBlackjackValue() can be used anyplace that a number could be used,
incorporating into a yield articulation or in the state of an if explanation
(http://math.hws.edu/eck/cs124/javanotes4/c5/ex-5-5-answer.html, April, 2016).
Compose a fundamental program that allows the customer to play a couple of
amusements of Blackjack. To make things fascinating, give the customer 100 dollars,
and let the customer make wagers on the amusement. In case the customer loses,
subtract the wager from the customer's cash. In case the customer wins, add a total
equivalent to the wager to the customer's cash. End the undertaking when the customer
needs to stop or when she comes up short on cash.
SOLUTION:
/*
This program lets the user play Blackjack. The computer
acts as the dealer. The user has a stake of $100, and
makes a bet on each game. The user can leave at any time,
or will be kicked out when he loses all the money.
House rules: The dealer hits on a total of 16 or less
and stands on a total of 17 or more. Dealer wins ties.
A new deck of cards is used for each game.
*/
public class Blackjack {
public static void main(String[] args) {
can be determined: If the merchant has gone more than 21, the customer wins.
Something else, if the merchant's aggregate is more vital than or equivalent to the
customer's aggregate, then the merchant wins. Something else, the customer wins
(http://math.hws.edu/eck/cs124/javanotes4/c5/ex-5-5-answer.html, April, 2016).
Two notes on programming: At any point in the subroutine, when you know who the
champ is, you can say "return genuine;" or "return false;" to end the subroutine and
come back to the primary framework. To abstain from having an abundance of variables
in your subroutine, remember that a capacity call, for example,
userHand.getBlackjackValue() can be used anyplace that a number could be used,
incorporating into a yield articulation or in the state of an if explanation
(http://math.hws.edu/eck/cs124/javanotes4/c5/ex-5-5-answer.html, April, 2016).
Compose a fundamental program that allows the customer to play a couple of
amusements of Blackjack. To make things fascinating, give the customer 100 dollars,
and let the customer make wagers on the amusement. In case the customer loses,
subtract the wager from the customer's cash. In case the customer wins, add a total
equivalent to the wager to the customer's cash. End the undertaking when the customer
needs to stop or when she comes up short on cash.
SOLUTION:
/*
This program lets the user play Blackjack. The computer
acts as the dealer. The user has a stake of $100, and
makes a bet on each game. The user can leave at any time,
or will be kicked out when he loses all the money.
House rules: The dealer hits on a total of 16 or less
and stands on a total of 17 or more. Dealer wins ties.
A new deck of cards is used for each game.
*/
public class Blackjack {
public static void main(String[] args) {

int money; // Amount of money the user has.
int bet; // Amount user bets on a game.
boolean userWins; // Did the user win the game?
TextIO.putln("Welcome to the game of blackjack.");
TextIO.putln();
money = 100; // User starts with $100.
while (true) {
TextIO.putln("You have " + money + " dollars.");
do {
TextIO.putln("How many dollars do you want to bet? (Enter 0 to end.)");
TextIO.put("? ");
bet = TextIO.getlnInt();
if (bet < 0 || bet > money)
TextIO.putln("Your answer must be between 0 and " + money + '.');
} while (bet < 0 || bet > money);
if (bet == 0)
break;
userWins = playBlackjack();
if (userWins)
money = money + bet;
else
money = money - bet;
TextIO.putln();
if (money == 0) {
TextIO.putln("Looks like you've are out of money!");
break;
}
}
TextIO.putln();
TextIO.putln("You leave with $" + money + '.');
int bet; // Amount user bets on a game.
boolean userWins; // Did the user win the game?
TextIO.putln("Welcome to the game of blackjack.");
TextIO.putln();
money = 100; // User starts with $100.
while (true) {
TextIO.putln("You have " + money + " dollars.");
do {
TextIO.putln("How many dollars do you want to bet? (Enter 0 to end.)");
TextIO.put("? ");
bet = TextIO.getlnInt();
if (bet < 0 || bet > money)
TextIO.putln("Your answer must be between 0 and " + money + '.');
} while (bet < 0 || bet > money);
if (bet == 0)
break;
userWins = playBlackjack();
if (userWins)
money = money + bet;
else
money = money - bet;
TextIO.putln();
if (money == 0) {
TextIO.putln("Looks like you've are out of money!");
break;
}
}
TextIO.putln();
TextIO.putln("You leave with $" + money + '.');
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

} // end main()
static boolean playBlackjack() {
// Let the user play one game of Blackjack.
// Return true if the user wins, false if the user loses.
Deck deck; // A deck of cards. A new deck for each game.
BlackjackHand dealerHand; // The dealer's hand.
BlackjackHand userHand; // The user's hand.
deck = new Deck();
dealerHand = new BlackjackHand();
userHand = new BlackjackHand();
/* Shuffle the deck, then deal two cards to each player. */
deck.shuffle();
dealerHand.addCard( deck.dealCard() );
dealerHand.addCard( deck.dealCard() );
userHand.addCard( deck.dealCard() );
userHand.addCard( deck.dealCard() );
TextIO.putln();
TextIO.putln();
/* Check if one of the players has Blackjack (two cards totaling to 21).
The player with Blackjack wins the game. Dealer wins ties.
*/
if (dealerHand.getBlackjackValue() == 21) {
TextIO.putln("Dealer has the " + dealerHand.getCard(0)
+ " and the " + dealerHand.getCard(1) + ".");
TextIO.putln("User has the " + userHand.getCard(0)
+ " and the " + userHand.getCard(1) + ".");
static boolean playBlackjack() {
// Let the user play one game of Blackjack.
// Return true if the user wins, false if the user loses.
Deck deck; // A deck of cards. A new deck for each game.
BlackjackHand dealerHand; // The dealer's hand.
BlackjackHand userHand; // The user's hand.
deck = new Deck();
dealerHand = new BlackjackHand();
userHand = new BlackjackHand();
/* Shuffle the deck, then deal two cards to each player. */
deck.shuffle();
dealerHand.addCard( deck.dealCard() );
dealerHand.addCard( deck.dealCard() );
userHand.addCard( deck.dealCard() );
userHand.addCard( deck.dealCard() );
TextIO.putln();
TextIO.putln();
/* Check if one of the players has Blackjack (two cards totaling to 21).
The player with Blackjack wins the game. Dealer wins ties.
*/
if (dealerHand.getBlackjackValue() == 21) {
TextIO.putln("Dealer has the " + dealerHand.getCard(0)
+ " and the " + dealerHand.getCard(1) + ".");
TextIO.putln("User has the " + userHand.getCard(0)
+ " and the " + userHand.getCard(1) + ".");
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

TextIO.putln();
TextIO.putln("Dealer has Blackjack. Dealer wins.");
return false;
}
if (userHand.getBlackjackValue() == 21) {
TextIO.putln("Dealer has the " + dealerHand.getCard(0)
+ " and the " + dealerHand.getCard(1) + ".");
TextIO.putln("User has the " + userHand.getCard(0)
+ " and the " + userHand.getCard(1) + ".");
TextIO.putln();
TextIO.putln("You have Blackjack. You win.");
return true;
}
/* If neither player has Blackjack, play the game. First the user
gets a chance to draw cards (i.e., to "Hit"). The while loop ends
when the user chooses to "Stand". If the user goes over 21,
the user loses immediately.
*/
while (true) {
/* Display user's cards, and let user decide to Hit or Stand. */
TextIO.putln();
TextIO.putln();
TextIO.putln("Your cards are:");
for ( int i = 0; i < userHand.getCardCount(); i++ )
TextIO.putln(" " + userHand.getCard(i));
TextIO.putln("Your total is " + userHand.getBlackjackValue());
TextIO.putln();
TextIO.putln("Dealer is showing the " + dealerHand.getCard(0));
TextIO.putln();
TextIO.putln("Dealer has Blackjack. Dealer wins.");
return false;
}
if (userHand.getBlackjackValue() == 21) {
TextIO.putln("Dealer has the " + dealerHand.getCard(0)
+ " and the " + dealerHand.getCard(1) + ".");
TextIO.putln("User has the " + userHand.getCard(0)
+ " and the " + userHand.getCard(1) + ".");
TextIO.putln();
TextIO.putln("You have Blackjack. You win.");
return true;
}
/* If neither player has Blackjack, play the game. First the user
gets a chance to draw cards (i.e., to "Hit"). The while loop ends
when the user chooses to "Stand". If the user goes over 21,
the user loses immediately.
*/
while (true) {
/* Display user's cards, and let user decide to Hit or Stand. */
TextIO.putln();
TextIO.putln();
TextIO.putln("Your cards are:");
for ( int i = 0; i < userHand.getCardCount(); i++ )
TextIO.putln(" " + userHand.getCard(i));
TextIO.putln("Your total is " + userHand.getBlackjackValue());
TextIO.putln();
TextIO.putln("Dealer is showing the " + dealerHand.getCard(0));
TextIO.putln();

TextIO.put("Hit (H) or Stand (S)? ");
char userAction; // User's response, 'H' or 'S'.
do {
userAction = Character.toUpperCase( TextIO.getlnChar() );
if (userAction != 'H' && userAction != 'S')
TextIO.put("Please respond H or S: ");
} while (userAction != 'H' && userAction != 'S');
/* If the user Hits, the user gets a card. If the user Stands,
the loop ends (and it's the dealer's turn to draw cards).
*/
if ( userAction == 'S' ) {
// Loop ends; user is done taking cards.
break;
}
else { // userAction is 'H'. Give the user a card.
// If the user goes over 21, the user loses.
Card newCard = deck.dealCard();
userHand.addCard(newCard);
TextIO.putln();
TextIO.putln("User hits.");
TextIO.putln("Your card is the " + newCard);
TextIO.putln("Your total is now " + userHand.getBlackjackValue());
if (userHand.getBlackjackValue() > 21) {
TextIO.putln();
TextIO.putln("You busted by going over 21. You lose.");
TextIO.putln("Dealer's other card was the "
+ dealerHand.getCard(1));
return false;
}
}
} // end while loop
char userAction; // User's response, 'H' or 'S'.
do {
userAction = Character.toUpperCase( TextIO.getlnChar() );
if (userAction != 'H' && userAction != 'S')
TextIO.put("Please respond H or S: ");
} while (userAction != 'H' && userAction != 'S');
/* If the user Hits, the user gets a card. If the user Stands,
the loop ends (and it's the dealer's turn to draw cards).
*/
if ( userAction == 'S' ) {
// Loop ends; user is done taking cards.
break;
}
else { // userAction is 'H'. Give the user a card.
// If the user goes over 21, the user loses.
Card newCard = deck.dealCard();
userHand.addCard(newCard);
TextIO.putln();
TextIO.putln("User hits.");
TextIO.putln("Your card is the " + newCard);
TextIO.putln("Your total is now " + userHand.getBlackjackValue());
if (userHand.getBlackjackValue() > 21) {
TextIO.putln();
TextIO.putln("You busted by going over 21. You lose.");
TextIO.putln("Dealer's other card was the "
+ dealerHand.getCard(1));
return false;
}
}
} // end while loop
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide
1 out of 24

Your All-in-One AI-Powered Toolkit for Academic Success.
+13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
Copyright © 2020–2025 A2Z Services. All Rights Reserved. Developed and managed by ZUCOL.