Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

Problems of Java

The document discusses modern Java programming problems, providing examples and solutions for beginners to advanced programmers. It covers key features of Java, its applications, and compares it with C and Python, highlighting advantages and installation steps for Java. Additionally, it includes sample code for various programming tasks like generating series, checking prime numbers, calculating factorials, and printing Pell series.

Uploaded by

Rahul Paul
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Problems of Java

The document discusses modern Java programming problems, providing examples and solutions for beginners to advanced programmers. It covers key features of Java, its applications, and compares it with C and Python, highlighting advantages and installation steps for Java. Additionally, it includes sample code for various programming tasks like generating series, checking prime numbers, calculating factorials, and printing Pell series.

Uploaded by

Rahul Paul
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Problems of Java

MORDEN JAVA PROGRAMMING PROBLEMS


( The ultimate java programming problems for beginner to advance
programmer journey by help of modern Java language )

Modern Java programming problems solving paper with output


console data, help of Vs-code IDE and JDK compiler setup
in windows computer. Few Questions and their respective
answer with output results. Learn complex Java codes and
behavior of Batch system.

First Paper

VS Codes IDE Java Environment Microsoft OpenJDK

KRISHNENDU MITRA
( Fullstack Web Developer )
Introduction:
Java is a high-level, object-oriented, and platform-independent programming language. It was
developed by James Gosling and his team at Sun Microsystems (now owned by Oracle Corporation) in
the mid-1990s. Java quickly gained popularity due to its "Write Once, Run Anywhere" (WORA)
capability, which allows Java programs to be executed on any platform with a Java Virtual Machine
(JVM).

Key Features of Java:

1. Object-Oriented: Java is based on the object-oriented programming (OOP) paradigm, where


everything is treated as an object. This approach promotes code reusability, modularity, and
better organization of the codebase.

2. Platform Independence: Java achieves platform independence by compiling Java source code into
an intermediate form called bytecode. This bytecode can run on any platform with a JVM, making
Java applications highly portable.

3. Memory Management: Java manages memory automatically through a process known as garbage
collection. This reduces the burden on the programmer, as they don't need to manually allocate
or deallocate memory.

4. Robustness and Safety: Java is designed to be robust and safe. It includes features like strong
type-checking, exception handling, and runtime bounds checking to ensure stable and secure
program execution.

5. Multi-threading Support: Java has built-in support for multi-threading, allowing developers to
create concurrent applications. This is essential for tasks like handling multiple client requests in
server-side applications.

6. Rich Standard Library: Java comes with a vast standard library that provides a wide range of pre-
built classes and packages, making it easier for developers to accomplish various tasks without
having to write everything from scratch.

7. Community and Ecosystem: Java has a massive and active developer community, resulting in a
rich ecosystem of libraries, frameworks, and tools that enhance productivity and help developers
build complex applications more efficiently.

Applications of Java:

Java is used in a wide range of applications, including but not limited to:
o Web development: Java serves as the backbone for many server-side web applications and
enterprise-level systems.

o Desktop applications: Java is employed in creating cross-platform desktop applications using


libraries like JavaFX and Swing.

Scan the QR for contact us Page – 1age-


o Mobile applications: With Android adopting Java as its primary programming language, Java is
extensively used for Android app development.

o Enterprise applications: Java is well-suited for building large-scale, robust, and secure enterprise-
level applications.

o Scientific applications: Java is used in scientific and research-oriented applications due to its
performance and numerical computation capabilities.

Overall, Java's popularity can be attributed to its simplicity, portability, robustness, and
versatility. Its widespread use in various domains makes it a valuable skill for programmers and
ensures its relevance in the software development landscape.

Java is better to C/Python:

Determining whether Java is better than C or Python depends on the context and the specific
requirements of a project. Each language has its strengths and weaknesses, and the choice of language
often depends on the nature of the application and the goals of the development.

Java's advantages over C:

1. Platform Independence: Java's "Write Once, Run Anywhere" capability allows it to run on any
platform with a Java Virtual Machine (JVM). In contrast, C code needs to be compiled separately
for each target platform.

2. Automatic Memory Management: Java's garbage collection takes care of memory management,
reducing the risk of memory leaks and making it easier for developers to manage memory
compared to C, where manual memory allocation and deallocation can be error-prone.

3. Object-Oriented: Java is inherently object-oriented, making it easier to design and organize code
using classes and objects, leading to code reusability and easier maintenance.

4. Rich Standard Library: Java comes with an extensive standard library, providing numerous pre-
built classes and functions for common tasks, which can save development time.

Java's advantages over Python:

1. Performance: Java generally performs better than Python for computationally-intensive tasks due
to its compiled nature and static typing. Python, being an interpreted language, can be slower in
certain scenarios.

2. Strong Typing: Java enforces strong typing, which helps catch errors at compile time, reducing the
likelihood of runtime errors compared to Python's dynamic typing.

3. Threading: Java has better support for multithreading and concurrent programming, making it
more suitable for applications requiring heavy parallel processing.

Scan the QR for contact us Page – 2age-


