Eclipse vs IntelliJ

Better ways to organize info - Winner: Eclipse
-  Eclipse provides workspace, working set, projects
-  Organizes views into perspectives, provides view like console, problems, errors. 
- We always know where to find info we need.

Editor -Winner: Eclipse
Eclipse shows error/warning in current window in left side bar. 
IntelliJ only shows error/warning for all content in right side bar. (Eclipse also shows things in right side bar)
When you write code, its much easier to check error/warning in Eclipse.

Shortcut keys -Winner: Eclipse
Eclipse's default shortcut is more natural to me: easier to remember and type. Usually Eclipse uses less keys. IntelliJ uses all keys F1-10.

To format code: Cmd+shift+f in eclipse Cmd+alt+l in IntelliJ
- what L means?

Quick fix - Winner: Eclipse
- Eclipse quick fix(ctrl+1) is too powerful, it can fix bugs, generate code based on current context.
- IntelliJ provides too many ways to do similar things - wtf?
Show intention actions - alt+enter
Basic code completion - ctrl+space

Smart type code completion - ctrl+shift+space

- Drop to frame always works in Eclipse, but doesn't in IntelliJ
- Display view in Eclipse stores history, it's much easier to use

IntelliJ does have its own advantages such as: smart step into for anonymous classes and lambdas.

Search everywhere in IntelliJ
In Eclipse, you have to use different shortcuts/ways to search type, resource, views. 
In IntelliJ, just double press shift keys.

Better Performance/More Stable - Winner: IntelliJ
Sometimes Eclipse is slow or gets stuck, you need take time to customize it, check Improve Eclipse Performance

Same code may work in Eclipse but not in IntelliJ
Eclipse and IntelliJ doesn't works well together, if some team members are using eclipse, you better also use eclipse, as sometimes, the same code works and can be deployed in eclipse's tomcat but doesn't work or can't be deployed in IntelliJ tomcat.

More about Eclipse and IntelliJ:
Mastering Eclipse IDE - Tips, Tricks
IntelliJ IDEA Tips and Tricks

How to Be a Great Technical Lead

How to choose tech stack
- List your current/near-future features
- Consider multiple/different options and how to use them to implement features 
- Compare their pros and cons: manageability, scalability 
- What techs are used in your team and departments
    - But this doesn't mean always use same tech stacks used before 
- What tech are supported by operation team

Build reputation
- be useful and help others

Know your team members
- their strength or weakness
  - programming skills
  - design skills
  - trouble shooting skills
- what they are interested, what are not
- what they want to learn and improve
Help them to grow and improve their skills

Know yourself
Know how/what you can help the team
- your programming/design/communication skills
Know when to stand alone and when to step in
Know when to let others shine

- don't try to do everything
- let other people do the job they are good at and observe
- let others contribute and take ownership/leadership

Spring Tips & Tricks

Spring-boot specifies and manages its dependencies' version:
Don't specify and overwrite the version again in our project's pom.xml.
Don't use same property value to overwrite the version by accident.

@Bean public static PropertySourcesPlaceholderConfigurer propertyConfig(){}

