Jav
Jav
Jav
VM, JRE, and JDK are platform dependent because the configuration of each OS is
different from each other. However, Java is platform independent.
JRE
JRE is an acronym for Java Runtime Environment. It is also written as Java RTE. The
Java Runtime Environment is a set of software tools which are used for developing
Java applications. It is used to provide the runtime environment. It is the
implementation of JVM. It physically exists. It contains a set of libraries + other files
that JVM uses at runtime.
JDK
JDK is an acronym for Java Development Kit. The Java Development Kit (JDK) is a
software development environment which is used to develop Java applications and
applets. It physically exists. It contains JRE + development tools.
The JDK contains a private Java Virtual Machine (JVM) and a few other resources
such as an interpreter/loader (java), a compiler (javac), an archiver (jar), a
documentation generator (Javadoc), etc. to complete the development of a Java
Application.
An applet is a program written in the Java programming language that can be included
in an HTML page,
A set of classes and interfaces grouped together are known as Packages in JAVA.
ex of package is import java.util.*;
util package in Java is a built-in package that contains various utility classes and
interfaces.
ex in util package are arrayS, ARRAY LIST ETC
BOOLEAN-1Bit, char-16bits, int-32bits, long-64,float,32,double-64bits,
1byte=8bits
primitve data types- can store only one value,pre-defined. includes
int,boolean,char etc.
non-primitve- can store multiple values, user-defined, includes array etc.
A class is a user-defined blueprint or prototype from which objects are created. Using
classes, you can create multiple objects with the same behavior instead of writing
their code multiple times.
Objects are instance of class
https://www.w3schools.com/java/java_methods.asp
Class Names
i. The first letter of the class should be in Uppercase (lowercase is allowed but
discouraged).
ii. If several words are used to form the name of the class, each inner word ’ s first
letter should be in Uppercase. Underscores are allowed, but not recommended. Also
allowed are numbers and currency symbols, although the latter are also discouraged
because they are used for a special purpose (for inner and anonymous classes).
Method Names
i. All the method names should start with a lowercase letter (uppercase is also allowed
but lowercase is recommended).
ii. If several words are used to form the name of the method, then each first letter of
the inner word should be in Uppercase. Underscores are allowed, but not
recommended. Also allowed are digits and currency symbols.
Certainly! Let's break down each part of the Java code snippet public static void
main(String[] args):
1. *public*: This is an access modifier, which indicates that the method main is
accessible from anywhere. In Java, public means that the method can be accessed by
any other class.
2. *static*: This keyword allows the method main to be called without needing to
create an instance of the class. In Java, the main method is typically declared as static
because it serves as the entry point for the program and can be invoked without
creating an object of the class containing it.
3. *void*: This is the return type of the method. void indicates that the main method
does not return any value. In Java, the main method does not need to return anything
because it is simply the starting point of the program.
4. *main*: This is the name of the method. In Java, the main method is the entry
point of a Java application. It is where the execution of the program begins.
5. *String[] args*: This is the parameter of the main method. It is an array of strings
(String[]) named args. When the Java program is executed from the command line,
any command-line arguments provided are passed to the main method through this
parameter. The args parameter allows the program to receive input or configuration
from the command line.
2. *Compiler: A compiler is a software tool that translates the entire source code
written in a high-level programming language into machine code or an intermediate
code called object code. Unlike interpreters, compilers generate the complete
executable file before execution. This executable file can be run multiple times
without needing to recompile the source code each time. Commonly used compiled
languages include C, C++, and Java. Compilers offer advantages such as faster
execution speed and optimization of code.
Identifiers in java
Identifiers are the names of local variables, instance and class variables, and labels,
but also the names for classes, packages, modules and methods. All Unicode
characters are valid, not just the ASCII subset.
i. All identifiers can begin with a letter, a currency symbol or an underscore (_).
According to the convention, a letter should be lower case for variables.
ii. The first character of identifiers can be followed by any combination of letters,
digits, currency symbols and the underscore. The underscore is not recommended for
the names of variables. Constants (static final attributes and enums) should be in all
Uppercase letters.
iv. A keyword cannot be used as an identifier since it is a reserved word and has some
special meaning.
Java Keywords
Keywords or Reserved words are the words in a language that are used for some
internal process or represent some predefined actions. These words are therefore not
allowed to use as variable names or objects.
Access Modifiers
The access modifiers in Java specifies the accessibility or scope of a field, method,
constructor, or class. We can change the access level of fields, constructors, methods,
and class by applying the access modifier on it.
Private: The access level of a private modifier is only within the class. It cannot be
accessed from outside the class.
Default: The access level of a default modifier is only within the package. It cannot
be accessed from outside the package. If you do not specify any access level, it will be
the default.
Protected: The access level of a protected modifier is within the package and outside
the package through child class. If you do not make the child class, it cannot be
accessed from outside the package.
Public: The access level of a public modifier is everywhere. It can be accessed from
within the class, outside the class, within the package and outside the package.
Variables
Variables are containers for storing data values. In Java, there are different types of
variables, for example: String - stores text, such as "Hello". String values are
surrounded by double quotes. int - stores integers (whole numbers), without decimals,
such as 123 or -123.
A data type is a classification that specifies which type of value a variable can hold or
which operations can be performed on that variable.
Local Variables
A variable defined within a block or method or constructor is called a local variable.
Scope:
Scope defines the region of the program where a variable can be accessed.
In Java, variables have block scope, meaning they are accessible only within the block
in which they are declared.
For instance, a variable declared within a method is only accessible within that
method.
Variables declared within a block (e.g., within loops or conditional statements) are
only accessible within that block.
Lifetime:
Lifetime refers to the duration for which a variable remains in memory.
Public means it can be accesses anywhere. Static means its belongs to particular
method etc.
Loops Concept
In Java, while, do-while, and for loops are used for repetitive execution of a block of
code. While they serve a similar purpose, they have different syntaxes and are suitable
for different scenarios:
1. *While Loop*:
- Syntax: while (condition) { // code block }
- The while loop executes a block of code repeatedly as long as the specified
condition is true.
- It first evaluates the condition, and if it's true, executes the code block. Then, it
re-evaluates the condition. If the condition is still true, the loop continues, and so on.
The loop terminates when the condition becomes false.
- The condition is tested before entering the loop, so there's a possibility that the
code inside the loop may never execute if the condition is initially false.
- Example:
java
int i = 0;
while (i < 5) {
System.out.println(i);
i++;
}
2. *Do-While Loop*:
- Syntax: do { // code block } while (condition);
- The do-while loop is similar to the while loop, but it guarantees that the code
block is executed at least once, regardless of whether the condition is true or false.
- It first executes the code block and then evaluates the condition. If the condition
is true, the loop continues; otherwise, it terminates.
- Example:
java
int i = 0;
do {
System.out.println(i);
i++;
} while (i < 5);
3. *For Loop*:
- Syntax: for (initialization; condition; update) { // code block }
- The for loop provides a concise way to iterate over a range of values or to iterate
based on a counter.
- It consists of three parts: initialization (executed once before the loop starts),
condition (evaluated before each iteration; if false, the loop terminates), and update
(executed after each iteration).
- The initialization, condition, and update parts are separated by semicolons.
- Example:
java
for (int i = 0; i < 5; i++) {
System.out.println(i);
}
In summary, while and do-while loops are used when the number of iterations is not
known beforehand or when you want to repeat a block of code until a certain
condition is met, while for loops are used when the number of iterations is known or
when you want to iterate over a range of values.
Prime number :
import java.util.Scanner;
public class CodesCracker
{
public static void main(String[] args)
{
int num, i, count=0;
Scanner s = new Scanner(System.in);
System.out.print("Enter a Number: ");
num = s.nextInt();
if(count==0)
System.out.println("\nIt is a Prime Number.");
else
System.out.println("\nIt is not a Prime Number.");
}
}
Fibonacci:
class FibonacciExample1{
public static void main(String args[])
{
int n1=0,n2=1,n3,i,count=10;
System.out.print(n1+" "+n2);//printing 0 and 1
}
}
while (n > 0) {
int rem = n % 10;
p = (p) + (rem * rem * rem);
n = n / 10;
}
if (temp == p) {
System.out.println("Yes. It is Armstrong No.");
Reverse a string
import java.util.*;
public class yoo {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
char ch=0;
String nchar="";
for(int i=0;i<str.length();i++){
ch=str.charAt(i);
nchar=ch+nchar;
}
System.out.println(nchar);
}
Factorial
import java.util.*;
public class yoo {
public static int fact(int n){
if(n==0){
return 1;
}
else{
return n*fact(n-1);
}
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
System.out.println(fact(n));
}
}
Occurence_of_a_string
import java.util.*;
public class yoo {
public static void main(String[] args) {
String str="ssidda";
int len;
int counter[]=new int[256];
for(int i=0;i<str.length();i++){
counter[(int)str.charAt(i)]++;
}
for(int i=0;i<256;i++){
if(counter[i]!=0){
System.out.println((char)i+"-->"+counter[i]);
}
}
}
Stage 3: Design
Design | Third Step In SDLC | BetsolIn the design phase (3rd step of SDLC), the
program developer scrutinizes whether the prepared software suffices all the
requirements of the end-user. Additionally, if the project is feasible for the customer
technologically, practically, and financially. Once the developer decides on the best
design approach, he then selects the program languages like Oracle, Java, etc., that
will suit the software.
Once the design specification is prepared, all the stakeholders will review this plan
and provide their feedback and suggestions. It is absolutely mandatory to collect and
incorporate stakeholder’s input in the document, as a small mistake can lead to cost
overrun.
Stage 4: Coding or Implementation
Coding or Implementation | Fourth Step In SDLC | BetsolTime to code! It means
translating the design to a computer-legible language. In this fourth stage of SDLC,
the tasks are divided into modules or units and assigned to various developers. The
developers will then start building the entire system by writing code using the
programming languages they chose. This stage is considered to be one of the longest
in SDLC. The developers need certain predefined coding guidelines, and
programming tools like interpreters, compilers, debugger to implement the code.
The developers can show the work done to the business analysts in case if any
modifications or enhancements required.
Stage 5: Testing
Testing | Fifth Step In SDLC | BetsolOnce the developers build the software, then it is
deployed in the testing environment. Then the testing team tests the functionality of
the entire system. In this fifth phase of SDLC, the testing is done to ensure that the
entire application works according to the customer requirements.
After testing, the QA and testing team might find some bugs or defects and
communicate the same with the developers. The development team then fixes the
bugs and send it to QA for a re-test. This process goes on until the software is stable,
bug-free and working according to the business requirements of that system.
Stage 6: Deployment
Development | Sixth Step In SDLC | BetsolThe sixth phase of SDLC: Once the testing
is done, and the product is ready for deployment, it is released for customers to use.
The size of the project determines the complexity of the deployment. The users are
then provided with the training or documentation that will help them to operate the
software. Again, a small round of testing is performed on production to ensure
environmental issues or any impact of the new release.
Stage 7: Maintenance
Maintenance | Seventh Step In SDLC | BetsolThe actual problem starts when the
customer actually starts using the developed system and those needs to be solved from
time to time. Maintenance is the seventh phase of SDLC where the developed product
is taken care of. According to the changing user end environment or technology, the
software is updated timely.
https://docs.google.com/document/d/1OrUsnDqzma9ob467aCdvRlZwkK7mhl552n92
vlBXr_U/edit