4. Static Code Analysis: Java's static analysis tools can help detect errors and potential issues in the
code at compile time, aiding in maintaining code quality.

It's important to note that C and Python have their own advantages in different contexts:

Advantages of C over Java and Python:


o C is closer to the hardware and offers more direct control over memory and system resources,
making it ideal for low-level programming, embedded systems, and performance-critical
applications.

Advantages of Python over Java and C:


o Python's simplicity and readability make it an excellent choice for rapid application development,
prototyping, and scripting tasks.

o Python's extensive libraries and frameworks support various domains, such as web development
(Django, Flask), scientific computing (NumPy, SciPy), and data analysis (Pandas).

In conclusion, the choice of language depends on factors like project requirements,


performance needs, development speed, team expertise, and existing infrastructure. Java's platform
independence, strong OOP support, and robust ecosystem make it a popular choice for enterprise
applications and larger projects. C might be preferred for system-level programming and resource-
constrained environments, while Python's ease of use and versatility make it a top choice for quick
prototyping and data-related tasks.

Installation of JAVA:

Pre-requiring Java
Before starting Modern Java problem solving some important installations and setup is
required in our computer. The first one is checking your
computer is ready to handling Java codes or not. Check the
storge is at least 45% clear and processor is higher than {i3,
ryzen3, dimensity 900, snapdragon 695} processor. If this
point is clear then ready to install programming environment
in our computer. At first download an IDE like VS-code, Java,
CodeBlockes etc. I am using VS-code to implement Java codes
for this paper.

After installing VS-code ide, make ready to it for Java extension.


Make file where we code Java, and open it in your VS-code then
click Ctrl+Shift+X and search an extension named ‘ Extension
Pack for Java, IntelliCode…’ to install it and thereafter make
file named ‘Main.java’ to write code in it.
If you want to do not download any Ide,tools then you can choose online Java compilers execute them.
Follow the given steps to make this setup idea successfully in your computer:

1. Vs Code installations:

Scan the QR for contact us Page – 3age-


Open any browser or Microsoft stores and search ‘VS code download’ or directly click the
given link https://code.visualstudio.com/download and then choose your operating system
pack mean if you use Mac then click macOs or if you use windows then click windows button
and wait to download it in you computer then install it like other Apps or game simply.

For more details to install Vs-code visit my youtube channel where I guide how to install it
step by step.
2. Make a Folder:
After installation Vs-code ide, you need a folder where you store your all Java codes and its
related media. This folder make your Os UI clean and logical so open your vs code folder or
follow this path to make a folder there ‘ D:\.vscode\Vs programmes\ ’(same path is not
required) , make folder name ‘ Java codes ’ like following

Post-requiring Java
When the pre-requiring points is done and your computer ready to approach java then simply
install Java on your computer, follow these steps based on windows operating system:

I. Visit the Oracle website to download the Java Development Kit (JDK) or the Java Runtime
Environment (JRE). The JDK includes the JRE and additional development tools, so it's usually
recommended for developers.

II. Go to the Java SE downloads page: https://www.oracle.com/java/technologies/javase-


downloads.html

III. Accept the license agreement and choose the appropriate JDK or JRE version for your
operating system (e.g., Windows x64 for 64-bit Windows or Windows x86 for 32-bit Windows).

Scan the QR for contact us Page – 4age-


IV. Download the installer and run it. Follow the installation wizard instructions.

V. After installation, set the "JAVA_HOME" environment variable to point to the JDK installation
directory and add the "bin" directory to the "PATH" environment variable.

VI. To verify that Java is installed, open a command prompt and type `java -version` to see the
installed Java version.

>> Note that if you want you use java in only VS-code then follow the given points:
I. Visit the Microsoft OpenJDK website to download the Java Development Kit (JDK). Click
the download button and go to next page. Showing at below,

II. Download the windows OpenJDK package in your computer supporting system in terms
of 32bit/64bit/128bit/etc.. and wait to download.

III. When download is completed, run it as administrator in your computer and accept the
license agreement (Read first).

IV. After installation, set the "JAVA_HOME" environment variable to point to the JDK
installation directory and add the "bin" directory to the "PATH" environment variable.

V. To verify that Java is installed, open a Terminal in your selected folder in VS-code and type
` java --version ` to see the installed Java version.

Scan the QR for contact us Page – 5age-


If the above points are successfully done then your computer ready to code a java project.

Open “Java codes” folder in Vs-code and make file which name is ‘Main.java’ and write the given codes
and run it in terminal. In terminal write javac Main.java and wait compile it, this command make a
class file named ‘Main.class’ and then write java Main in terminal and wait to get output

If you want to learn more and depley about java then download our another java ebooks in following
sourse and read them , this doument’s Aim only solve some Java related problems.
More source is:
https://whitelotus4.github.io/weatherbyWHITELOTUS.github.io/PStorebyWhiteLotus.html#PS
WL1?details=Problems%20of%20Java.kid
Visit this site and search there introduction of java or simply java.
Check out the Licence and meta data for this document to understand this paper.

