Found 346 Articles for Java Programming

Member variables in Java

Kumar Varma
Updated on 24-Feb-2020 05:06:13

8K+ Views

Member variables are known as instance variables in java.Instance variables are declared in a class, but outside a method, constructor or any block.When space is allocated for an object in the heap, a slot for each instance variable value is created.Instance variables are created when an object is created with the use of the keyword 'new' and destroyed when the object is destroyed.Instance variables hold values that must be referenced by more than one method, constructor or block, or essential parts of an object's state that must be present throughout the class.Instance variables can be declared in a class level ... Read More

Local variables in Java

Syed Javed
Updated on 12-Mar-2020 12:14:34

1K+ Views

Local variables are declared in methods, constructors, or blocks.Local variables are created when the method, constructor or block is entered and the variable will be destroyed once it exits the method, constructor, or block.Access modifiers cannot be used for local variables.Local variables are visible only within the declared method, constructor, or block.Local variables are implemented at stack level internally.There is no default value for local variables, so local variables should be declared and an initial value should be assigned before the first use.ExampleHere, age is a local variable. This is defined inside pupAge()method and its scope is limited to only ... Read More

Java variable naming rules

George John
Updated on 30-Jul-2019 22:30:21

3K+ Views

All Java components require names. Names used for classes, variables, and methods are called identifiers. In Java, there are several points to remember about identifiers. They are as follows - Step 1 − All identifiers should begin with a letter (A to Z or a to z), currency character ($) or an underscore (_). Step 2 − After the first character, identifiers can have any combination of characters. Step 3 − A keyword cannot be used as an identifier. Step 4 − Most importantly, identifiers are case sensitive. Step 5 − Examples of legal identifiers: age, $salary, _value, __1_value. Step 6 − Examples of illegal identifiers: 123abc, -salary.

Troubleshooting tips

Rishi Raj
Updated on 13-Jun-2020 13:30:56

444 Views

Following steps are mostly required to Troubleshoot any problem that occurred in production.As the first step, get the time frame from the user when a particular issue occurred. Get the logs for that particular time period.If logs are very large in size, use grep command to filter out errors.$ grep -o "\w*Exception" error.log | sort -r | uniq -cIt will help to get all the exceptions in error.log sorted in reversed order and give the unique result and with counts.

When Java runs faster than C++?

Alankritha Ammu
Updated on 13-Jun-2020 14:03:12

65 Views

Following are the areas where Java has proved itself faster than C++.Memory allocation/deallocation: Memory allocation/deallocation is much faster and it is often faster to create a new big array instead of using the cached one.Object instantiation: Memory management done by GC of Java attributes faster object related operations on Java than C++.Multithreading and Synchronization: Modern Java programs makes use of multi-core systems to make synchronization and multithreading much faster operation.JIT has improved a lot over period of time and modern Java program execution now is much faster.String operations are faster by having length. Collection methods are optimized like Array copy.Class loading ... Read More

Why is Java slower than C++ programs?

Akshaya Akki
Updated on 13-Jun-2020 14:02:33

957 Views

Modern Java is quite fast and is comparable to C++ code base but it still takes lot of memory. Slowness of Java programs is primarily because of bad programming practices. But following areas are where Java can be improved.Java libraries are written keeping readability and correctness in mind, not performance.Slow String based operations as Strings are UTF-16 encoded objects and are immutable. So more String are used, more memory is required.Boundary checks on arrays also make its operations bit slow.I/O Stream operations are slow considering synchronization checks on each access.Lacking low level functionality like C also attributes to slowness in ... Read More

Memory management in Java

Ayyan
Updated on 24-Feb-2020 09:18:49

513 Views

Java memory model is divided between Thread Stacks (One for each thread) and a heap area.Thread StackIt is a thread specific memory area and contains local variables, methods call information etc. JVM stacks could be of fixed size or variable size. If computation in a thread exceeds its stack size limit then JVM throws StackOverflowError and exits.HeapIt contains all the objects created during application lifecycle. The heap is created when the virtual machine starts up. Garbage collector reclaims heap storage for objects and objects are never explicitly deallocated. The JVM is not using any automatic storage management system, and it ... Read More

What is Java Method Area?

Ayyan
Updated on 30-Jul-2019 22:30:21

2K+ Views

JVM has a method area common across all the threads. It contains per-class elements like constant pool, fields, method local data, method code, constructor codes etc. which are used in class and initialization of objects/interfaces.This method area gets created during JVM start-up. It is generally part of Heap area. It could be of fixed size or vary. Its memory may not be contiguous. JVM implementation can give control to programmer over Method area creation, its sizing etc. If method area memory is not sufficient to satisfy an allocation request then JVM throws OutOfMemoryError.

Java Memory Model

Alankritha Ammu
Updated on 24-Feb-2020 09:21:54

2K+ Views

Java memory model is divided between Thread Stacks (One for each thread) and a heap area.Thread Stack: It is a thread specific memory area and contains local variables, methods call information etc. JVM stacks could be of fixed size or variable size. If computation in a thread exceeds its stack size limit then JVM throws StackOverflowError and exits.HeapIt contains all the objects created during application lifecycle. The heap is created when the virtual machine starts up. Garbage collector reclaims heap storage for objects and objects are never explicitly deallocated. The JVM is not using any automatic storage management system, and ... Read More

What is the Java Runtime Environment (JRE)?

Ayyan
Updated on 25-Feb-2020 08:19:34

276 Views

JRE is Java Runtime Environment and is the machine-specific implementation of JVM. It contains libraries like rt.jar, class loaders etc which are used by JVM.

Advertisements