Java Consepts
Java Consepts
Java Consepts
class Animal
}
class Animal{
}
class Dog extends Animal{
}
class Cat extends Animal{
Executing a program. Once you compile the program, you can run it.
This is the exciting part, where your program takes control of your
computer (within the constraints of what the Java system allows). It
is perhaps more accurate to say that your computer follows your
instructions. It is even more accurate to say that a part of the Java
system known as the Java Virtual Machine (the JVM, for short)
directs your computer to follow your instructions. To use the JVM to
execute your program, type the java command followed by the
program name in a terminal window
Type conversion.
num1 = 5 # int
# Float
System.out.println(value);
}
}
A run time error will only occur when the code is actually running. These are the
most difficult - and lead to program crashes and bugs in your code which can be
hard to track down.
Compiler errors are due to inaccuracies in code, where the compiler throws an
error to alert you to something which will not compile, and therefore cannot be
run.
Compile-time and Runtime are the two programming terms used in the software
development. Compile-time is the time at which the source code is converted into an
executable code while the run time is the time at which the executable code is started
running. Both the compile-time and runtime refer to different types of error.
Compile-time errors are the errors that occurred when we write the wrong
syntax. If we write the wrong syntax or semantics of any programming
language, then the compile-time errors will be thrown by the compiler. The
compiler will not allow to run the program until all the errors are removed from
the program. When all the errors are removed from the program, then the
compiler will generate the executable file.
The compile-time errors can be:
o Syntax errors
o Semantic errors
The runtime errors are the errors that occur during the execution and
after compilation. The examples of runtime errors are division by zero,
etc. These errors are not easy to detect as the compiler does not point to
these errors.
o Let's explore some typical C runtime error types, cases, and their
possible effects.
Division by Zero
Example:
int x = 4343434334334; error because compiler can know that this
number is too large.
Int x = int x = Integer.MAX_VALUE + 4; not make any error because
compiler does not know this value after assignment in compile time.
int x = 4L; compile error because (L) indicate that this is long value but
you assignment to int.
MrgMarriageContractVORowImpl marriageRow =
(MrgMarriageContractVORowImpl) row;
} else {
Example of NullPointerException:
Assignment Error:
int calculateSum() {
System.out.println(num);
To execute the bytecode JVM (Java Virtual Machine) will execute it.
JVM: It’s a software-based execution Environment that interprets and run bytecode.
Each platform like (window, I/OS, It Setra ) has its own JVM implementation.
platform independent bytecode meaning that meaning that the same compile java
program can be executed any platform that has a compatible JVM.
This help the developers to not write the same code in different versions depending
on the platform.
Python Advance:
Syntax errors, also known as parsing errors, are perhaps the most common kind of complaint you get while you are
still learning Python:
The parser repeats the offending line and displays little ‘arrow’s pointing at the token in the line where the error
was detected. The error may be caused by the absence of a token before the indicated token. In the example, the
error is detected at the function print(), since a colon (':') is missing before it. File name and line number are printed
so you know where to look in case the input came from a script.
Exceptions:
Even if a statement or expression is syntactically correct, it may cause an error when an attempt is made to
execute it. Errors detected during execution are called exceptions and are not unconditionally fatal: you will soon
learn how to handle them in Python programs. Most exceptions are not handled by programs, however, and result in
error messages as shown here:
The last line of the error message indicates what happened. Exceptions come in different types, and the type is
printed as part of the message: the types in the example are ZeroDivisionError, NameError and TypeError. The
string printed as the exception type is the name of the built-in exception that occurred. This is true for all built-in
exceptions, but need not be true for user-defined exceptions (although it is a useful convention).
The rest of the line provides detail based on the type of exception and what caused it.
The preceding part of the error message shows the context where the exception occurred, in the form of a stack
traceback. In general, it contains a stack traceback listing source lines; however, it will not display lines read from
standard input.
It is possible to write programs that handle selected exceptions. Look at the following example, which asks the user
for input until a valid integer has been entered, but allows the user to interrupt the program (using Control-C or
whatever the operating system supports); note that a user-generated interruption is signaled by raising
the KeyboardInterrupt exception.
First, the try clause (the statement(s) between the try and except keywords) is executed.
If no exception occurs, the except clause is skipped and execution of the try statement is finished.
If an exception occurs during execution of the try clause, the rest of the clause is skipped. Then, if its type
matches the exception named after the except keyword, the except clause is executed, and then execution
continues after the try/except block.
If an exception occurs which does not match the exception named in the except clause, it is passed on to
outer try statements; if no handler is found, it is an unhandled exception and execution stops with an error
message.
A try statement may have more than one except clause, to specify handlers for different exceptions. At most one
handler will be executed. Handlers only handle exceptions that occur in the corresponding try clause, not in other
handlers of the same try statement. An except clause may name multiple exceptions as a parenthesized tuple, for
example:
A class in an except clause matches exceptions which are instances of the class itself or one of its derived classes
(but not the other way around — an except clause listing a derived class does not match instances of its base
classes). For example, the following code will print B, C, D in that order:
When an exception occurs, it may have associated values, also known as the exception’s arguments. The presence
and types of the arguments depend on the exception type.