The given all code and ther output is follow the makaut universty syllabus and programe related
curiculam on colleges, this paper based on 2017 to 2024s Java language and Java libraries.

Scan the QR for contact us Page – 6age-


1) Write a programs for each of the following to print the series:

a) 1, 4, 9, 16, 25, 36, …… 100

public class Main{


//code by krish
public static void main(String[] args){
//not return anything
int n, i = 1;
n = 10; //the range is given in question
System.out.println("First 8 values of this series are: ");
//1 to 10 do
while(i <= n){
System.out.print(i * i + " ");
i++;
}
}
}
Output:
First 8 values of this series are:

1 4 9 16 25 36 49 64 81 100

b) 1, 2, 4, 7, 11, 16, 22, 29, …., up to n terms. [Take n as input]

import java.util.Scanner;
//code by krish
public class Main{
public static void main(String args[]){
//not return anything
int i, term, n;
//access scanner utility
Scanner input = new Scanner(System.in);
System.out.print("Enter the range of number(n): ");
n = input.nextInt(); //take user input
//0 to n do
for(i = 0; i < n; i++){

Scan the QR for contact us Page – 7age-


//calculate the value of term
term = 1 + ((i * (i + 1)) / 2);
//display the Kboat Series value
System.out.print(term + " ");
}
input.close(); //close the scanner utility
}
}
Output:
Enter the range of number(n): 15

1 2 4 7 11 16 22 29 37 46 56 67 79 92 106

2) Write a program to input an integer and check whether it is a prime number or not:

import java.util.Scanner;
//code by krish
public class Main{
public static void main(String args[]){
//not return anything
int i, n, temp = 0;
//access scanner utility
Scanner input = new Scanner(System.in);
System.out.print("Enter the number: ");
n = input.nextInt(); //take user input
//0 or 1 not prime and unloopable
if(n == 0 || n == 1){
System.out.println(n + " is not prime number");
}else{
for(i = 2; i < n; i++){ //never i<=n, always i<n
if(n % i == 0){ //reminder 0 says it is not
System.out.println(n + " is not prime number");
temp++; //how many elements able to encounter n
//break the code
break;
}

Scan the QR for contact us Page – 8age-


}
if(temp == 0){
System.out.println(n + " is prime number");
}
}
input.close(); //close the scanner utility
}
}
Output:
Enter the number: 17

17 is prime number

3) Write a program to input an integer and find its factorial:

import java.util.Scanner;
//code by krish
public class test{
public static void main(String args[]){
//not return anything
int i, n;
//access scanner utility
Scanner input = new Scanner(System.in);
System.out.print("Enter the number: ");
n = input.nextInt(); //take user input
//huge size factorial value store in long
long fact = 1;
for(i = 1; i <= n; ++i){
// x! = x * (x-1) * (x-2) *.....* 2 * 1;
fact *= i;
}
System.out.printf("Factorial of %d = %d ", n, fact);
input.close(); //close the scanner utility
}
}

Scan the QR for contact us Page – 9age-


Output:
Enter the number: 5

Factorial of 5 = 120

4) Write a program to print the first 15 numbers of the Pell series:

public class Main{


//code by krish
// function return Pell value
public static int pellCaller(int n){
//return integer value
if(n <= 2)
return n;
// a and b use to first and last
int a = 1, b = 2, c, i;
for(i = 3; i <= n; i++){
c = 2 * b + a;
a = b; //menhover swap
b = c;
}
return b; //result
}
// main code
public static void main(String args[]){
int n = 15, i; //15 is given in question
System.out.println("The 1 to " + n + "th" + " term of the
series is: ");
for(i = 1; i <= n; i++){ //1 to n, not 0 to n
System.out.printf("%10d ",pellCaller(i));

if((i % 5 == 0) && (i != 0)){ //just for styling


System.out.println(" ");
}
}
}

Scan the QR for contact us Page – 10age-


}
Output:
The 1 to 15th term of the series is:

1 2 5 12 29

70 169 408 985 2378

5741 13860 33461 80782 195025

5) Using nested loops write programmes to generate the following patterns on the screen :

a.

*****
****
***
**
*
public class Main{
//code by krish
public static void main(String[] args){
int n = 5; //row no is given in question
int i, j; //loop controller
for(i = n; i > 0; i--){
//no space requires
for(j = 1; j <= i; j++){ //loop in a loop
System.out.print("*");
}
System.out.println();
}
}
}
Output:
*****

****

***

**

Scan the QR for contact us Page – 11age-


b.

12345
23451
34512
45123
51234

public class Main{


//code by krish
public static void main(String[] args){
int i, j; //loop controller
int n=5; //row no is given in question
for(i=1; i<=n; i++){
for(j=i; j<=n; j++){ //loop in a loop
System.out.print(j);
}
for(j=1; j<=i-1; j++){ //loop in a loop
System.out.print(j);
}
System.out.println(); //change the line
}
}
}
Output:
12345

23451

34512

45123

51234

To be continue…..

Scan the QR for contact us Page – 12age-

You might also like