Bind properties to a list or a map
First create ConversionService bean
@Bean public ConversionService conversionService() {
    return new DefaultConversionService();

private List<Integer> myList

redis.expires={typeA:900, typeB: 86400}

private Map<String, Long> expires;

Spring Cache
Support Spring Expression Language in Spring AOP
In contrast to the @Cacheable annotation, @CachePut does not cause the advised method to be skipped. Rather, it always causes the method to be invoked and its result to be stored in the associated cache. 
We can use #result as key in @CachePut.

if (result != NO_RESULT) evaluationContext.setVariable(RESULT_VARIABLE, result);

- To support #result, we just put method return result value into the variable: result.

Synchronized caching
@CacheConfig(cacheNames = "cacheA")
@Cacheable(key= ("#p0['name']")) // p0 is a map
@CachePut(key = "") // p0 is an instance
@Cacheable(key = "'somePrefix-'+#p0")

public static final String PREFIX = "'" + CACHE_NAME + "-'+";
@Cacheable(key = PREFIX + "#p0.toString()") // p0 is UUID

@CachePut(key = PREFIX + "#result.uuid.toString()", condition = "#p2 == 'typeA'")

Compared with condition, unless expressions are evaluated after the method has been called.
unless = "#result != null"

Not cache null value explicitly
@Cacheable(unless = "#result == null")

Change cache log level to trace
logger name="org.springframework.cache" level="trace"
No cache entry for key
Cache entry for key found in cache

Redis Cache
- Cache null values
- Use properties to set different expires for different cache regions
public CacheManager cacheManager(final StringRedisTemplate redisTemplate) {
    final RedisCacheManager cacheManager =
            new RedisCacheManager(redisTemplate, Collections.<String>emptyList(), true);
    return cacheManager;
configKeys = stringRedisTemplate.opsForZSet().range(cacheKey, 0, -1)

Bind Collection of Beans
@Autowired(required = false)
private List<XInterface> instances;


Using Spring managed Bean in non-managed object

Spring EL
private List myList;

Parse annotation's value using Spring EL
// instance are thread safe
private final ExpressionParser parser = new SpelExpressionParser(); 
final XAnnotation xAnnotation = method.getAnnotation(XAnnotation.class);
final Expression exp = parser.parseExpression(xAnnotation.propertyA());
final EvaluationContext context = new MethodBasedEvaluationContext(invocation.getThis(), invocation.getMethod(),
        invocation.getArguments(), new LocalVariableTableParameterNameDiscoverer());

final Object value = exp.getValue(context);

Spring EL
#root, #root.methodName,, #result


BeanUtils.copyProperties - copy properties while ignoring null values
@Retryable(value = {FooException.class, BarException.class}, maxAttempts = 5)

Use AbstractSecurityWebApplicationInitializer
Configure it by extends WebSecurityConfigurerAdapter

Authentication auth = SecurityContextHolder.getContext().getAuthentication();

Integrate In-Memory Authentication for Test Automation

Use inMemoryAuthentication in dev lines for automation test

Extend UsernamePasswordAuthenticationFilter
Build Multi-Tenant Application

Spring Test
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)

Spring test doesn't work with JUnit 4.11
InitializationError When Use Spring Test + JUnit

Spring data
How pring-data-cassandra runs query


Add @NoRepositoryBean to intermediate repository interface.

@Score private Float score;

com.jcraft.jsch.JSchException: UnknownHostKey
ssh-keyscan server-ip-address > my_known_hosts
new DefaultSftpSessionFactory().setKnownHosts(new ClassPathResource("my_known_hosts").getFile().getAbsolutePath());

Return raw json string
- Add StringHttpMessageConverter before MappingJackson2HttpMessageConverter in method configureMessageConverters of WebMvcConfigurationSupport

Injecting Bean Dependencies as Method Parameters
public Foo foo(@Qualifier("bar1") Bar bar1) {
 return new Foo(bar1);
@Bean public Bar bar1() {
 return new Bar("bar1");
This approach is better than the following one as there is only one bean(bar) created.
public Foo foo() {
 return new Foo(bar());

If we create a bean manually in code and it implements InitializingBean interface which will be called automatically after the bean is created by Spring, we may have to call afterPropertiesSet manually.

@Autowired(required = false)

private Configuration aConf;

Journey to be A Great Engineer

Be aware of yourself
- strength, weaknesses
- have a plan to overcome the weaknesses that matters
Brand yourself/build reputation
- join discussion, other projects proactively
- make presentation, give a talk
- be useful and help others grow
Be better everyday
- writer better code, design system better
- try new/different/best approach
Never give up
- exhausts All Resources to solve the problem
- ask more questions and dig deeper
Follow up
- be inquisitive
- how others eventually fix/solve the problem
- what's the real root cause

Keep Learning everyday
- in different ways
  - learn from books/blog/video/podcast
  - learn from others: no matter whether developers are senior or junior than you
  - be open-minded
- learn related/important skills that matters
  - how to search in codebase, log, git(hub) efficiently
  - troubleshoot, IDE
  - how to review code
- learn tech stack used by other team (members)
- understand trends and new techs
  - what's the advantage, when should use it when not
  - how it works, how it's designed
Maintain your learning log 
- blog, notes, doc etc
Maintain your toolbox
- languages/frameworks/ide/bash, new features

Keep calm and be happy/excited
- when meet some difficult problems
- when hear suggestions

- prepare for next meeting/discussion/feature/project
- learning the techs that may be used in current or next feature/project
- learn the techs that may be different(better) and can improve your current solution
- don't blindly repeat same approach/design/code

Use time efficiently
- Know the topics, what you can get and what you can contribute
- Whether it's important to you, if not and you are not required, skip it

- Avoid fragmented time; if can't, use it efficiently(reading, podcast)
- don’t lose state when context switch
- use tools to automate

Think/Discuss/design more before take action
- full algorithm/design before coding
- don't take action blindly: make change then test it or debug it
- check and infer first
Admit what you don’t know
- don't pretend
- ask questions and learn it

Share knowledge
- share more and learn more

How to Ask questions
Ask more and deeper questions to yourself
Ask questions to others
- don't ask simple knowledgeable questions too often
  -- learn/read/google first
- But don't hesitate to ask questions to any one if needed

How to answer questions
- first understand the question and what's the real question and issue
- don't just assume others are asking simple or stupid questions
- if not 100% sure, check it before answer

Quickly vs Slowly
Know when to solve problem or do things quickly when to do things slowly
- Solve problems quickly so others can move on
- But take time to find root cause or reflect if it matters

Career Development
- be initiative
- talk with your managers
- express your interest/passion and goal
- work on interesting/challenging projects
- prefer yes over no

Troubleshooting Practices

Troubleshooting is important and inevitable for engineers when we try to figure out why the code doesn't work; it also improves our problem solving skills: what steps to take to quickly find the root cause.

This articles is to reflect the process that I took to find the root cause.

Can't deploy Spring-boot application to tomcat
- SpringBootServletInitializer.configure is not called at all

During dev, the team is running spring-boot application as java application. But later when we deploy to the cloud, we need run it as web application. The developer tried it but doesn't work.

We found out it's because the dev specifies 2.5 in web.xml unintentionally and Spring-boot requires Servlet 3.0 by default.

jackson-module-scala: NoSuchMethodError due to intellij
Recently when I ran tests in intellij, it throws the following exception:
java.lang.NoSuchMethodError: scala.util.matching.Regex.unapplySeq(Ljava/lang/CharSequence;)Lscala/Option;
at com.fasterxml.jackson.module.scala.JacksonModule$.version$lzycompute(JacksonModule.scala:30)
at com.fasterxml.jackson.module.scala.JacksonModule$.version(JacksonModule.scala:26)
at com.fasterxml.jackson.module.scala.JacksonModule$class.version(JacksonModule.scala:49)
at com.fasterxml.jackson.module.scala.DefaultScalaModule.version(DefaultScalaModule.scala:19)
at com.fasterxml.jackson.databind.ObjectMapper.registerModule(

Seems it's caused by jackson-module-scala, but I use mvn dependency:tree and dependency:copy-dependencies to check all thing looks good: we use scala-2.11 and jackson-module-scala_2.11. Also if I ran the test in command line, it works.

This made me think maybe this is because of intellij. 
I added a breakpoint and run: scala.util.Properties.versionString in debug mode, it's 2.10.6. This is strange. Then I check external libraries in intellij, there are indeed multiple scala-library versions: 2.10.6 and 2.11.8.

In our current projects, we don't use scala-library-2.10.6 anywhere. Maybe previously we use scala 2.10.6, later we upgraded to 2.11. But intellij still keeps reference to old scala in external libraries.
- no effects when reimport all maven projects

The workaround is to delete .idea/libraries internals and restart IntelliJ and reimport projects.

ClassNotFoundException: StandardSessionIdGenerator because we overwrite tomcat.version
- Asked by team mate to help solve this issue
Usually this is because of version conflict. We use spring-boot 1.5, but the tomcat-embed-core is 7.0.65. This looks suspicious. Then I checked the pom.xml. This makes me check how spring-boot specifies its version. search tomcat-embed-core in, found 
spring-boot-starters/spring-boot-starter-tomcat/pom.xml and spring-boot-dependencies/pom.xml:

But we also defined same property: tomcat.version to 7.0.50 in project's pom.xml for some tomcat dependencies we used. This overwrites spring-boot property. So now spring-boot use tomcat-embed-core 7.0.65 which doesn't have StandardSessionIdGenerator class.

The fix is to change our own property to xx. tomcat.version and also bumped its version to same as spring-boot.
- spring-boot should add prefix such as spring.boot to these properties.

Find code by running sample code and debugging it
Build Web Service APIs to Update Solr's Managed Resources (stop words, synonyms)
I need figure out how to get address of one of live solr nodes by using CloudSolrClient.  I know solrJ uses apache http client to send requests, somewhere it needs get addresses of solr nodes, so I write some sample code which sends invalid request, solrJ will throw exception, then I check the stack trace form the log and find out the code that I need at org.apache.solr.client.solrj.impl.CloudSolrClient.sendRequest(SolrRequest, String).


Java (159) Lucene-Solr (110) All (60) Interview (59) J2SE (53) Algorithm (37) Eclipse (35) Soft Skills (35) Code Example (31) Linux (26) JavaScript (23) Spring (22) Windows (22) Web Development (20) Tools (19) Nutch2 (18) Bugs (17) Debug (15) Defects (14) Text Mining (14) J2EE (13) Network (13) PowerShell (11) Chrome (9) Continuous Integration (9) How to (9) Learning code (9) Performance (9) UIMA (9) html (9) Design (8) Dynamic Languages (8) Http Client (8) Maven (8) Security (8) Trouble Shooting (8) bat (8) blogger (8) Big Data (7) Google (7) Guava (7) JSON (7) Problem Solving (7) ANT (6) Coding Skills (6) Database (6) Scala (6) Shell (6) css (6) Algorithm Series (5) Cache (5) IDE (5) Lesson Learned (5) Miscs (5) Programmer Skills (5) System Design (5) Tips (5) adsense (5) xml (5) AIX (4) Code Quality (4) GAE (4) Git (4) Good Programming Practices (4) Jackson (4) Memory Usage (4) OpenNLP (4) Project Managment (4) Python (4) Spark (4) Testing (4) ads (4) regular-expression (4) Android (3) Apache Spark (3) Become a Better You (3) Concurrency (3) Eclipse RCP (3) English (3) Firefox (3) Happy Hacking (3) IBM (3) J2SE Knowledge Series (3) JAX-RS (3) Jetty (3) Restful Web Service (3) Script (3) regex (3) seo (3) .Net (2) Android Studio (2) Apache (2) Apache Procrun (2) Architecture (2) Batch (2) Build (2) Building Scalable Web Sites (2) C# (2) C/C++ (2) CSV (2) Career (2) Cassandra (2) Distributed (2) Fiddler (2) Google Drive (2) Gson (2) Html Parser (2) Http (2) Image Tools (2) JQuery (2) Jersey (2) LDAP (2) Life (2) Logging (2) Software Issues (2) Storage (2) Text Search (2) xml parser (2) AOP (1) Application Design (1) AspectJ (1) Bit Operation (1) Chrome DevTools (1) Cloud (1) Codility (1) Data Mining (1) Data Structure (1) ExceptionUtils (1) Exif (1) Feature Request (1) FindBugs (1) Greasemonkey (1) HTML5 (1) Httpd (1) I18N (1) IBM Java Thread Dump Analyzer (1) JDK Source Code (1) JDK8 (1) JMX (1) Lazy Developer (1) Mac (1) Machine Learning (1) Mobile (1) My Plan for 2010 (1) Netbeans (1) Notes (1) Operating System (1) Perl (1) Problems (1) Product Architecture (1) Programming Life (1) Quality (1) Redhat (1) Redis (1) Review (1) RxJava (1) Solutions logs (1) Team Management (1) Thread Dump Analyzer (1) Troubleshooting (1) Visualization (1) boilerpipe (1) htm (1) ongoing (1) procrun (1) rss (1)

Popular Posts